llvm.org GIT mirror llvm / a9390a4
Stop emitting instructions with the name "tmp" they eat up memory and have to be uniqued, without any benefit. If someone prefers %tmp42 to %42, run instnamer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140634 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
22 changed file(s) with 125 addition(s) and 148 deletion(s). Raw diff Collapse all Expand all
162162 }
163163
164164 // If we haven't found this binop, insert it.
165 Instruction *BO = cast(Builder.CreateBinOp(Opcode, LHS, RHS, "tmp"));
165 Instruction *BO = cast(Builder.CreateBinOp(Opcode, LHS, RHS));
166166 BO->setDebugLoc(SaveInsertPt->getDebugLoc());
167167 rememberInstruction(BO);
168168
979979 const SCEV *const StepArray[1] = { SE.getSCEV(StepV) };
980980 IncV = expandAddToGEP(StepArray, StepArray+1, GEPPtrTy, IntTy, PN);
981981 if (IncV->getType() != PN->getType()) {
982 IncV = Builder.CreateBitCast(IncV, PN->getType(), "tmp");
982 IncV = Builder.CreateBitCast(IncV, PN->getType());
983983 rememberInstruction(IncV);
984984 }
985985 } else {
12211221 Type *Ty = SE.getEffectiveSCEVType(S->getType());
12221222 Value *V = expandCodeFor(S->getOperand(),
12231223 SE.getEffectiveSCEVType(S->getOperand()->getType()));
1224 Value *I = Builder.CreateTrunc(V, Ty, "tmp");
1224 Value *I = Builder.CreateTrunc(V, Ty);
12251225 rememberInstruction(I);
12261226 return I;
12271227 }
12301230 Type *Ty = SE.getEffectiveSCEVType(S->getType());
12311231 Value *V = expandCodeFor(S->getOperand(),
12321232 SE.getEffectiveSCEVType(S->getOperand()->getType()));
1233 Value *I = Builder.CreateZExt(V, Ty, "tmp");
1233 Value *I = Builder.CreateZExt(V, Ty);
12341234 rememberInstruction(I);
12351235 return I;
12361236 }
12391239 Type *Ty = SE.getEffectiveSCEVType(S->getType());
12401240 Value *V = expandCodeFor(S->getOperand(),
12411241 SE.getEffectiveSCEVType(S->getOperand()->getType()));
1242 Value *I = Builder.CreateSExt(V, Ty, "tmp");
1242 Value *I = Builder.CreateSExt(V, Ty);
12431243 rememberInstruction(I);
12441244 return I;
12451245 }
12551255 LHS = InsertNoopCastOfTo(LHS, Ty);
12561256 }
12571257 Value *RHS = expandCodeFor(S->getOperand(i), Ty);
1258 Value *ICmp = Builder.CreateICmpSGT(LHS, RHS, "tmp");
1258 Value *ICmp = Builder.CreateICmpSGT(LHS, RHS);
12591259 rememberInstruction(ICmp);
12601260 Value *Sel = Builder.CreateSelect(ICmp, LHS, RHS, "smax");
12611261 rememberInstruction(Sel);
12791279 LHS = InsertNoopCastOfTo(LHS, Ty);
12801280 }
12811281 Value *RHS = expandCodeFor(S->getOperand(i), Ty);
1282 Value *ICmp = Builder.CreateICmpUGT(LHS, RHS, "tmp");
1282 Value *ICmp = Builder.CreateICmpUGT(LHS, RHS);
12831283 rememberInstruction(ICmp);
12841284 Value *Sel = Builder.CreateSelect(ICmp, LHS, RHS, "umax");
12851285 rememberInstruction(Sel);
13751375 for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
13761376 Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock);
13771377 Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal,
1378 Constant::getNullValue(GVVal->getType()),
1379 "tmp");
1378 Constant::getNullValue(GVVal->getType()));
13801379 BasicBlock *FreeBlock = BasicBlock::Create(Cmp->getContext(), "free_it",
13811380 OrigBB->getParent());
13821381 BasicBlock *NextBlock = BasicBlock::Create(Cmp->getContext(), "next",
11961196 // an endless loop. By checking that A is non-constant we ensure that
11971197 // we will never get to the loop.
11981198 if (A == tmpOp0 && !isa(A)) // A&(A^B) -> A & ~B
1199 return BinaryOperator::CreateAnd(A, Builder->CreateNot(B, "tmp"));
1199 return BinaryOperator::CreateAnd(A, Builder->CreateNot(B));
12001200 }
12011201 }
12021202
22272227 if (A == Op1) // (B|A)^B == (A|B)^B
22282228 std::swap(A, B);
22292229 if (B == Op1) // (A|B)^B == A & ~B
2230 return BinaryOperator::CreateAnd(A, Builder->CreateNot(Op1, "tmp"));
2230 return BinaryOperator::CreateAnd(A, Builder->CreateNot(Op1));
22312231 } else if (match(Op0I, m_And(m_Value(A), m_Value(B))) &&
22322232 Op0I->hasOneUse()){
22332233 if (A == Op1) // (A&B)^A -> (B&A)^A
22342234 std::swap(A, B);
22352235 if (B == Op1 && // (B&A)^A == ~B & A
22362236 !isa(Op1)) { // Canonical form is (B&C)^C
2237 return BinaryOperator::CreateAnd(Builder->CreateNot(A, "tmp"), Op1);
2237 return BinaryOperator::CreateAnd(Builder->CreateNot(A), Op1);
22382238 }
22392239 }
22402240 }
653653
654654 if (ExtractedElts[Idx] == 0) {
655655 ExtractedElts[Idx] =
656 Builder->CreateExtractElement(Idx < 16 ? Op0 : Op1,
657 ConstantInt::get(Type::getInt32Ty(II->getContext()),
658 Idx&15, false), "tmp");
656 Builder->CreateExtractElement(Idx < 16 ? Op0 : Op1,
657 Builder->getInt32(Idx&15));
659658 }
660659
661660 // Insert this value into the result vector.
662661 Result = Builder->CreateInsertElement(Result, ExtractedElts[Idx],
663 ConstantInt::get(Type::getInt32Ty(II->getContext()),
664 i, false), "tmp");
662 Builder->getInt32(i));
665663 }
666664 return CastInst::Create(Instruction::BitCast, Result, CI.getType());
667665 }
11421140 } else {
11431141 Instruction::CastOps opcode = CastInst::getCastOpcode(*AI,
11441142 false, ParamTy, false);
1145 Args.push_back(Builder->CreateCast(opcode, *AI, ParamTy, "tmp"));
1143 Args.push_back(Builder->CreateCast(opcode, *AI, ParamTy));
11461144 }
11471145
11481146 // Add any parameter attributes.
11681166 // Must promote to pass through va_arg area!
11691167 Instruction::CastOps opcode =
11701168 CastInst::getCastOpcode(*AI, false, PTy, false);
1171 Args.push_back(Builder->CreateCast(opcode, *AI, PTy, "tmp"));
1169 Args.push_back(Builder->CreateCast(opcode, *AI, PTy));
11721170 } else {
11731171 Args.push_back(*AI);
11741172 }
12121210 if (!NV->getType()->isVoidTy()) {
12131211 Instruction::CastOps opcode =
12141212 CastInst::getCastOpcode(NC, false, OldRetTy, false);
1215 NV = NC = CastInst::Create(opcode, NC, OldRetTy, "tmp");
1213 NV = NC = CastInst::Create(opcode, NC, OldRetTy);
12161214 NC->setDebugLoc(Caller->getDebugLoc());
12171215
12181216 // If this is an invoke instruction, we should insert it after the first
121121 } else {
122122 Amt = ConstantInt::get(AI.getArraySize()->getType(), Scale);
123123 // Insert before the alloca, not before the cast.
124 Amt = AllocaBuilder.CreateMul(Amt, NumElements, "tmp");
124 Amt = AllocaBuilder.CreateMul(Amt, NumElements);
125125 }
126126
127127 if (uint64_t Offset = (AllocElTySize*ArrayOffset)/CastElTySize) {
128128 Value *Off = ConstantInt::get(AI.getArraySize()->getType(),
129129 Offset, true);
130 Amt = AllocaBuilder.CreateAdd(Amt, Off, "tmp");
130 Amt = AllocaBuilder.CreateAdd(Amt, Off);
131131 }
132132
133133 AllocaInst *New = AllocaBuilder.CreateAlloca(CastElTy, Amt);
456456 // Canonicalize trunc x to i1 -> (icmp ne (and x, 1), 0), likewise for vector.
457457 if (DestTy->getScalarSizeInBits() == 1) {
458458 Constant *One = ConstantInt::get(Src->getType(), 1);
459 Src = Builder->CreateAnd(Src, One, "tmp");
459 Src = Builder->CreateAnd(Src, One);
460460 Value *Zero = Constant::getNullValue(Src->getType());
461461 return new ICmpInst(ICmpInst::ICMP_NE, Src, Zero);
462462 }
518518 In->getType()->getScalarSizeInBits()-1);
519519 In = Builder->CreateLShr(In, Sh, In->getName()+".lobit");
520520 if (In->getType() != CI.getType())
521 In = Builder->CreateIntCast(In, CI.getType(), false/*ZExt*/, "tmp");
521 In = Builder->CreateIntCast(In, CI.getType(), false/*ZExt*/);
522522
523523 if (ICI->getPredicate() == ICmpInst::ICMP_SGT) {
524524 Constant *One = ConstantInt::get(In->getType(), 1);
572572
573573 if ((Op1CV != 0) == isNE) { // Toggle the low bit.
574574 Constant *One = ConstantInt::get(In->getType(), 1);
575 In = Builder->CreateXor(In, One, "tmp");
575 In = Builder->CreateXor(In, One);
576576 }
577577
578578 if (CI.getType() == In->getType())
820820 AndValue));
821821 }
822822 if (SrcSize > DstSize) {
823 Value *Trunc = Builder->CreateTrunc(A, CI.getType(), "tmp");
823 Value *Trunc = Builder->CreateTrunc(A, CI.getType());
824824 APInt AndValue(APInt::getLowBitsSet(DstSize, MidSize));
825825 return BinaryOperator::CreateAnd(Trunc,
826826 ConstantInt::get(Trunc->getType(),
867867 Value *TI0 = TI->getOperand(0);
868868 if (TI0->getType() == CI.getType()) {
869869 Constant *ZC = ConstantExpr::getZExt(C, CI.getType());
870 Value *NewAnd = Builder->CreateAnd(TI0, ZC, "tmp");
870 Value *NewAnd = Builder->CreateAnd(TI0, ZC);
871871 return BinaryOperator::CreateXor(NewAnd, ZC);
872872 }
873873 }
900900 Op0->getType()->getScalarSizeInBits()-1);
901901 Value *In = Builder->CreateAShr(Op0, Sh, Op0->getName()+".lobit");
902902 if (In->getType() != CI.getType())
903 In = Builder->CreateIntCast(In, CI.getType(), true/*SExt*/, "tmp");
903 In = Builder->CreateIntCast(In, CI.getType(), true/*SExt*/);
904904
905905 if (Pred == ICmpInst::ICMP_SGT)
906906 In = Builder->CreateNot(In, In->getName()+".not");
13061306 if (CI.getOperand(0)->getType()->getScalarSizeInBits() >
13071307 TD->getPointerSizeInBits()) {
13081308 Value *P = Builder->CreateTrunc(CI.getOperand(0),
1309 TD->getIntPtrType(CI.getContext()), "tmp");
1309 TD->getIntPtrType(CI.getContext()));
13101310 return new IntToPtrInst(P, CI.getType());
13111311 }
13121312 if (CI.getOperand(0)->getType()->getScalarSizeInBits() <
13131313 TD->getPointerSizeInBits()) {
13141314 Value *P = Builder->CreateZExt(CI.getOperand(0),
1315 TD->getIntPtrType(CI.getContext()), "tmp");
1315 TD->getIntPtrType(CI.getContext()));
13161316 return new IntToPtrInst(P, CI.getType());
13171317 }
13181318 }
13811381 if (TD) {
13821382 if (CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits()) {
13831383 Value *P = Builder->CreatePtrToInt(CI.getOperand(0),
1384 TD->getIntPtrType(CI.getContext()),
1385 "tmp");
1384 TD->getIntPtrType(CI.getContext()));
13861385 return new TruncInst(P, CI.getType());
13871386 }
13881387 if (CI.getType()->getScalarSizeInBits() > TD->getPointerSizeInBits()) {
13891388 Value *P = Builder->CreatePtrToInt(CI.getOperand(0),
1390 TD->getIntPtrType(CI.getContext()),
1391 "tmp");
1389 TD->getIntPtrType(CI.getContext()));
13921390 return new ZExtInst(P, CI.getType());
13931391 }
13941392 }
11851185 // Compute C << Y.
11861186 Value *NS;
11871187 if (Shift->getOpcode() == Instruction::LShr) {
1188 NS = Builder->CreateShl(AndCST, Shift->getOperand(1), "tmp");
1188 NS = Builder->CreateShl(AndCST, Shift->getOperand(1));
11891189 } else {
11901190 // Insert a logical shift.
1191 NS = Builder->CreateLShr(AndCST, Shift->getOperand(1), "tmp");
1191 NS = Builder->CreateLShr(AndCST, Shift->getOperand(1));
11921192 }
11931193
11941194 // Compute X & (C << Y).
24832483 match(D, m_ConstantInt(C2)) && Op1->hasOneUse()) {
24842484 Constant *NC = ConstantInt::get(I.getContext(),
24852485 C1->getValue() ^ C2->getValue());
2486 Value *Xor = Builder->CreateXor(C, NC, "tmp");
2486 Value *Xor = Builder->CreateXor(C, NC);
24872487 return new ICmpInst(I.getPredicate(), A, Xor);
24882488 }
24892489
25192519 }
25202520
25212521 if (X) { // Build (X^Y) & Z
2522 Op1 = Builder->CreateXor(X, Y, "tmp");
2523 Op1 = Builder->CreateAnd(Op1, Z, "tmp");
2522 Op1 = Builder->CreateXor(X, Y);
2523 Op1 = Builder->CreateAnd(Op1, Z);
25242524 I.setOperand(0, Op1);
25252525 I.setOperand(1, Constant::getNullValue(Op1->getType()));
25262526 return &I;
3737 m_Value(B))) &&
3838 // The "1" can be any value known to be a power of 2.
3939 isPowerOfTwo(PowerOf2, IC.getTargetData())) {
40 A = IC.Builder->CreateSub(A, B, "tmp");
40 A = IC.Builder->CreateSub(A, B);
4141 return IC.Builder->CreateShl(PowerOf2, A);
4242 }
4343
130130 { Value *X; ConstantInt *C1;
131131 if (Op0->hasOneUse() &&
132132 match(Op0, m_Add(m_Value(X), m_ConstantInt(C1)))) {
133 Value *Add = Builder->CreateMul(X, CI, "tmp");
133 Value *Add = Builder->CreateMul(X, CI);
134134 return BinaryOperator::CreateAdd(Add, Builder->CreateMul(C1, CI));
135135 }
136136 }
243243
244244 if (BoolCast) {
245245 Value *V = Builder->CreateSub(Constant::getNullValue(I.getType()),
246 BoolCast, "tmp");
246 BoolCast);
247247 return BinaryOperator::CreateAnd(V, OtherOp);
248248 }
249249 }
465465 { const APInt *CI; Value *N;
466466 if (match(Op1, m_Shl(m_Power2(CI), m_Value(N)))) {
467467 if (*CI != 1)
468 N = Builder->CreateAdd(N, ConstantInt::get(I.getType(), CI->logBase2()),
469 "tmp");
468 N = Builder->CreateAdd(N, ConstantInt::get(I.getType(),CI->logBase2()));
470469 if (I.isExact())
471470 return BinaryOperator::CreateExactLShr(Op0, N);
472471 return BinaryOperator::CreateLShr(Op0, N);
629628 // Turn A % (C << N), where C is 2^k, into A & ((C << N)-1)
630629 if (match(Op1, m_Shl(m_Power2(), m_Value()))) {
631630 Constant *N1 = Constant::getAllOnesValue(I.getType());
632 Value *Add = Builder->CreateAdd(Op1, N1, "tmp");
631 Value *Add = Builder->CreateAdd(Op1, N1);
633632 return BinaryOperator::CreateAnd(Op0, Add);
634633 }
635634
324324 if ((RHSKnownOne & LHSKnownOne) == RHSKnownOne) {
325325 Constant *AndC = Constant::getIntegerValue(VTy,
326326 ~RHSKnownOne & DemandedMask);
327 Instruction *And =
328 BinaryOperator::CreateAnd(I->getOperand(0), AndC, "tmp");
327 Instruction *And = BinaryOperator::CreateAnd(I->getOperand(0), AndC);
329328 return InsertNewInstWith(And, *I);
330329 }
331330 }
350349
351350 Constant *AndC =
352351 ConstantInt::get(I->getType(), NewMask & AndRHS->getValue());
353 Instruction *NewAnd =
354 BinaryOperator::CreateAnd(I->getOperand(0), AndC, "tmp");
352 Instruction *NewAnd = BinaryOperator::CreateAnd(I->getOperand(0), AndC);
355353 InsertNewInstWith(NewAnd, *I);
356354
357355 Constant *XorC =
358356 ConstantInt::get(I->getType(), NewMask & XorRHS->getValue());
359 Instruction *NewXor =
360 BinaryOperator::CreateXor(NewAnd, XorC, "tmp");
357 Instruction *NewXor = BinaryOperator::CreateXor(NewAnd, XorC);
361358 return InsertNewInstWith(NewXor, *I);
362359 }
363360
821821 DEBUG(dbgs() << "CGP: Reusing nonlocal addrmode: " << AddrMode << " for "
822822 << *MemoryInst);
823823 if (SunkAddr->getType() != Addr->getType())
824 SunkAddr = Builder.CreateBitCast(SunkAddr, Addr->getType(), "tmp");
824 SunkAddr = Builder.CreateBitCast(SunkAddr, Addr->getType());
825825 } else {
826826 DEBUG(dbgs() << "CGP: SINKING nonlocal addrmode: " << AddrMode << " for "
827827 << *MemoryInst);
945945 // Compute which bits of the stored value are being used by the load. Convert
946946 // to an integer type to start with.
947947 if (SrcVal->getType()->isPointerTy())
948 SrcVal = Builder.CreatePtrToInt(SrcVal, TD.getIntPtrType(Ctx), "tmp");
948 SrcVal = Builder.CreatePtrToInt(SrcVal, TD.getIntPtrType(Ctx));
949949 if (!SrcVal->getType()->isIntegerTy())
950 SrcVal = Builder.CreateBitCast(SrcVal, IntegerType::get(Ctx, StoreSize*8),
951 "tmp");
950 SrcVal = Builder.CreateBitCast(SrcVal, IntegerType::get(Ctx, StoreSize*8));
952951
953952 // Shift the bits to the least significant depending on endianness.
954953 unsigned ShiftAmt;
958957 ShiftAmt = (StoreSize-LoadSize-Offset)*8;
959958
960959 if (ShiftAmt)
961 SrcVal = Builder.CreateLShr(SrcVal, ShiftAmt, "tmp");
960 SrcVal = Builder.CreateLShr(SrcVal, ShiftAmt);
962961
963962 if (LoadSize != StoreSize)
964 SrcVal = Builder.CreateTrunc(SrcVal, IntegerType::get(Ctx, LoadSize*8),
965 "tmp");
963 SrcVal = Builder.CreateTrunc(SrcVal, IntegerType::get(Ctx, LoadSize*8));
966964
967965 return CoerceAvailableValueToLoadType(SrcVal, LoadTy, InsertPt, TD);
968966 }
491491 Value *BranchVal = LIC;
492492 if (!isa(Val) ||
493493 Val->getType() != Type::getInt1Ty(LIC->getContext()))
494 BranchVal = new ICmpInst(InsertPt, ICmpInst::ICMP_EQ, LIC, Val, "tmp");
494 BranchVal = new ICmpInst(InsertPt, ICmpInst::ICMP_EQ, LIC, Val);
495495 else if (Val != ConstantInt::getTrue(Val->getContext()))
496496 // We want to enter the new loop when the condition is true.
497497 std::swap(TrueDest, FalseDest);
616616
617617 if (LoadInst *LI = dyn_cast(User)) {
618618 // The load is a bit extract from NewAI shifted right by Offset bits.
619 Value *LoadedVal = Builder.CreateLoad(NewAI, "tmp");
619 Value *LoadedVal = Builder.CreateLoad(NewAI);
620620 Value *NewLoadVal
621621 = ConvertScalar_ExtractValue(LoadedVal, LI->getType(), Offset, Builder);
622622 LI->replaceAllUsesWith(NewLoadVal);
821821 // a shuffle vector.
822822 if (FromType->getPrimitiveSizeInBits() ==
823823 ToType->getPrimitiveSizeInBits())
824 return Builder.CreateBitCast(FromVal, ToType, "tmp");
824 return Builder.CreateBitCast(FromVal, ToType);
825825 else
826826 return CreateShuffleVectorCast(FromVal, ToType, Builder);
827827 }
837837 LLVMContext &Context = FromVal->getContext();
838838 Type *CastTy = VectorType::get(CastElementTy,
839839 NumCastVectorElements);
840 Value *Cast = Builder.CreateBitCast(FromVal, CastTy, "tmp");
840 Value *Cast = Builder.CreateBitCast(FromVal, CastTy);
841841
842842 unsigned EltSize = TD.getTypeAllocSizeInBits(CastElementTy);
843843 unsigned Elt = Offset/EltSize;
844844 assert(EltSize*Elt == Offset && "Invalid modulus in validity checking");
845845 Value *Extract = Builder.CreateExtractElement(Cast, ConstantInt::get(
846 Type::getInt32Ty(Context), Elt), "tmp");
847 return Builder.CreateBitCast(Extract, ToType, "tmp");
846 Type::getInt32Ty(Context), Elt));
847 return Builder.CreateBitCast(Extract, ToType);
848848 }
849849
850850 // Otherwise it must be an element access.
855855 assert(EltSize*Elt == Offset && "Invalid modulus in validity checking");
856856 }
857857 // Return the element extracted out of it.
858 Value *V = Builder.CreateExtractElement(FromVal, ConstantInt::get(
859 Type::getInt32Ty(FromVal->getContext()), Elt), "tmp");
858 Value *V = Builder.CreateExtractElement(FromVal, Builder.getInt32(Elt));
860859 if (V->getType() != ToType)
861 V = Builder.CreateBitCast(V, ToType, "tmp");
860 V = Builder.CreateBitCast(V, ToType);
862861 return V;
863862 }
864863
871870 Value *Elt = ConvertScalar_ExtractValue(FromVal, ST->getElementType(i),
872871 Offset+Layout.getElementOffsetInBits(i),
873872 Builder);
874 Res = Builder.CreateInsertValue(Res, Elt, i, "tmp");
873 Res = Builder.CreateInsertValue(Res, Elt, i);
875874 }
876875 return Res;
877876 }
882881 for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
883882 Value *Elt = ConvertScalar_ExtractValue(FromVal, AT->getElementType(),
884883 Offset+i*EltSize, Builder);
885 Res = Builder.CreateInsertValue(Res, Elt, i, "tmp");
884 Res = Builder.CreateInsertValue(Res, Elt, i);
886885 }
887886 return Res;
888887 }
908907 // only some bits are used.
909908 if (ShAmt > 0 && (unsigned)ShAmt < NTy->getBitWidth())
910909 FromVal = Builder.CreateLShr(FromVal,
911 ConstantInt::get(FromVal->getType(),
912 ShAmt), "tmp");
910 ConstantInt::get(FromVal->getType(), ShAmt));
913911 else if (ShAmt < 0 && (unsigned)-ShAmt < NTy->getBitWidth())
914912 FromVal = Builder.CreateShl(FromVal,
915 ConstantInt::get(FromVal->getType(),
916 -ShAmt), "tmp");
913 ConstantInt::get(FromVal->getType(), -ShAmt));
917914
918915 // Finally, unconditionally truncate the integer to the right width.
919916 unsigned LIBitWidth = TD.getTypeSizeInBits(ToType);
920917 if (LIBitWidth < NTy->getBitWidth())
921918 FromVal =
922919 Builder.CreateTrunc(FromVal, IntegerType::get(FromVal->getContext(),
923 LIBitWidth), "tmp");
920 LIBitWidth));
924921 else if (LIBitWidth > NTy->getBitWidth())
925922 FromVal =
926923 Builder.CreateZExt(FromVal, IntegerType::get(FromVal->getContext(),
927 LIBitWidth), "tmp");
924 LIBitWidth));
928925
929926 // If the result is an integer, this is a trunc or bitcast.
930927 if (ToType->isIntegerTy()) {
931928 // Should be done.
932929 } else if (ToType->isFloatingPointTy() || ToType->isVectorTy()) {
933930 // Just do a bitcast, we know the sizes match up.
934 FromVal = Builder.CreateBitCast(FromVal, ToType, "tmp");
931 FromVal = Builder.CreateBitCast(FromVal, ToType);
935932 } else {
936933 // Otherwise must be a pointer.
937 FromVal = Builder.CreateIntToPtr(FromVal, ToType, "tmp");
934 FromVal = Builder.CreateIntToPtr(FromVal, ToType);
938935 }
939936 assert(FromVal->getType() == ToType && "Didn't convert right?");
940937 return FromVal;
970967 // a shuffle vector.
971968 if (VTy->getPrimitiveSizeInBits() ==
972969 SV->getType()->getPrimitiveSizeInBits())
973 return Builder.CreateBitCast(SV, AllocaType, "tmp");
970 return Builder.CreateBitCast(SV, AllocaType);
974971 else
975972 return CreateShuffleVectorCast(SV, VTy, Builder);
976973 }
983980 ValSize);
984981 unsigned NumCastVectorElements = VecSize / ValSize;
985982
986 LLVMContext &Context = SV->getContext();
987 Type *OldCastTy = VectorType::get(CastElementTy,
988 NumCastVectorElements);
989 Value *OldCast = Builder.CreateBitCast(Old, OldCastTy, "tmp");
990
991 Value *SVCast = Builder.CreateBitCast(SV, CastElementTy, "tmp");
983 Type *OldCastTy = VectorType::get(CastElementTy, NumCastVectorElements);
984 Value *OldCast = Builder.CreateBitCast(Old, OldCastTy);
985
986 Value *SVCast = Builder.CreateBitCast(SV, CastElementTy);
992987
993988 unsigned EltSize = TD.getTypeAllocSizeInBits(CastElementTy);
994989 unsigned Elt = Offset/EltSize;
995990 assert(EltSize*Elt == Offset && "Invalid modulus in validity checking");
996991 Value *Insert =
997 Builder.CreateInsertElement(OldCast, SVCast, ConstantInt::get(
998 Type::getInt32Ty(Context), Elt), "tmp");
999 return Builder.CreateBitCast(Insert, AllocaType, "tmp");
992 Builder.CreateInsertElement(OldCast, SVCast, Builder.getInt32(Elt));
993 return Builder.CreateBitCast(Insert, AllocaType);
1000994 }
1001995
1002996 // Must be an element insertion.
1003997 assert(SV->getType() == VTy->getElementType());
1004998 uint64_t EltSize = TD.getTypeAllocSizeInBits(VTy->getElementType());
1005999 unsigned Elt = Offset/EltSize;
1006 return Builder.CreateInsertElement(Old, SV,
1007 ConstantInt::get(Type::getInt32Ty(SV->getContext()), Elt),
1008 "tmp");
1000 return Builder.CreateInsertElement(Old, SV, Builder.getInt32(Elt));
10091001 }
10101002
10111003 // If SV is a first-class aggregate value, insert each value recursively.
10121004 if (StructType *ST = dyn_cast(SV->getType())) {
10131005 const StructLayout &Layout = *TD.getStructLayout(ST);
10141006 for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) {
1015 Value *Elt = Builder.CreateExtractValue(SV, i, "tmp");
1007 Value *Elt = Builder.CreateExtractValue(SV, i);
10161008 Old = ConvertScalar_InsertValue(Elt, Old,
10171009 Offset+Layout.getElementOffsetInBits(i),
10181010 Builder);
10231015 if (ArrayType *AT = dyn_cast(SV->getType())) {
10241016 uint64_t EltSize = TD.getTypeAllocSizeInBits(AT->getElementType());
10251017 for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
1026 Value *Elt = Builder.CreateExtractValue(SV, i, "tmp");
1018 Value *Elt = Builder.CreateExtractValue(SV, i);
10271019 Old = ConvertScalar_InsertValue(Elt, Old, Offset+i*EltSize, Builder);
10281020 }
10291021 return Old;
10361028 unsigned SrcStoreWidth = TD.getTypeStoreSizeInBits(SV->getType());
10371029 unsigned DestStoreWidth = TD.getTypeStoreSizeInBits(AllocaType);
10381030 if (SV->getType()->isFloatingPointTy() || SV->getType()->isVectorTy())
1039 SV = Builder.CreateBitCast(SV,
1040 IntegerType::get(SV->getContext(),SrcWidth), "tmp");
1031 SV = Builder.CreateBitCast(SV, IntegerType::get(SV->getContext(),SrcWidth));
10411032 else if (SV->getType()->isPointerTy())
1042 SV = Builder.CreatePtrToInt(SV, TD.getIntPtrType(SV->getContext()), "tmp");
1033 SV = Builder.CreatePtrToInt(SV, TD.getIntPtrType(SV->getContext()));
10431034
10441035 // Zero extend or truncate the value if needed.
10451036 if (SV->getType() != AllocaType) {
10461037 if (SV->getType()->getPrimitiveSizeInBits() <
10471038 AllocaType->getPrimitiveSizeInBits())
1048 SV = Builder.CreateZExt(SV, AllocaType, "tmp");
1039 SV = Builder.CreateZExt(SV, AllocaType);
10491040 else {
10501041 // Truncation may be needed if storing more than the alloca can hold
10511042 // (undefined behavior).
1052 SV = Builder.CreateTrunc(SV, AllocaType, "tmp");
1043 SV = Builder.CreateTrunc(SV, AllocaType);
10531044 SrcWidth = DestWidth;
10541045 SrcStoreWidth = DestStoreWidth;
10551046 }
10721063 // only some bits in the structure are set.
10731064 APInt Mask(APInt::getLowBitsSet(DestWidth, SrcWidth));
10741065 if (ShAmt > 0 && (unsigned)ShAmt < DestWidth) {
1075 SV = Builder.CreateShl(SV, ConstantInt::get(SV->getType(),
1076 ShAmt), "tmp");
1066 SV = Builder.CreateShl(SV, ConstantInt::get(SV->getType(), ShAmt));
10771067 Mask <<= ShAmt;
10781068 } else if (ShAmt < 0 && (unsigned)-ShAmt < DestWidth) {
1079 SV = Builder.CreateLShr(SV, ConstantInt::get(SV->getType(),
1080 -ShAmt), "tmp");
1069 SV = Builder.CreateLShr(SV, ConstantInt::get(SV->getType(), -ShAmt));
10811070 Mask = Mask.lshr(-ShAmt);
10821071 }
10831072
873873 Callee->getAttributes());
874874 Value *FAbs = EmitUnaryFloatFnCall(Sqrt, "fabs", B,
875875 Callee->getAttributes());
876 Value *FCmp = B.CreateFCmpOEQ(Op1, NegInf, "tmp");
877 Value *Sel = B.CreateSelect(FCmp, Inf, FAbs, "tmp");
876 Value *FCmp = B.CreateFCmpOEQ(Op1, NegInf);
877 Value *Sel = B.CreateSelect(FCmp, Inf, FAbs);
878878 return Sel;
879879 }
880880
907907 Value *LdExpArg = 0;
908908 if (SIToFPInst *OpC = dyn_cast(Op)) {
909909 if (OpC->getOperand(0)->getType()->getPrimitiveSizeInBits() <= 32)
910 LdExpArg = B.CreateSExt(OpC->getOperand(0), B.getInt32Ty(), "tmp");
910 LdExpArg = B.CreateSExt(OpC->getOperand(0), B.getInt32Ty());
911911 } else if (UIToFPInst *OpC = dyn_cast(Op)) {
912912 if (OpC->getOperand(0)->getType()->getPrimitiveSizeInBits() < 32)
913 LdExpArg = B.CreateZExt(OpC->getOperand(0), B.getInt32Ty(), "tmp");
913 LdExpArg = B.CreateZExt(OpC->getOperand(0), B.getInt32Ty());
914914 }
915915
916916 if (LdExpArg) {
995995 Value *F = Intrinsic::getDeclaration(Callee->getParent(),
996996 Intrinsic::cttz, ArgType);
997997 Value *V = B.CreateCall(F, Op, "cttz");
998 V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1), "tmp");
999 V = B.CreateIntCast(V, B.getInt32Ty(), false, "tmp");
1000
1001 Value *Cond = B.CreateICmpNE(Op, Constant::getNullValue(ArgType), "tmp");
998 V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1));
999 V = B.CreateIntCast(V, B.getInt32Ty(), false);
1000
1001 Value *Cond = B.CreateICmpNE(Op, Constant::getNullValue(ArgType));
10021002 return B.CreateSelect(Cond, V, B.getInt32(0));
10031003 }
10041004 };
220220 return;
221221
222222 ICmpInst *ICmp = new ICmpInst(Rem, ICmpInst::ICMP_EQ,
223 Rem->getOperand(0), Rem->getOperand(1),
224 "tmp");
223 Rem->getOperand(0), Rem->getOperand(1));
225224 SelectInst *Sel =
226225 SelectInst::Create(ICmp,
227226 ConstantInt::get(Rem->getType(), 0),
0 ; RUN: opt < %s -indvars -S -enable-iv-rewrite | FileCheck %s
1 ; CHECK: %p.2.ip.1 = getelementptr [3 x [3 x double]]* %p, i64 2, i64 %tmp, i64 1
1 ; CHECK: %p.2.ip.1 = getelementptr [3 x [3 x double]]* %p, i64 2, i64 %0, i64 1
22 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n:32:64"
33
44 ; Indvars shouldn't expand this to
88 define void @test1(i32* %A) {
99 call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
1010 ret void
11 ; CHECK: %tmp = bitcast i32* %A to i8*
12 ; CHECK: call void @test1a(i8* %tmp)
11 ; CHECK: %1 = bitcast i32* %A to i8*
12 ; CHECK: call void @test1a(i8* %1)
1313 ; CHECK: ret void
1414 }
1515
2323 define i32 @test2(i32 %A) {
2424 call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
2525 ret i32 %A
26 ; CHECK: %tmp = trunc i32 %A to i8
27 ; CHECK: call void @test2a(i8 %tmp)
26 ; CHECK: %1 = trunc i32 %A to i8
27 ; CHECK: call void @test2a(i8 %1)
2828 ; CHECK: ret i32 %A
2929 }
3030
3737 call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B
3838 )
3939 ret void
40 ; CHECK: %tmp = zext i8 %B to i32
41 ; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %tmp)
40 ; CHECK: %1 = zext i8 %B to i32
41 ; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %1)
4242 ; CHECK: ret void
4343 }
4444
5353 %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; [#uses=1]
5454 ret i32 %X
5555 ; CHECK: %X = call i8 @test4a()
56 ; CHECK: %tmp = zext i8 %X to i32
57 ; CHECK: ret i32 %tmp
56 ; CHECK: %1 = zext i8 %X to i32
57 ; CHECK: ret i32 %1
5858 }
5959
6060
44 entry:
55 ; CHECK: test1
66 ; CHECK: ptrtoint i32* %x to i64
7 %tmp = ptrtoint i32* %x to i1
8 ret i1 %tmp
7 %0 = ptrtoint i32* %x to i1
8 ret i1 %0
99 }
1010
1111 define i32* @test2(i128 %x) nounwind {
1212 entry:
1313 ; CHECK: test2
14 ; CHECK: inttoptr i64 %tmp1 to i32*
15 %tmp = inttoptr i128 %x to i32*
16 ret i32* %tmp
14 ; CHECK: inttoptr i64 %0 to i32*
15 %0 = inttoptr i128 %x to i32*
16 ret i32* %0
1717 }
1818
1919 ; PR3574
2020 ; CHECK: f0
21 ; CHECK: %tmp = zext i32 %a0 to i64
22 ; CHECK: ret i64 %tmp
21 ; CHECK: %1 = zext i32 %a0 to i64
22 ; CHECK: ret i64 %1
2323 define i64 @f0(i32 %a0) nounwind {
2424 %t0 = inttoptr i32 %a0 to i8*
2525 %t1 = ptrtoint i8* %t0 to i64
66
77 ; CHECK: @test1
88 ; CHECK: and <2 x i64> %a,
9 ; CHECK: icmp ne <2 x i64> %tmp, zeroinitializer
9 ; CHECK: icmp ne <2 x i64> %1, zeroinitializer
1010 }
1111
1212 ; The ashr turns into an lshr.
6161 ret void
6262 ; CHECK: @test2
6363 ; CHECK: br i1 %cmp10,
64 ; CHECK: %tmp = mul i64 %Size, 4
65 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base1, i8 1, i64 %tmp, i32 4, i1 false)
64 ; CHECK: %0 = mul i64 %Size, 4
65 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base1, i8 1, i64 %0, i32 4, i1 false)
6666 ; CHECK-NOT: store
6767 }
6868
33 ; LSR should property handle the post-inc offset when folding the
44 ; non-IV operand of an icmp into the IV.
55
6 ; CHECK: %tmp2 = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
7 ; CHECK: %tmp3 = lshr i64 %tmp2, 1
8 ; CHECK: %tmp4 = mul i64 %tmp3, 2
6 ; CHECK: %5 = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
7 ; CHECK: %6 = lshr i64 %5, 1
8 ; CHECK: %7 = mul i64 %6, 2
99 ; CHECK: br label %for.body
1010 ; CHECK: for.body:
11 ; CHECK: %lsr.iv5 = phi i64 [ %lsr.iv.next, %for.body ], [ %tmp4, %for.body.lr.ph ]
12 ; CHECK: %lsr.iv.next = add i64 %lsr.iv5, -2
13 ; CHECK: %lsr.iv.next6 = inttoptr i64 %lsr.iv.next to i16*
14 ; CHECK: %cmp27 = icmp eq i16* %lsr.iv.next6, null
11 ; CHECK: %lsr.iv2 = phi i64 [ %lsr.iv.next, %for.body ], [ %7, %for.body.lr.ph ]
12 ; CHECK: %lsr.iv.next = add i64 %lsr.iv2, -2
13 ; CHECK: %lsr.iv.next3 = inttoptr i64 %lsr.iv.next to i16*
14 ; CHECK: %cmp27 = icmp eq i16* %lsr.iv.next3, null
1515
1616 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
1717 target triple = "x86_64-unknown-linux-gnu"
109109 ; CHECK-NOT: alloca
110110 ; CHECK: bitcast <4 x float> %x to <2 x double>
111111 ; CHECK-NEXT: extractelement <2 x double>
112 ; CHECK-NEXT: bitcast double %tmp4 to <2 x float>
112 ; CHECK-NEXT: bitcast double %2 to <2 x float>
113113 ; CHECK-NEXT: extractelement <4 x float>
114114 }
115115
124124 ; CHECK: bitcast <4 x float> %x to <2 x double>
125125 ; CHECK-NEXT: bitcast <2 x float> %y to double
126126 ; CHECK-NEXT: insertelement <2 x double>
127 ; CHECK-NEXT: bitcast <2 x double> %tmp2 to <4 x float>
127 ; CHECK-NEXT: bitcast <2 x double> %3 to <4 x float>
128128 }
129129
130130 define i256 @test9(<4 x i256> %x) {
139139 ; CHECK-NOT: alloca
140140 ; CHECK: bitcast <4 x i256> %x to <2 x i512>
141141 ; CHECK-NEXT: extractelement <2 x i512>
142 ; CHECK-NEXT: bitcast i512 %tmp4 to <2 x i256>
142 ; CHECK-NEXT: bitcast i512 %2 to <2 x i256>
143143 ; CHECK-NEXT: extractelement <4 x i256>
144144 }
145145
154154 ; CHECK: bitcast <4 x i256> %x to <2 x i512>
155155 ; CHECK-NEXT: bitcast <2 x i256> %y to i512
156156 ; CHECK-NEXT: insertelement <2 x i512>
157 ; CHECK-NEXT: bitcast <2 x i512> %tmp2 to <4 x i256>
157 ; CHECK-NEXT: bitcast <2 x i512> %3 to <4 x i256>
158158 }
159159
160160 %union.v = type { <2 x i64> }
244244 ret void
245245 ; CHECK: @test15
246246 ; CHECK-NOT: alloca
247 ; CHECK: shufflevector <4 x i64> %tmpV2, <4 x i64> undef, <3 x i32>
247 ; CHECK: shufflevector <4 x i64> %tmpV1, <4 x i64> undef, <3 x i32>
248248 }
249249
250250 define <4 x float> @test16(<4 x float> %x, i64 %y0, i64 %y1) {
66 ; CHECK: define float @foo(float %x) nounwind {
77 ; CHECK: %sqrtf = call float @sqrtf(float %x) nounwind readonly
88 ; CHECK: %fabsf = call float @fabsf(float %sqrtf) nounwind readonly
9 ; CHECK: %tmp = fcmp oeq float %x, 0xFFF0000000000000
10 ; CHECK: %tmp1 = select i1 %tmp, float 0x7FF0000000000000, float %fabsf
11 ; CHECK: ret float %tmp1
9 ; CHECK: %1 = fcmp oeq float %x, 0xFFF0000000000000
10 ; CHECK: %retval = select i1 %1, float 0x7FF0000000000000, float %fabsf
11 ; CHECK: ret float %retval
1212
1313 define float @foo(float %x) nounwind {
1414 %retval = call float @powf(float %x, float 0.5)
1818 ; CHECK: define double @doo(double %x) nounwind {
1919 ; CHECK: %sqrt = call double @sqrt(double %x) nounwind readonly
2020 ; CHECK: %fabs = call double @fabs(double %sqrt) nounwind readonly
21 ; CHECK: %tmp = fcmp oeq double %x, 0xFFF0000000000000
22 ; CHECK: %tmp1 = select i1 %tmp, double 0x7FF0000000000000, double %fabs
23 ; CHECK: ret double %tmp1
21 ; CHECK: %1 = fcmp oeq double %x, 0xFFF0000000000000
22 ; CHECK: %retval = select i1 %1, double 0x7FF0000000000000, double %fabs
23 ; CHECK: ret double %retval
2424 ; CHECK: }
2525
2626 define double @doo(double %x) nounwind {