X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FScalar%2FInstructionCombining.cpp;h=649dd46c81feadfcc093a64a12e5a1f92b92db90;hb=afc407ea5196b6ce638c25bd21569270504bb604;hp=3edc86b93d25aa0da79a4b4cb60533ae49975c0d;hpb=7b9e1d251f2e7d8481e1cfcd72b8c2f0ffa244ef;p=oota-llvm.git diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 3edc86b93d2..649dd46c81f 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -7674,19 +7674,20 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { unsigned Align = cast(CI.getOperand(4))->getZExtValue(); PointerType *NewPtrTy = NULL; // Destination pointer type is always i8 * - if (Size == 8) - NewPtrTy = PointerType::get(Type::Int64Ty); - else if (Size == 4) - NewPtrTy = PointerType::get(Type::Int32Ty); - else if (Size == 2) - NewPtrTy = PointerType::get(Type::Int16Ty); - else if (Size == 1) - NewPtrTy = PointerType::get(Type::Int8Ty); + // 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)); + if (NewPtrTy) { Value *Src = InsertCastBefore(Instruction::BitCast, CI.getOperand(2), NewPtrTy, 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); + AddToWorkList(cast(L)); + AddToWorkList(cast(NS)); CI.replaceAllUsesWith(NS); Changed = true; return EraseInstFromFunction(CI); @@ -9115,6 +9116,29 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { } } else if (CE->isCast()) { + // Instead of loading constant c string, use corresponding integer value + // directly if string length is small enough. + const std::string &Str = CE->getOperand(0)->getStringValue(); + if (!Str.empty()) { + unsigned len = Str.length(); + const Type *Ty = cast(CE->getType())->getElementType(); + unsigned numBits = Ty->getPrimitiveSizeInBits(); + if ((numBits >> 3) == len + 1) { + // Replace LI with immediate integer store. + APInt StrVal(numBits, 0); + 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; + Value *NL = ConstantInt::get(StrVal); + return ReplaceInstUsesWith(LI, NL); + } + } + if (Instruction *Res = InstCombineLoadCast(*this, LI)) return Res; }