[llvm-commits] [llvm] r43055 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner clattner at apple.com
Tue Oct 16 17:40:57 PDT 2007


> URL: http://llvm.org/viewvc/llvm-project?rev=43055&view=rev
> Log:
> Use immediate stores.

Hey Devang,

There is nothing about this xform that is specific to the memcpy/ 
memmove xform.  Can you just move this to visitLoadInst, transforming  
any load from a (casted) constant string?

-Chris

> Modified:
>     llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ 
> Scalar/InstructionCombining.cpp?rev=43055&r1=43054&r2=43055&view=diff
>
> ====================================================================== 
> ========
> --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp  
> (original)
> +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue  
> Oct 16 18:44:18 2007
> @@ -7673,18 +7673,40 @@
>          unsigned Size = MemOpLength->getZExtValue();
>          unsigned Align = cast<ConstantInt>(CI.getOperand(4))- 
> >getZExtValue();
>          PointerType *NewPtrTy = NULL;
> +        unsigned numBits = Size << 3;
>          // Destination pointer type is always i8 *
>          // If Size is 8 then use Int64Ty
>          // If Size is 4 then use Int32Ty
>          // If Size is 2 then use Int16Ty
>          // If Size is 1 then use Int8Ty
>          if (Size && Size <=8 && !(Size&(Size-1)))
> -          NewPtrTy = PointerType::get(IntegerType::get(Size<<3));
> +          NewPtrTy = PointerType::get(IntegerType::get(numBits));
>
>          if (NewPtrTy) {
> -          Value *Src = InsertCastBefore(Instruction::BitCast,  
> CI.getOperand(2), NewPtrTy, CI);
> +          Value *L = NULL;
> +          // If source is a null terminated constant c string then  
> try to use immediate store.
> +          if (Constant *C = dyn_cast<Constant>(CI.getOperand(2))) {
> +            const std::string &Str = C->getStringValue();
> +            if (!Str.empty()) {
> +              APInt StrVal(numBits, 0);
> +              unsigned len = Str.length();
> +              APInt SingleChar(numBits, 0);
> +              for (unsigned i = 0; i < len; i++) {
> +                SingleChar = (uint64_t) Str[i];
> +                StrVal = (StrVal << 8) | SingleChar;
> +              }
> +              // Append NULL at the end.
> +              SingleChar = 0;
> +              StrVal = (StrVal << 8) | SingleChar;
> +              L = ConstantInt::get(StrVal);
> +            }
> +          }
> +          // Otherwise load source from memory.
> +          if (L == NULL) {
> +            Value *Src = InsertCastBefore(Instruction::BitCast,  
> CI.getOperand(2), NewPtrTy, CI);
> +            L = new LoadInst(Src, "tmp", false, Align, &CI);
> +          }
>            Value *Dest = InsertCastBefore(Instruction::BitCast,  
> CI.getOperand(1), NewPtrTy, CI);
> -          Value *L = new LoadInst(Src, "tmp", false, Align, &CI);
>            Value *NS = new StoreInst(L, Dest, false, Align, &CI);
>            CI.replaceAllUsesWith(NS);
>            Changed = true;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list