Commit 271dd183 authored by Rhys Perry's avatar Rhys Perry

ac/llvm: insert phis before demote kill

LLVM (like NIR) requires phi instructions to be before any other
instructions in the block. ac_branch_exited() can insert non-phi
instructions before visit_block() adds phis, so visit_block() should add
phi instructions before the non-phi instructions ac_branch_exited()
Signed-off-by: Rhys Perry's avatarRhys Perry <>
Reviewed-by: default avatarMarek Olšák <>
Fixes: aa757f4f ("ac/llvm: fix demote inside conditional branches")
Part-of: <mesa/mesa!8054>
parent 3a63e430
......@@ -4727,6 +4727,21 @@ static void visit_cf_list(struct ac_nir_context *ctx, struct exec_list *list);
static void visit_block(struct ac_nir_context *ctx, nir_block *block)
LLVMBasicBlockRef blockref = LLVMGetInsertBlock(ctx->ac.builder);
LLVMValueRef first = LLVMGetFirstInstruction(blockref);
if (first) {
/* ac_branch_exited() might have already inserted non-phis */
LLVMPositionBuilderBefore(ctx->ac.builder, LLVMGetFirstInstruction(blockref));
nir_foreach_instr(instr, block) {
if (instr->type != nir_instr_type_phi)
visit_phi(ctx, nir_instr_as_phi(instr));
LLVMPositionBuilderAtEnd(ctx->ac.builder, blockref);
nir_foreach_instr (instr, block) {
switch (instr->type) {
case nir_instr_type_alu:
......@@ -4742,7 +4757,6 @@ static void visit_block(struct ac_nir_context *ctx, nir_block *block)
visit_tex(ctx, nir_instr_as_tex(instr));
case nir_instr_type_phi:
visit_phi(ctx, nir_instr_as_phi(instr));
case nir_instr_type_ssa_undef:
visit_ssa_undef(ctx, nir_instr_as_ssa_undef(instr));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment