[llvm-commits] CVS: gcc-3.4/gcc/llvm-expand.c

Chris Lattner lattner at cs.uiuc.edu
Fri Feb 13 22:27:11 PST 2004


Changes in directory gcc-3.4/gcc:

llvm-expand.c updated: 1.11 -> 1.12

---
Log message:

Use a memset instead of an explicit loop to initialize arrays in tests like
test/Regression/CFrontend/2004-02-13-StringInit.c.tr


---
Diffs of the changes:  (+43 -32)

Index: gcc-3.4/gcc/llvm-expand.c
diff -u gcc-3.4/gcc/llvm-expand.c:1.11 gcc-3.4/gcc/llvm-expand.c:1.12
--- gcc-3.4/gcc/llvm-expand.c:1.11	Fri Feb 13 22:07:54 2004
+++ gcc-3.4/gcc/llvm-expand.c	Fri Feb 13 22:26:31 2004
@@ -3903,6 +3903,9 @@
       if (Size-TailStart < 16)
         TailStart = Size;
 
+      /* FIXME: If tailstart is obscenely large, we are better off starting with
+       * an initialized global and memcpy'ing it over.
+       */
       for (i = 0; i != TailStart; ++i) {
         /* Make a getelementptr instruction that addresses the field */
         OffsetInst = create_gep3(target, llvm_constant_long_0,
@@ -3911,41 +3914,49 @@
         append_inst(Fn, create_store_inst(Elements[i], Offset, isVolatile));
       }
 
-      /* If there is tail padding to emit, add the loop now. */
+      /* If there is tail padding to emit, add the loop or memset call now. */
       if (TailStart != Size) {
         llvm_value *Val = Elements[i];
-        llvm_basicblock *FromBlock =
-          llvm_ilist_back(llvm_basicblock, Fn->BasicBlocks);
-        llvm_basicblock *Loop = llvm_basicblock_new("initializeloop");
-        llvm_basicblock *After = llvm_basicblock_new("continue");
-        llvm_instruction *PHI;
-        llvm_value *SetNE;
-        
-        /* Output the branch to the loop block, and the loop block itself. */
-        append_inst(Fn, create_uncond_branch(Loop));
-        llvm_emit_label(Fn, Loop);
-
-        /* Create the PHI node now */
-        PHI = llvm_instruction_new(LongTy, "idx", O_PHINode, 4);
-        PHI->Operands[0] = llvm_constant_new_integral(LongTy, TailStart);
-        PHI->Operands[1] = D2V(FromBlock);
-        PHI->Operands[3] = D2V(Loop);
-        append_inst(Fn, PHI);
-
-        /* Make a getelementptr & store to the fields */
-        OffsetInst = create_gep3(target, llvm_constant_long_0, D2V(PHI));
-        Offset = append_inst(Fn, OffsetInst);   /* Add it to the program */
-        append_inst(Fn, create_store_inst(Val, Offset, isVolatile));
-
-        /* Add one to the counter, add it to the PHI operand */
-        PHI->Operands[2] = 
-          append_inst(Fn, create_binary_inst("tmp", O_Add, D2V(PHI), 
-                                     llvm_constant_new_integral(LongTy, 1)));
-        /* Add a setne instruction to test for loop termination */
-        SetNE = append_inst(Fn, create_binary_inst("hasmore", O_SetNE, D2V(PHI),
+        if (llvm_type_get_size(Val->Ty) == 1) {
+          llvm_value *DestPtr =
+            append_inst(Fn, create_gep3(target, llvm_constant_long_0,
+                                llvm_constant_new_integral(LongTy, TailStart)));
+          EmitMemset(Fn, DestPtr, Val,
+                     llvm_constant_new_integral(LongTy, Size-TailStart), 1);
+        } else {
+          llvm_basicblock *FromBlock =
+            llvm_ilist_back(llvm_basicblock, Fn->BasicBlocks);
+          llvm_basicblock *Loop = llvm_basicblock_new("initializeloop");
+          llvm_basicblock *After = llvm_basicblock_new("continue");
+          llvm_instruction *PHI;
+          llvm_value *SetNE;
+          
+          /* Output the branch to the loop block, and the loop block itself. */
+          append_inst(Fn, create_uncond_branch(Loop));
+          llvm_emit_label(Fn, Loop);
+          
+          /* Create the PHI node now */
+          PHI = llvm_instruction_new(LongTy, "idx", O_PHINode, 4);
+          PHI->Operands[0] = llvm_constant_new_integral(LongTy, TailStart);
+          PHI->Operands[1] = D2V(FromBlock);
+          PHI->Operands[3] = D2V(Loop);
+          append_inst(Fn, PHI);
+          
+          /* Make a getelementptr & store to the fields */
+          OffsetInst = create_gep3(target, llvm_constant_long_0, D2V(PHI));
+          Offset = append_inst(Fn, OffsetInst);   /* Add it to the program */
+          append_inst(Fn, create_store_inst(Val, Offset, isVolatile));
+          
+          /* Add one to the counter, add it to the PHI operand */
+          PHI->Operands[2] = 
+            append_inst(Fn, create_binary_inst("tmp", O_Add, D2V(PHI), 
+                                        llvm_constant_new_integral(LongTy, 1)));
+          /* Add a setne instruction to test for loop termination */
+          SetNE = append_inst(Fn, create_binary_inst("hasmore",O_SetNE,D2V(PHI),
                                    llvm_constant_new_integral(LongTy, Size-1)));
-        append_inst(Fn, create_cond_branch(SetNE, Loop, After));
-        llvm_emit_label(Fn, After);
+          append_inst(Fn, create_cond_branch(SetNE, Loop, After));
+          llvm_emit_label(Fn, After);
+        }
       }
     }
   }





More information about the llvm-commits mailing list