gallivm: simplify conditional branching
authorJose Fonseca <jfonseca@vmware.com>
Wed, 10 Mar 2010 22:22:30 +0000 (17:22 -0500)
committerZack Rusin <zackr@vmware.com>
Wed, 10 Mar 2010 22:22:30 +0000 (17:22 -0500)
Instead of testing each component individually, we can test the entire
vector at once.

src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c

index aa57289395e5cf570cf7772154f348c3e2199f97..b3a0fe7d9beaab9643eb1733782ba1b4ea702a33 100644 (file)
@@ -276,27 +276,14 @@ static void lp_exec_continue(struct lp_exec_mask *mask)
 static void lp_exec_endloop(struct lp_exec_mask *mask)
 {
    LLVMBasicBlockRef endloop;
-   LLVMValueRef i1cond;
-
-   { /* convert our soa vector into i1 */
-      int i;
-      LLVMValueRef packed = 0;
-      for (i = 0; i < mask->bld->type.length; ++i) {
-         LLVMValueRef component = LLVMBuildExtractElement(
-            mask->bld->builder,
-            mask->break_mask,
-            LLVMConstInt(LLVMInt32Type(), i, 0), "");
-         if (packed)
-            packed = LLVMBuildOr(mask->bld->builder,
-                                 packed, component, "");
-         else
-            packed = component;
-      }
-      i1cond = LLVMBuildICmp(mask->bld->builder, LLVMIntNE,
-                             packed,
-                             LLVMConstNull(LLVMTypeOf(packed)),
-                             "");
-   }
+   LLVMTypeRef reg_type = LLVMIntType(mask->bld->type.width*
+                                      mask->bld->type.length);
+   /* i1cond = (mask == 0) */
+   LLVMValueRef i1cond = LLVMBuildICmp(
+      mask->bld->builder,
+      LLVMIntNE,
+      LLVMBuildBitCast(mask->bld->builder, mask->break_mask, reg_type, ""),
+      LLVMConstNull(reg_type), "");
 
    endloop = lp_build_insert_new_block(mask->bld->builder, "endloop");