Mesa (lp-binning): llvmpipe: fix more if/else/endif design bugs

Brian Paul brianp at kemper.freedesktop.org
Fri Jan 8 14:08:05 PST 2010


Module: Mesa
Branch: lp-binning
Commit: 5208af7853989c30bea6ce8c4ac659a2f2304225
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5208af7853989c30bea6ce8c4ac659a2f2304225

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Jan  8 12:47:30 2010 -0700

llvmpipe: fix more if/else/endif design bugs

---

 src/gallium/drivers/llvmpipe/lp_bld_flow.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_bld_flow.c b/src/gallium/drivers/llvmpipe/lp_bld_flow.c
index 161ec95..693742f 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_flow.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_flow.c
@@ -647,9 +647,12 @@ lp_build_if(struct lp_build_if_state *ctx,
    LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
 
    /* create a phi node for each variable */
-   for (i = 0; i < flow->num_variables; i++)
+   for (i = 0; i < flow->num_variables; i++) {
       ifthen->phi[i] = LLVMBuildPhi(builder, LLVMTypeOf(*flow->variables[i]), "");
 
+      /* add add the initial value of the var from the entry block */
+      LLVMAddIncoming(ifthen->phi[i], flow->variables[i], &ifthen->entry_block, 1);
+   }
 
    /* create/insert true_block before merge_block */
    ifthen->true_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-true-block");
@@ -706,21 +709,20 @@ lp_build_endif(struct lp_build_if_state *ctx)
       for (i = 0; i < flow->num_variables; i++) {
          assert(*flow->variables[i]);
          LLVMAddIncoming(ifthen->phi[i], flow->variables[i], &ifthen->false_block, 1);
+
+         /* replace the variable ref with the phi function */
+         *flow->variables[i] = ifthen->phi[i];
       }
    }
    else {
       /* no else clause */
       LLVMPositionBuilderAtEnd(ctx->builder, ifthen->merge_block);
       for (i = 0; i < flow->num_variables; i++) {
-         LLVMValueRef undef;
-
          assert(*flow->variables[i]);
-
          LLVMAddIncoming(ifthen->phi[i], flow->variables[i], &ifthen->true_block, 1);
 
-         /* undef value from the block preceeding the 'if' */
-         undef = LLVMGetUndef(LLVMTypeOf(*flow->variables[i]));
-         LLVMAddIncoming(ifthen->phi[i], &undef, &ifthen->entry_block, 1);
+         /* replace the variable ref with the phi function */
+         *flow->variables[i] = ifthen->phi[i];
       }
    }
 



More information about the mesa-commit mailing list