From 124adf253c5cd4940088ca2f10bc12da30375683 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sun, 10 Oct 2010 18:45:14 +0100 Subject: [PATCH] gallivm: Fix a long standing bug with nested if-then-else emission. We can't patch true-block at end-if time, as there is no guarantee that the block at the beginning of the true stanza is the same at the end of the true stanza -- other control flow elements may have been emitted half way the true stanza. Although this bug surfaced recently with the commit to skip mip filtering when lod is an integer the bug was always there, although probably it was avoided until now: e.g., cubemap selection nests if-then-else on the else stanza, which does not suffer from the same problem. --- src/gallium/auxiliary/gallivm/lp_bld_flow.c | 23 ++++++--------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.c b/src/gallium/auxiliary/gallivm/lp_bld_flow.c index 99a49df317c..9d1a74f5d16 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_flow.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.c @@ -320,7 +320,6 @@ lp_build_if(struct lp_build_if_state *ifthen, /* create endif/merge basic block for the phi functions */ ifthen->merge_block = lp_build_insert_new_block(builder, "endif-block"); - LLVMPositionBuilderAtEnd(builder, ifthen->merge_block); /* create/insert true_block before merge_block */ ifthen->true_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-true-block"); @@ -336,6 +335,9 @@ lp_build_if(struct lp_build_if_state *ifthen, void lp_build_else(struct lp_build_if_state *ifthen) { + /* Append an unconditional Br(anch) instruction on the true_block */ + LLVMBuildBr(ifthen->builder, ifthen->merge_block); + /* create/insert false_block before the merge block */ ifthen->false_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-false-block"); @@ -353,9 +355,9 @@ lp_build_endif(struct lp_build_if_state *ifthen) /* Insert branch to the merge block from current block */ LLVMBuildBr(ifthen->builder, ifthen->merge_block); - /*** - *** Now patch in the various branch instructions. - ***/ + /* + * Now patch in the various branch instructions. + */ /* Insert the conditional branch instruction at the end of entry_block */ LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->entry_block); @@ -370,19 +372,6 @@ lp_build_endif(struct lp_build_if_state *ifthen) ifthen->true_block, ifthen->merge_block); } - /* Insert branch from end of true_block to merge_block */ - if (ifthen->false_block) { - /* Append an unconditional Br(anch) instruction on the true_block */ - LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->true_block); - LLVMBuildBr(ifthen->builder, ifthen->merge_block); - } - else { - /* No else clause. - * Note that we've already inserted the branch at the end of - * true_block. See the very first LLVMBuildBr() call in this function. - */ - } - /* Resume building code at end of the ifthen->merge_block */ LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->merge_block); } -- 2.30.2