20 using namespace PatternMatch;
29 Offset = CI->getZExtValue();
43 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(
I->getOperand(1))) {
44 if (
I->getOpcode() == Instruction::Shl) {
46 Scale = UINT64_C(1) << RHS->getZExtValue();
48 return I->getOperand(0);
51 if (
I->getOpcode() == Instruction::Mul) {
53 Scale = RHS->getZExtValue();
55 return I->getOperand(0);
58 if (
I->getOpcode() == Instruction::Add) {
64 Offset += RHS->getZExtValue();
87 AllocaBuilder.SetInsertPoint(AI.
getParent(), &AI);
94 unsigned AllocElTyAlign =
TD->getABITypeAlignment(AllocElTy);
95 unsigned CastElTyAlign =
TD->getABITypeAlignment(CastElTy);
96 if (CastElTyAlign < AllocElTyAlign)
return 0;
101 if (!AI.
hasOneUse() && CastElTyAlign == AllocElTyAlign)
return 0;
103 uint64_t AllocElTySize =
TD->getTypeAllocSize(AllocElTy);
104 uint64_t CastElTySize =
TD->getTypeAllocSize(CastElTy);
105 if (CastElTySize == 0 || AllocElTySize == 0)
return 0;
109 uint64_t AllocElTyStoreSize =
TD->getTypeStoreSize(AllocElTy);
110 uint64_t CastElTyStoreSize =
TD->getTypeStoreSize(CastElTy);
111 if (!AI.
hasOneUse() && CastElTyStoreSize < AllocElTyStoreSize)
return 0;
115 unsigned ArraySizeScale;
116 uint64_t ArrayOffset;
122 if ((AllocElTySize*ArraySizeScale) % CastElTySize != 0 ||
123 (AllocElTySize*ArrayOffset ) % CastElTySize != 0)
return 0;
125 unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize;
132 Amt = AllocaBuilder.CreateMul(Amt, NumElements);
135 if (uint64_t Offset = (AllocElTySize*ArrayOffset)/CastElTySize) {
138 Amt = AllocaBuilder.CreateAdd(Amt, Off);
141 AllocaInst *New = AllocaBuilder.CreateAlloca(CastElTy, Amt);
151 Value *NewCast = AllocaBuilder.CreateBitCast(New, AI.
getType(),
"tmpcast");
152 ReplaceInstUsesWith(AI, NewCast);
154 return ReplaceInstUsesWith(CI, New);
162 if (
Constant *
C = dyn_cast<Constant>(V)) {
175 case Instruction::Add:
176 case Instruction::Sub:
177 case Instruction::Mul:
181 case Instruction::AShr:
182 case Instruction::LShr:
183 case Instruction::Shl:
184 case Instruction::UDiv:
185 case Instruction::URem: {
191 case Instruction::Trunc:
192 case Instruction::ZExt:
193 case Instruction::SExt:
203 Opc == Instruction::SExt);
207 Value *False = EvaluateInDifferentType(I->
getOperand(2), Ty, isSigned);
227 return InsertNewInstWith(Res, *I);
254 DstTy, SrcIntPtrTy, MidIntPtrTy,
259 if ((Res == Instruction::IntToPtr && SrcTy != DstIntPtrTy) ||
260 (Res == Instruction::PtrToInt && DstTy != SrcIntPtrTy))
273 if (V->
getType() == Ty || isa<Constant>(V))
return false;
277 if (
const CastInst *CI = dyn_cast<CastInst>(V))
283 if (opc == Instruction::SExt && isa<CmpInst>(V) && Ty->
isVectorTy())
296 if (
CastInst *CSrc = dyn_cast<CastInst>(Src)) {
306 if (
SelectInst *SI = dyn_cast<SelectInst>(Src))
311 if (isa<PHINode>(Src)) {
337 if (isa<Constant>(V))
341 if (!I)
return false;
347 if ((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
357 case Instruction::Add:
358 case Instruction::Sub:
359 case Instruction::Mul:
367 case Instruction::UDiv:
368 case Instruction::URem: {
372 if (BitWidth < OrigBitWidth) {
382 case Instruction::Shl:
387 if (CI->getLimitedValue(BitWidth) < BitWidth)
391 case Instruction::LShr:
400 CI->getLimitedValue(BitWidth) < BitWidth) {
405 case Instruction::Trunc:
408 case Instruction::ZExt:
409 case Instruction::SExt:
437 if (
Instruction *Result = commonCastTransforms(CI))
442 if (SimplifyDemandedInstructionBits(CI))
452 if ((DestTy->
isVectorTy() || ShouldChangeType(SrcTy, DestTy)) &&
457 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
458 " to avoid cast: " << CI <<
'\n');
459 Value *Res = EvaluateInDifferentType(Src, DestTy,
false);
460 assert(Res->
getType() == DestTy);
461 return ReplaceInstUsesWith(CI, Res);
467 Src = Builder->CreateAnd(Src, One);
501 return BinaryOperator::CreateAnd(NewTrunc,
516 const APInt &Op1CV = Op1C->getValue();
522 if (!DoXform)
return ICI;
527 In = Builder->CreateLShr(In, Sh, In->
getName()+
".lobit");
528 if (In->getType() != CI.
getType())
529 In = Builder->CreateIntCast(In, CI.
getType(),
false);
533 In = Builder->CreateXor(In, One, In->
getName()+
".not");
536 return ReplaceInstUsesWith(CI, In);
547 if ((Op1CV == 0 || Op1CV.isPowerOf2()) &&
551 uint32_t BitWidth = Op1C->getType()->getBitWidth();
552 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
555 APInt KnownZeroMask(~KnownZero);
556 if (KnownZeroMask.isPowerOf2()) {
557 if (!DoXform)
return ICI;
560 if (Op1CV != 0 && (Op1CV != KnownZeroMask)) {
566 return ReplaceInstUsesWith(CI, Res);
569 uint32_t ShiftAmt = KnownZeroMask.logBase2();
578 if ((Op1CV != 0) == isNE) {
580 In = Builder->CreateXor(In, One);
583 if (CI.
getType() == In->getType())
584 return ReplaceInstUsesWith(CI, In);
595 uint32_t BitWidth = ITy->getBitWidth();
599 APInt KnownZeroLHS(BitWidth, 0), KnownOneLHS(BitWidth, 0);
600 APInt KnownZeroRHS(BitWidth, 0), KnownOneRHS(BitWidth, 0);
604 if (KnownZeroLHS == KnownZeroRHS && KnownOneLHS == KnownOneRHS) {
605 APInt KnownBits = KnownZeroLHS | KnownOneLHS;
606 APInt UnknownBit = ~KnownBits;
608 if (!DoXform)
return ICI;
610 Value *Result = Builder->CreateXor(LHS, RHS);
613 if (KnownOneLHS.uge(UnknownBit))
614 Result = Builder->CreateAnd(Result,
618 Result = Builder->CreateLShr(
624 return ReplaceInstUsesWith(CI, Result);
653 if (isa<Constant>(V))
657 if (!I)
return false;
670 case Instruction::ZExt:
671 case Instruction::SExt:
672 case Instruction::Trunc:
677 case Instruction::Add:
678 case Instruction::Sub:
679 case Instruction::Mul:
684 if (BitsToClear == 0 && Tmp == 0)
703 case Instruction::Shl:
709 uint64_t ShiftAmt = Amt->getZExtValue();
710 BitsToClear = ShiftAmt < BitsToClear ? BitsToClear - ShiftAmt : 0;
714 case Instruction::LShr:
720 BitsToClear += Amt->getZExtValue();
764 if (
Instruction *Result = commonCastTransforms(CI))
769 if (SimplifyDemandedInstructionBits(CI))
779 unsigned BitsToClear;
780 if ((DestTy->isVectorTy() || ShouldChangeType(SrcTy, DestTy)) &&
782 assert(BitsToClear < SrcTy->getScalarSizeInBits() &&
783 "Unreasonable BitsToClear");
786 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
787 " to avoid zero extend: " << CI);
788 Value *Res = EvaluateInDifferentType(Src, DestTy,
false);
789 assert(Res->
getType() == DestTy);
792 uint32_t DestBitSize = DestTy->getScalarSizeInBits();
797 DestBitSize-SrcBitsKept)))
798 return ReplaceInstUsesWith(CI, Res);
803 return BinaryOperator::CreateAnd(Res, C);
809 if (
TruncInst *CSrc = dyn_cast<TruncInst>(Src)) {
814 Value *
A = CSrc->getOperand(0);
816 unsigned MidSize = CSrc->getType()->getScalarSizeInBits();
822 if (SrcSize < DstSize) {
829 if (SrcSize == DstSize) {
834 if (SrcSize > DstSize) {
837 return BinaryOperator::CreateAnd(Trunc,
843 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Src))
844 return transformZExtICmp(ICI, CI);
852 if (LHS && RHS && LHS->
hasOneUse() && RHS->hasOneUse() &&
853 (transformZExtICmp(LHS, CI,
false) ||
854 transformZExtICmp(RHS, CI,
false))) {
856 Value *RCast = Builder->CreateZExt(RHS, CI.
getType(), RHS->getName());
865 Value *TI0 = TI->getOperand(0);
868 BinaryOperator::CreateAnd(TI0,
877 And->getOperand(1) ==
C)
878 if (
TruncInst *TI = dyn_cast<TruncInst>(
And->getOperand(0))) {
879 Value *TI0 = TI->getOperand(0);
882 Value *NewAnd = Builder->CreateAnd(TI0, ZC);
883 return BinaryOperator::CreateXor(NewAnd, ZC);
905 if (
ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
913 Value *In = Builder->CreateAShr(Op0, Sh, Op0->
getName()+
".lobit");
914 if (In->getType() != CI.
getType())
915 In = Builder->CreateIntCast(In, CI.
getType(),
true);
918 In = Builder->CreateNot(In, In->getName()+
".not");
919 return ReplaceInstUsesWith(CI, In);
926 ICI->
isEquality() && (Op1C->isZero() || Op1C->getValue().isPowerOf2())){
927 unsigned BitWidth = Op1C->getType()->getBitWidth();
928 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
931 APInt KnownZeroMask(~KnownZero);
932 if (KnownZeroMask.isPowerOf2()) {
936 if (!Op1C->isZero() && Op1C->getValue() != KnownZeroMask) {
940 return ReplaceInstUsesWith(CI, V);
946 unsigned ShiftAmt = KnownZeroMask.countTrailingZeros();
949 In = Builder->CreateLShr(In,
954 In = Builder->CreateAdd(In,
960 unsigned ShiftAmt = KnownZeroMask.countLeadingZeros();
963 In = Builder->CreateShl(In,
968 BitWidth - 1),
"sext");
972 return ReplaceInstUsesWith(CI, In);
982 Type *EltTy = VTy->getElementType();
986 Value *In = Builder->CreateAShr(Op0, VSh, Op0->
getName()+
".lobit");
987 return ReplaceInstUsesWith(CI, In);
1004 "Can't sign extend type to a smaller type");
1006 if (isa<Constant>(V))
1010 if (!I)
return false;
1021 case Instruction::SExt:
1022 case Instruction::ZExt:
1023 case Instruction::Trunc:
1028 case Instruction::Add:
1029 case Instruction::Sub:
1030 case Instruction::Mul:
1070 if (SimplifyDemandedInstructionBits(CI))
1080 if ((DestTy->isVectorTy() || ShouldChangeType(SrcTy, DestTy)) &&
1083 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
1084 " to avoid sign extend: " << CI);
1085 Value *Res = EvaluateInDifferentType(Src, DestTy,
true);
1086 assert(Res->
getType() == DestTy);
1089 uint32_t DestBitSize = DestTy->getScalarSizeInBits();
1094 return ReplaceInstUsesWith(CI, Res);
1098 return BinaryOperator::CreateAShr(Builder->CreateShl(Res, ShAmt,
"sext"),
1104 if (
TruncInst *TI = dyn_cast<TruncInst>(Src))
1105 if (TI->hasOneUse() && TI->getOperand(0)->getType() == DestTy) {
1107 uint32_t DestBitSize = DestTy->getScalarSizeInBits();
1111 Value *Res = Builder->CreateShl(TI->getOperand(0), ShAmt,
"sext");
1112 return BinaryOperator::CreateAShr(Res, ShAmt);
1115 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Src))
1116 return transformSExtICmp(ICI, CI);
1139 unsigned ShAmt = CA->getZExtValue()+SrcDstSize-MidSize;
1141 A = Builder->CreateShl(A, ShAmtV, CI.
getName());
1142 return BinaryOperator::CreateAShr(A, ShAmtV);
1164 if (I->
getOpcode() == Instruction::FPExt)
1170 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
1179 if (CFP->getType()->isDoubleTy())
1201 case Instruction::FAdd:
1202 case Instruction::FSub:
1203 case Instruction::FMul:
1204 case Instruction::FDiv:
1205 case Instruction::FRem:
1209 if (LHSTrunc->
getType() != SrcTy &&
1210 RHSTrunc->getType() != SrcTy) {
1215 RHSTrunc->getType()->getScalarSizeInBits() <= DstSize) {
1216 LHSTrunc = Builder->CreateFPExt(LHSTrunc, CI.
getType());
1217 RHSTrunc = Builder->CreateFPExt(RHSTrunc, CI.
getType());
1258 Value *Args[] = { InnerTrunc };
1276 if (Arg && Arg->
getOpcode() == Instruction::FPExt &&
1286 Builder->getFloatTy(), Builder->getFloatTy(),
1295 EraseInstFromFunction(*Call);
1304 return commonCastTransforms(CI);
1310 return commonCastTransforms(FI);
1318 if ((isa<UIToFPInst>(OpI) || isa<SIToFPInst>(OpI)) &&
1322 return ReplaceInstUsesWith(FI, OpI->
getOperand(0));
1324 return commonCastTransforms(FI);
1330 return commonCastTransforms(FI);
1338 if ((isa<UIToFPInst>(OpI) || isa<SIToFPInst>(OpI)) &&
1342 return ReplaceInstUsesWith(FI, OpI->
getOperand(0));
1344 return commonCastTransforms(FI);
1348 return commonCastTransforms(CI);
1352 return commonCastTransforms(CI);
1363 TD->getPointerSizeInBits(AS)) {
1386 if (GEP->hasAllZeroIndices()) {
1396 return commonCastTransforms(CI);
1402 unsigned AS = GEP->getPointerAddressSpace();
1403 unsigned OffsetBits =
TD->getPointerSizeInBits(AS);
1404 APInt Offset(OffsetBits, 0);
1406 if (GEP->hasOneUse() &&
1408 GEP->accumulateConstantOffset(*
TD, Offset)) {
1412 if (FindElementAtOffset(OrigBase->
getType(),
1418 Value *NGEP = cast<GEPOperator>(GEP)->isInBounds() ?
1419 Builder->CreateInBoundsGEP(OrigBase, NewIndices) :
1420 Builder->CreateGEP(OrigBase, NewIndices);
1423 if (isa<BitCastInst>(CI))
1425 assert(isa<PtrToIntInst>(CI));
1431 return commonCastTransforms(CI);
1440 return commonPointerCastTransforms(CI);
1446 return commonPointerCastTransforms(CI);
1500 for (
unsigned i = 0, e = SrcElts; i != e; ++i)
1504 for (
unsigned i = 0, e = DestTy->
getNumElements()-SrcElts; i != e; ++i)
1535 "Shift should be a multiple of the element type size");
1538 if (isa<UndefValue>(V))
return true;
1542 if (V->
getType() == VecEltTy) {
1544 if (
Constant *
C = dyn_cast<Constant>(V))
1545 if (
C->isNullValue())
1550 ElementIndex = Elements.
size() - ElementIndex - 1;
1553 if (Elements[ElementIndex] != 0)
1556 Elements[ElementIndex] = V;
1560 if (
Constant *
C = dyn_cast<Constant>(V)) {
1569 Shift, Elements, VecEltTy, IC);
1573 if (!isa<IntegerType>(
C->getType()))
1575 C->getType()->getPrimitiveSizeInBits()));
1579 for (
unsigned i = 0; i != NumElts; ++i) {
1580 unsigned ShiftI = Shift+i*ElementSize;
1593 if (I == 0)
return false;
1595 default:
return false;
1596 case Instruction::BitCast:
1598 Elements, VecEltTy, IC);
1599 case Instruction::ZExt:
1605 Elements, VecEltTy, IC);
1608 Elements, VecEltTy, IC) &&
1610 Elements, VecEltTy, IC);
1611 case Instruction::Shl: {
1614 if (CI == 0)
return false;
1618 Elements, VecEltTy, IC);
1656 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
1657 if (Elements[i] == 0)
continue;
1678 Value *VecInput = 0;
1681 isa<VectorType>(VecInput->
getType())) {
1705 isa<VectorType>(VecInput->
getType())) {
1737 return ReplaceInstUsesWith(CI, Src);
1739 if (
PointerType *DstPTy = dyn_cast<PointerType>(DestTy)) {
1741 Type *DstElTy = DstPTy->getElementType();
1753 if (
AllocaInst *AI = dyn_cast<AllocaInst>(Src))
1754 if (
Instruction *V = PromoteCastOfAllocation(CI, *AI))
1762 unsigned NumZeros = 0;
1763 while (SrcElTy != DstElTy &&
1764 isa<CompositeType>(SrcElTy) && !SrcElTy->
isPointerTy() &&
1766 SrcElTy = cast<CompositeType>(SrcElTy)->getTypeAtIndex(ZeroUInt);
1771 if (SrcElTy == DstElTy) {
1782 if (
VectorType *DestVTy = dyn_cast<VectorType>(DestTy)) {
1783 if (DestVTy->getNumElements() == 1 && !SrcTy->
isVectorTy()) {
1784 Value *Elem = Builder->CreateBitCast(Src, DestVTy->getElementType());
1790 if (isa<IntegerType>(SrcTy)) {
1794 if (isa<TruncInst>(Src) || isa<ZExtInst>(Src)) {
1795 CastInst *SrcCast = cast<CastInst>(Src);
1797 if (isa<VectorType>(BCIn->getOperand(0)->getType()))
1799 cast<VectorType>(DestTy), *
this))
1807 return ReplaceInstUsesWith(CI, V);
1811 if (
VectorType *SrcVTy = dyn_cast<VectorType>(SrcTy)) {
1812 if (SrcVTy->getNumElements() == 1) {
1817 Builder->CreateExtractElement(Src,
1825 dyn_cast<InsertElementInst>(CI.
getOperand(0)))
1834 if (SVI->hasOneUse() && DestTy->
isVectorTy() &&
1836 SVI->getType()->getNumElements() ==
1837 SVI->getOperand(0)->getType()->getVectorNumElements()) {
1842 if (((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(0))) &&
1844 ((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(1))) &&
1846 Value *LHS = Builder->CreateBitCast(SVI->getOperand(0), DestTy);
1847 Value *RHS = Builder->CreateBitCast(SVI->getOperand(1), DestTy);
1856 return commonPointerCastTransforms(CI);
1857 return commonCastTransforms(CI);
1861 return commonCastTransforms(CI);
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
static bool CanEvaluateSExtd(Value *V, Type *Ty)
void push_back(const T &Elt)
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
class_match< Value > m_Value()
m_Value() - Match an arbitrary value and ignore it.
static IntegerType * getInt1Ty(LLVMContext &C)
unsigned getScalarSizeInBits()
Instruction * visitBitCast(BitCastInst &CI)
static const fltSemantics IEEEdouble
The main container class for the LLVM Intermediate Representation.
void setAlignment(unsigned Align)
Intrinsic::ID getIntrinsicID() const
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=0)
static Instruction::CastOps isEliminableCastPair(const CastInst *CI, unsigned opcode, Type *DstTy, DataLayout *TD)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
This class represents zero extension of integer types.
Instruction * commonCastTransforms(CastInst &CI)
Implement the transforms common to all CastInst visitors.
bool hasNoSignedWrap() const
bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout *TD=0, unsigned Depth=0)
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
bool isPtrOrPtrVectorTy() const
int getFPMantissaWidth() const
static bool isEquality(Predicate P)
const Function * getParent() const
Return the enclosing method, or null if none.
This class represents a sign extension of integer types.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static Value * LookThroughFPExtensions(Value *V)
Instruction * visitUIToFP(CastInst &CI)
static bool CanEvaluateZExtd(Value *V, Type *Ty, unsigned &BitsToClear)
static Constant * FitsInFPType(ConstantFP *CFP, const fltSemantics &Sem)
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
static Constant * getNullValue(Type *Ty)
StringRef getName() const
Instruction * visitFPExt(CastInst &CI)
bool match(Val *V, const Pattern &P)
Instruction * visitFPToUI(FPToUIInst &FI)
This class represents a conversion between pointers from one address space to another.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
DataLayout * getDataLayout() const
Base class of casting instructions.
#define llvm_unreachable(msg)
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
unsigned getNumArgOperands() const
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
m_Trunc
InstCombiner - The -instcombine pass.
Instruction * visitIntToPtr(IntToPtrInst &CI)
Instruction * visitAddrSpaceCast(AddrSpaceCastInst &CI)
Type * getAllocatedType() const
static Type * getPPC_FP128Ty(LLVMContext &C)
static unsigned getTypeSizeIndex(unsigned Value, Type *Ty)
not_match< LHS > m_Not(const LHS &L)
This class represents a cast from a pointer to an integer.
uint64_t getZExtValue() const
Return the zero extended value.
static bool isMultipleOfTypeSize(unsigned Value, Type *Ty)
static bool CanEvaluateTruncated(Value *V, Type *Ty)
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
m_ZExt
Constant * ConstantFoldConstantExpression(const ConstantExpr *CE, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0)
This class represents a no-op cast from one type to another.
class_match< ConstantInt > m_ConstantInt()
m_ConstantInt() - Match an arbitrary ConstantInt and ignore it.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
This class represents a cast from floating point to signed integer.
unsigned getNumElements() const
Return the number of elements in the Vector type.
This class represents a truncation of integer types.
Type * getElementType() const
void ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout *TD=0, unsigned Depth=0)
unsigned getNumIncomingValues() const
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Construct any of the CastInst subclasses.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
static Value * DecomposeSimpleLinearExpr(Value *Val, unsigned &Scale, uint64_t &Offset)
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=0)
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
unsigned getIntrinsicID() const LLVM_READONLY
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
m_BitCast
LLVM Constant Representation.
PointerType * getType() const
int64_t getSExtValue() const
Get sign extended value.
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
unsigned getAlignment() const
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
BasicBlock * getIncomingBlock(unsigned i) const
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
Represent an integer comparison operator.
opStatus convert(const fltSemantics &, roundingMode, bool *)
Value * getOperand(unsigned i) const
Integer representation type.
unsigned countPopulation() const
Count the number of bits set.
Predicate getPredicate() const
Return the predicate for this instruction.
static Instruction * OptimizeVectorResize(Value *InVal, VectorType *DestTy, InstCombiner &IC)
This class represents a cast from an integer to a pointer.
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
Instruction * visitFPToSI(FPToSIInst &FI)
unsigned getNumContainedTypes() const
static UndefValue * get(Type *T)
LLVMContext & getContext() const
All values hold a context through their type.
const Value * getTrueValue() const
static const fltSemantics IEEEhalf
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=0)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
BinaryOps getOpcode() const
static IntegerType * get(LLVMContext &C, unsigned NumBits)
Get or create an IntegerType instance.
static Constant * getBitCast(Constant *C, Type *Ty)
static Value * OptimizeIntegerToVectorInsertions(BitCastInst &CI, InstCombiner &IC)
Class for constant integers.
Value * getIncomingValue(unsigned i) const
unsigned getVectorNumElements() const
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Instruction * visitSExt(SExtInst &CI)
This class represents a cast from floating point to unsigned integer.
Instruction * visitZExt(ZExtInst &CI)
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
static unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
Determine if a cast pair is eliminable.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
Function * getCalledFunction() const
static Constant * getTrunc(Constant *C, Type *Ty)
static Constant * get(Type *Ty, double V)
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
AttributeSet getAttributes() const
Return the attribute list for this Function.
Value * getArgOperand(unsigned i) const
Class for arbitrary precision integers.
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=0)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static Instruction * OptimizeIntToFloatBitCast(BitCastInst &CI, InstCombiner &IC)
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Instruction * visitTrunc(TruncInst &CI)
static const fltSemantics IEEEsingle
static IntegerType * getInt32Ty(LLVMContext &C)
static Constant * getZExt(Constant *C, Type *Ty)
Instruction * visitSIToFP(CastInst &CI)
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=0)
unsigned getPrimitiveSizeInBits() const
unsigned ComputeNumSignBits(Value *Op, const DataLayout *TD=0, unsigned Depth=0)
const APFloat & getValueAPF() const
void setAttributes(const AttributeSet &Attrs)
This class represents a truncation of floating point types.
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
const Value * getArraySize() const
Instruction * commonPointerCastTransforms(CastInst &CI)
Implement the transforms for cast of pointer (bitcast/ptrtoint)
const Value * getFalseValue() const
static BinaryOperator * CreateFNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=0)
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=0)
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
Instruction * visitPtrToInt(PtrToIntInst &CI)
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
const BasicBlock * getParent() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
bool hasNoUnsignedWrap() const
static bool CollectInsertionElements(Value *V, unsigned Shift, SmallVectorImpl< Value * > &Elements, Type *VecEltTy, InstCombiner &IC)
Instruction * visitFPTrunc(FPTruncInst &CI)