22 using namespace llvm::PatternMatch;
30 assert(I &&
"No instruction?");
31 assert(OpNo < I->getNumOperands() &&
"Operand index too large");
35 if (!OpC)
return false;
39 if ((~Demanded & OpC->
getValue()) == 0)
53 bool InstCombiner::SimplifyDemandedInstructionBits(
Instruction &Inst) {
55 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
58 Value *V = SimplifyDemandedUseBits(&Inst, DemandedMask,
59 KnownZero, KnownOne, 0);
60 if (V == 0)
return false;
61 if (V == &Inst)
return true;
62 ReplaceInstUsesWith(Inst, V);
69 bool InstCombiner::SimplifyDemandedBits(
Use &U,
APInt DemandedMask,
72 Value *NewVal = SimplifyDemandedUseBits(U.
get(), DemandedMask,
73 KnownZero, KnownOne, Depth);
74 if (NewVal == 0)
return false;
101 Value *InstCombiner::SimplifyDemandedUseBits(
Value *V,
APInt DemandedMask,
104 assert(V != 0 &&
"Null pointer of Value???");
105 assert(Depth <= 6 &&
"Limit Search Depth");
109 "SimplifyDemandedBits needs to know bit widths!");
115 "Value *V, DemandedMask, KnownZero and KnownOne "
116 "must have same BitWidth");
119 KnownOne = CI->getValue() & DemandedMask;
120 KnownZero = ~KnownOne & DemandedMask;
123 if (isa<ConstantPointerNull>(V)) {
126 KnownZero = DemandedMask;
132 if (DemandedMask == 0) {
133 if (isa<UndefValue>(V))
141 APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
142 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
166 if ((DemandedMask & ~LHSKnownZero & RHSKnownOne) ==
167 (DemandedMask & ~LHSKnownZero))
169 if ((DemandedMask & ~RHSKnownZero & LHSKnownOne) ==
170 (DemandedMask & ~RHSKnownZero))
174 if ((DemandedMask & (RHSKnownZero|LHSKnownZero)) == DemandedMask)
188 if ((DemandedMask & ~LHSKnownOne & RHSKnownZero) ==
189 (DemandedMask & ~LHSKnownOne))
191 if ((DemandedMask & ~RHSKnownOne & LHSKnownZero) ==
192 (DemandedMask & ~RHSKnownOne))
197 if ((DemandedMask & (~RHSKnownZero) & LHSKnownOne) ==
198 (DemandedMask & (~RHSKnownZero)))
200 if ((DemandedMask & (~LHSKnownZero) & RHSKnownOne) ==
201 (DemandedMask & (~LHSKnownZero)))
212 if ((DemandedMask & RHSKnownZero) == DemandedMask)
214 if ((DemandedMask & LHSKnownZero) == DemandedMask)
237 RHSKnownZero, RHSKnownOne, Depth+1) ||
238 SimplifyDemandedBits(I->
getOperandUse(0), DemandedMask & ~RHSKnownZero,
239 LHSKnownZero, LHSKnownOne, Depth+1))
241 assert(!(RHSKnownZero & RHSKnownOne) &&
"Bits known to be one AND zero?");
242 assert(!(LHSKnownZero & LHSKnownOne) &&
"Bits known to be one AND zero?");
246 if ((DemandedMask & ~LHSKnownZero & RHSKnownOne) ==
247 (DemandedMask & ~LHSKnownZero))
249 if ((DemandedMask & ~RHSKnownZero & LHSKnownOne) ==
250 (DemandedMask & ~RHSKnownZero))
254 if ((DemandedMask & (RHSKnownZero|LHSKnownZero)) == DemandedMask)
262 KnownOne = RHSKnownOne & LHSKnownOne;
264 KnownZero = RHSKnownZero | LHSKnownZero;
269 RHSKnownZero, RHSKnownOne, Depth+1) ||
270 SimplifyDemandedBits(I->
getOperandUse(0), DemandedMask & ~RHSKnownOne,
271 LHSKnownZero, LHSKnownOne, Depth+1))
273 assert(!(RHSKnownZero & RHSKnownOne) &&
"Bits known to be one AND zero?");
274 assert(!(LHSKnownZero & LHSKnownOne) &&
"Bits known to be one AND zero?");
278 if ((DemandedMask & ~LHSKnownOne & RHSKnownZero) ==
279 (DemandedMask & ~LHSKnownOne))
281 if ((DemandedMask & ~RHSKnownOne & LHSKnownZero) ==
282 (DemandedMask & ~RHSKnownOne))
287 if ((DemandedMask & (~RHSKnownZero) & LHSKnownOne) ==
288 (DemandedMask & (~RHSKnownZero)))
290 if ((DemandedMask & (~LHSKnownZero) & RHSKnownOne) ==
291 (DemandedMask & (~LHSKnownZero)))
299 KnownZero = RHSKnownZero & LHSKnownZero;
301 KnownOne = RHSKnownOne | LHSKnownOne;
305 RHSKnownZero, RHSKnownOne, Depth+1) ||
307 LHSKnownZero, LHSKnownOne, Depth+1))
309 assert(!(RHSKnownZero & RHSKnownOne) &&
"Bits known to be one AND zero?");
310 assert(!(LHSKnownZero & LHSKnownOne) &&
"Bits known to be one AND zero?");
314 if ((DemandedMask & RHSKnownZero) == DemandedMask)
316 if ((DemandedMask & LHSKnownZero) == DemandedMask)
322 if ((DemandedMask & ~RHSKnownZero & ~LHSKnownZero) == 0) {
326 return InsertNewInstWith(Or, *I);
333 if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) {
335 if ((RHSKnownOne & LHSKnownOne) == RHSKnownOne) {
337 ~RHSKnownOne & DemandedMask);
339 return InsertNewInstWith(And, *I);
355 isa<ConstantInt>(LHSInst->getOperand(1)) &&
356 (LHSKnownOne & RHSKnownOne & DemandedMask) != 0) {
357 ConstantInt *AndRHS = cast<ConstantInt>(LHSInst->getOperand(1));
359 APInt NewMask = ~(LHSKnownOne & RHSKnownOne & DemandedMask);
364 InsertNewInstWith(NewAnd, *I);
368 Instruction *NewXor = BinaryOperator::CreateXor(NewAnd, XorC);
369 return InsertNewInstWith(NewXor, *I);
373 KnownZero= (RHSKnownZero & LHSKnownZero) | (RHSKnownOne & LHSKnownOne);
375 KnownOne = (RHSKnownZero & LHSKnownOne) | (RHSKnownOne & LHSKnownZero);
380 RHSKnownZero, RHSKnownOne, Depth+1) ||
382 LHSKnownZero, LHSKnownOne, Depth+1))
384 assert(!(RHSKnownZero & RHSKnownOne) &&
"Bits known to be one AND zero?");
385 assert(!(LHSKnownZero & LHSKnownOne) &&
"Bits known to be one AND zero?");
393 KnownOne = RHSKnownOne & LHSKnownOne;
394 KnownZero = RHSKnownZero & LHSKnownZero;
396 case Instruction::Trunc: {
398 DemandedMask = DemandedMask.
zext(truncBf);
399 KnownZero = KnownZero.
zext(truncBf);
400 KnownOne = KnownOne.
zext(truncBf);
402 KnownZero, KnownOne, Depth+1))
404 DemandedMask = DemandedMask.
trunc(BitWidth);
405 KnownZero = KnownZero.
trunc(BitWidth);
406 KnownOne = KnownOne.
trunc(BitWidth);
407 assert(!(KnownZero & KnownOne) &&
"Bits known to be one AND zero?");
410 case Instruction::BitCast:
417 if (DstVTy->getNumElements() != SrcVTy->getNumElements())
428 KnownZero, KnownOne, Depth+1))
430 assert(!(KnownZero & KnownOne) &&
"Bits known to be one AND zero?");
432 case Instruction::ZExt: {
436 DemandedMask = DemandedMask.
trunc(SrcBitWidth);
437 KnownZero = KnownZero.
trunc(SrcBitWidth);
438 KnownOne = KnownOne.
trunc(SrcBitWidth);
440 KnownZero, KnownOne, Depth+1))
442 DemandedMask = DemandedMask.
zext(BitWidth);
443 KnownZero = KnownZero.
zext(BitWidth);
444 KnownOne = KnownOne.
zext(BitWidth);
445 assert(!(KnownZero & KnownOne) &&
"Bits known to be one AND zero?");
450 case Instruction::SExt: {
454 APInt InputDemandedBits = DemandedMask &
460 if ((NewBits & DemandedMask) != 0)
461 InputDemandedBits.
setBit(SrcBitWidth-1);
463 InputDemandedBits = InputDemandedBits.
trunc(SrcBitWidth);
464 KnownZero = KnownZero.
trunc(SrcBitWidth);
465 KnownOne = KnownOne.
trunc(SrcBitWidth);
466 if (SimplifyDemandedBits(I->
getOperandUse(0), InputDemandedBits,
467 KnownZero, KnownOne, Depth+1))
469 InputDemandedBits = InputDemandedBits.
zext(BitWidth);
470 KnownZero = KnownZero.
zext(BitWidth);
471 KnownOne = KnownOne.
zext(BitWidth);
472 assert(!(KnownZero & KnownOne) &&
"Bits known to be one AND zero?");
479 if (KnownZero[SrcBitWidth-1] || (NewBits & ~DemandedMask) == NewBits) {
482 return InsertNewInstWith(NewCast, *I);
483 }
else if (KnownOne[SrcBitWidth-1]) {
488 case Instruction::Add: {
492 unsigned NLZ = DemandedMask.countLeadingZeros();
507 if (SimplifyDemandedBits(I->
getOperandUse(0), InDemandedBits,
508 LHSKnownZero, LHSKnownOne, Depth+1))
517 if (LHSKnownZero == 0 && LHSKnownOne == 0)
521 if ((LHSKnownZero & RHS->getValue()) == RHS->getValue()) {
525 return InsertNewInstWith(Or, *I);
537 const APInt &RHSVal = RHS->getValue();
538 APInt CarryBits((~LHSKnownZero + RHSVal) ^ (~LHSKnownZero ^ RHSVal));
544 KnownOne = ((LHSKnownZero & RHSVal) |
545 (LHSKnownOne & ~RHSVal)) & ~CarryBits;
549 KnownZero = LHSKnownZero & ~RHSVal & ~CarryBits;
553 if (DemandedMask[BitWidth-1] == 0) {
557 if (SimplifyDemandedBits(I->
getOperandUse(0), DemandedFromOps,
558 LHSKnownZero, LHSKnownOne, Depth+1) ||
560 LHSKnownZero, LHSKnownOne, Depth+1))
566 case Instruction::Sub:
569 if (DemandedMask[BitWidth-1] == 0) {
572 uint32_t NLZ = DemandedMask.countLeadingZeros();
574 if (SimplifyDemandedBits(I->
getOperandUse(0), DemandedFromOps,
575 LHSKnownZero, LHSKnownOne, Depth+1) ||
577 LHSKnownZero, LHSKnownOne, Depth+1))
588 APInt I0 = C0->getValue();
589 if ((I0 + 1).isPowerOf2() && (I0 | KnownZero).isAllOnesValue()) {
591 return InsertNewInstWith(Xor, *I);
595 case Instruction::Shl:
601 Value *R = SimplifyShrShlDemandedBits(Shr, I, DemandedMask,
602 KnownZero, KnownOne);
608 uint64_t ShiftAmt = SA->getLimitedValue(BitWidth-1);
609 APInt DemandedMaskIn(DemandedMask.lshr(ShiftAmt));
613 if (IOp->hasNoSignedWrap())
615 else if (IOp->hasNoUnsignedWrap())
618 if (SimplifyDemandedBits(I->
getOperandUse(0), DemandedMaskIn,
619 KnownZero, KnownOne, Depth+1))
621 assert(!(KnownZero & KnownOne) &&
"Bits known to be one AND zero?");
622 KnownZero <<= ShiftAmt;
623 KnownOne <<= ShiftAmt;
629 case Instruction::LShr:
632 uint64_t ShiftAmt = SA->getLimitedValue(BitWidth-1);
635 APInt DemandedMaskIn(DemandedMask.shl(ShiftAmt));
639 if (cast<LShrOperator>(I)->isExact())
642 if (SimplifyDemandedBits(I->
getOperandUse(0), DemandedMaskIn,
643 KnownZero, KnownOne, Depth+1))
645 assert(!(KnownZero & KnownOne) &&
"Bits known to be one AND zero?");
651 KnownZero |= HighBits;
655 case Instruction::AShr:
660 if (DemandedMask == 1) {
664 return InsertNewInstWith(NewVal, *I);
669 if (DemandedMask.isSignBit())
673 uint32_t ShiftAmt = SA->getLimitedValue(BitWidth-1);
676 APInt DemandedMaskIn(DemandedMask.shl(ShiftAmt));
679 if (DemandedMask.countLeadingZeros() <= ShiftAmt)
680 DemandedMaskIn.
setBit(BitWidth-1);
684 if (cast<AShrOperator>(I)->isExact())
687 if (SimplifyDemandedBits(I->
getOperandUse(0), DemandedMaskIn,
688 KnownZero, KnownOne, Depth+1))
690 assert(!(KnownZero & KnownOne) &&
"Bits known to be one AND zero?");
703 if (BitWidth <= ShiftAmt || KnownZero[BitWidth-ShiftAmt-1] ||
704 (HighBits & ~DemandedMask) == HighBits) {
708 NewVal->
setIsExact(cast<BinaryOperator>(I)->isExact());
709 return InsertNewInstWith(NewVal, *I);
710 }
else if ((KnownOne & SignBit) != 0) {
711 KnownOne |= HighBits;
715 case Instruction::SRem:
719 if (Rem->isAllOnesValue())
723 if (DemandedMask.ult(RA))
726 APInt LowBits = RA - 1;
729 LHSKnownZero, LHSKnownOne, Depth+1))
733 KnownZero = LHSKnownZero & LowBits;
734 KnownOne = LHSKnownOne & LowBits;
738 if (LHSKnownZero[BitWidth-1] || ((LHSKnownZero & LowBits) == LowBits))
739 KnownZero |= ~LowBits;
743 if (LHSKnownOne[BitWidth-1] && ((LHSKnownOne & LowBits) != 0))
744 KnownOne |= ~LowBits;
746 assert(!(KnownZero & KnownOne) &&
"Bits known to be one AND zero?");
752 if (DemandedMask.isNegative() && KnownZero.isNonNegative()) {
753 APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
756 if (LHSKnownZero.isNegative())
757 KnownZero.setBit(KnownZero.getBitWidth() - 1);
760 case Instruction::URem: {
761 APInt KnownZero2(BitWidth, 0), KnownOne2(BitWidth, 0);
764 KnownZero2, KnownOne2, Depth+1) ||
766 KnownZero2, KnownOne2, Depth+1))
769 unsigned Leaders = KnownZero2.countLeadingOnes();
770 Leaders = std::max(Leaders,
771 KnownZero2.countLeadingOnes());
777 switch (II->getIntrinsicID()) {
782 unsigned NLZ = DemandedMask.countLeadingZeros();
783 unsigned NTZ = DemandedMask.countTrailingZeros();
791 if (BitWidth-NLZ-NTZ == 8) {
792 unsigned ResultBit = NTZ;
793 unsigned InputBit = BitWidth-NTZ-8;
798 if (InputBit > ResultBit)
799 NewVal = BinaryOperator::CreateLShr(II->getArgOperand(0),
802 NewVal = BinaryOperator::CreateShl(II->getArgOperand(0),
805 return InsertNewInstWith(NewVal, *I);
822 if ((DemandedMask & (KnownZero|KnownOne)) == DemandedMask)
847 const APInt &ShlOp1 = cast<ConstantInt>(Shl->
getOperand(1))->getValue();
848 const APInt &ShrOp1 = cast<ConstantInt>(Shr->
getOperand(1))->getValue();
849 if (!ShlOp1 || !ShrOp1)
855 if (ShlOp1.
uge(BitWidth) || ShrOp1.
uge(BitWidth))
863 KnownZero &= DemandedMask;
868 bool isLshr = (Shr->
getOpcode() == Instruction::LShr);
869 BitMask1 = isLshr ? (BitMask1.lshr(ShrAmt) << ShlAmt) :
870 (BitMask1.ashr(ShrAmt) << ShlAmt);
872 if (ShrAmt <= ShlAmt) {
873 BitMask2 <<= (ShlAmt - ShrAmt);
875 BitMask2 = isLshr ? BitMask2.lshr(ShrAmt - ShlAmt):
876 BitMask2.ashr(ShrAmt - ShlAmt);
880 if ((BitMask1 & DemandedMask) == (BitMask2 & DemandedMask)) {
881 if (ShrAmt == ShlAmt)
888 if (ShrAmt < ShlAmt) {
890 New = BinaryOperator::CreateShl(VarX, Amt);
896 New = isLshr ? BinaryOperator::CreateLShr(VarX, Amt) :
898 if (cast<BinaryOperator>(Shr)->isExact())
902 return InsertNewInstWith(New, *Shl);
916 Value *InstCombiner::SimplifyDemandedVectorElts(
Value *V,
APInt DemandedElts,
919 unsigned VWidth = cast<VectorType>(V->
getType())->getNumElements();
921 assert((DemandedElts & ~EltMask) == 0 &&
"Invalid DemandedElts!");
923 if (isa<UndefValue>(V)) {
929 if (DemandedElts == 0) {
937 if (
Constant *
C = dyn_cast<Constant>(V)) {
943 Type *EltTy = cast<VectorType>(V->
getType())->getElementType();
947 for (
unsigned i = 0; i != VWidth; ++i) {
948 if (!DemandedElts[i]) {
954 Constant *Elt =
C->getAggregateElement(i);
955 if (Elt == 0)
return 0;
957 if (isa<UndefValue>(Elt)) {
967 return NewCV !=
C ? NewCV : 0;
986 DemandedElts = EltMask;
992 bool MadeChange =
false;
993 APInt UndefElts2(VWidth, 0);
998 case Instruction::InsertElement: {
1005 TmpV = SimplifyDemandedVectorElts(I->
getOperand(0), DemandedElts,
1006 UndefElts2, Depth+1);
1007 if (TmpV) { I->
setOperand(0, TmpV); MadeChange =
true; }
1014 if (IdxNo >= VWidth || !DemandedElts[IdxNo]) {
1021 APInt DemandedElts2 = DemandedElts;
1023 TmpV = SimplifyDemandedVectorElts(I->
getOperand(0), DemandedElts2,
1024 UndefElts, Depth+1);
1025 if (TmpV) { I->
setOperand(0, TmpV); MadeChange =
true; }
1028 UndefElts.clearBit(IdxNo);
1031 case Instruction::ShuffleVector: {
1033 uint64_t LHSVWidth =
1035 APInt LeftDemanded(LHSVWidth, 0), RightDemanded(LHSVWidth, 0);
1036 for (
unsigned i = 0; i < VWidth; i++) {
1037 if (DemandedElts[i]) {
1039 if (MaskVal != -1u) {
1040 assert(MaskVal < LHSVWidth * 2 &&
1041 "shufflevector mask index out of range!");
1042 if (MaskVal < LHSVWidth)
1043 LeftDemanded.setBit(MaskVal);
1045 RightDemanded.setBit(MaskVal - LHSVWidth);
1050 APInt UndefElts4(LHSVWidth, 0);
1051 TmpV = SimplifyDemandedVectorElts(I->
getOperand(0), LeftDemanded,
1052 UndefElts4, Depth+1);
1053 if (TmpV) { I->
setOperand(0, TmpV); MadeChange =
true; }
1055 APInt UndefElts3(LHSVWidth, 0);
1056 TmpV = SimplifyDemandedVectorElts(I->
getOperand(1), RightDemanded,
1057 UndefElts3, Depth+1);
1058 if (TmpV) { I->
setOperand(1, TmpV); MadeChange =
true; }
1060 bool NewUndefElts =
false;
1061 for (
unsigned i = 0; i < VWidth; i++) {
1063 if (MaskVal == -1u) {
1064 UndefElts.setBit(i);
1065 }
else if (!DemandedElts[i]) {
1066 NewUndefElts =
true;
1067 UndefElts.setBit(i);
1068 }
else if (MaskVal < LHSVWidth) {
1069 if (UndefElts4[MaskVal]) {
1070 NewUndefElts =
true;
1071 UndefElts.setBit(i);
1074 if (UndefElts3[MaskVal - LHSVWidth]) {
1075 NewUndefElts =
true;
1076 UndefElts.setBit(i);
1084 for (
unsigned i = 0; i < VWidth; ++i) {
1097 APInt LeftDemanded(DemandedElts), RightDemanded(DemandedElts);
1099 for (
unsigned i = 0; i < VWidth; i++) {
1100 if (CV->getAggregateElement(i)->isNullValue())
1101 LeftDemanded.clearBit(i);
1103 RightDemanded.clearBit(i);
1107 TmpV = SimplifyDemandedVectorElts(I->
getOperand(1), LeftDemanded,
1108 UndefElts, Depth+1);
1109 if (TmpV) { I->
setOperand(1, TmpV); MadeChange =
true; }
1111 TmpV = SimplifyDemandedVectorElts(I->
getOperand(2), RightDemanded,
1112 UndefElts2, Depth+1);
1113 if (TmpV) { I->
setOperand(2, TmpV); MadeChange =
true; }
1116 UndefElts &= UndefElts2;
1119 case Instruction::BitCast: {
1124 APInt InputDemandedElts(InVWidth, 0);
1127 if (VWidth == InVWidth) {
1131 InputDemandedElts = DemandedElts;
1132 }
else if (VWidth > InVWidth) {
1139 Ratio = VWidth/InVWidth;
1140 for (
unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx) {
1141 if (DemandedElts[OutIdx])
1142 InputDemandedElts.setBit(OutIdx/Ratio);
1151 Ratio = InVWidth/VWidth;
1152 for (
unsigned InIdx = 0; InIdx != InVWidth; ++InIdx)
1153 if (DemandedElts[InIdx/Ratio])
1154 InputDemandedElts.setBit(InIdx);
1158 TmpV = SimplifyDemandedVectorElts(I->
getOperand(0), InputDemandedElts,
1159 UndefElts2, Depth+1);
1165 UndefElts = UndefElts2;
1166 if (VWidth > InVWidth) {
1171 for (
unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx)
1172 if (UndefElts2[OutIdx/Ratio])
1173 UndefElts.setBit(OutIdx);
1174 }
else if (VWidth < InVWidth) {
1179 UndefElts = ~0ULL >> (64-VWidth);
1180 for (
unsigned InIdx = 0; InIdx != InVWidth; ++InIdx)
1181 if (!UndefElts2[InIdx])
1182 UndefElts.clearBit(InIdx/Ratio);
1189 case Instruction::Add:
1190 case Instruction::Sub:
1191 case Instruction::Mul:
1193 TmpV = SimplifyDemandedVectorElts(I->
getOperand(0), DemandedElts,
1194 UndefElts, Depth+1);
1195 if (TmpV) { I->
setOperand(0, TmpV); MadeChange =
true; }
1196 TmpV = SimplifyDemandedVectorElts(I->
getOperand(1), DemandedElts,
1197 UndefElts2, Depth+1);
1198 if (TmpV) { I->
setOperand(1, TmpV); MadeChange =
true; }
1202 UndefElts &= UndefElts2;
1204 case Instruction::FPTrunc:
1205 case Instruction::FPExt:
1206 TmpV = SimplifyDemandedVectorElts(I->
getOperand(0), DemandedElts,
1207 UndefElts, Depth+1);
1208 if (TmpV) { I->
setOperand(0, TmpV); MadeChange =
true; }
1227 TmpV = SimplifyDemandedVectorElts(II->
getArgOperand(0), DemandedElts,
1228 UndefElts, Depth+1);
1229 if (TmpV) { II->
setArgOperand(0, TmpV); MadeChange =
true; }
1230 TmpV = SimplifyDemandedVectorElts(II->
getArgOperand(1), DemandedElts,
1231 UndefElts2, Depth+1);
1232 if (TmpV) { II->
setArgOperand(1, TmpV); MadeChange =
true; }
1236 if (DemandedElts == 1) {
1256 TmpV = InsertNewInstWith(BinaryOperator::CreateFSub(LHS, RHS,
1261 TmpV = InsertNewInstWith(BinaryOperator::CreateFMul(LHS, RHS,
1271 InsertNewInstWith(New, *II);
1278 UndefElts &= UndefElts2;
1284 return MadeChange ? I : 0;
void clearAllBits()
Set every bit to 0.
static int getMaskValue(Constant *Mask, unsigned i)
const Use & getOperandUse(unsigned i) const
void push_back(const T &Elt)
IntegerType * getType() const
class_match< Value > m_Value()
m_Value() - Match an arbitrary value and ignore it.
void setHasNoSignedWrap(bool b=true)
static APInt getSignBit(unsigned BitWidth)
Get the SignBit for a specific bit width.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT abs() const
Get the absolute value;.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getScalarSizeInBits()
Intrinsic::ID getIntrinsicID() const
void setBit(unsigned bitPosition)
Set a given bit to 1.
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.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
static bool ShrinkDemandedConstant(Instruction *I, unsigned OpNo, APInt Demanded)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
static Constant * getNullValue(Type *Ty)
StringRef getName() const
bool match(Val *V, const Pattern &P)
Base class of casting instructions.
const APInt & getValue() const
Return the constant's value.
BinOp2_match< LHS, RHS, Instruction::LShr, Instruction::AShr > m_Shr(const LHS &L, const RHS &R)
m_Shr - Matches LShr or AShr.
#define llvm_unreachable(msg)
static Constant * get(ArrayRef< Constant * > V)
APInt lshr(const APInt &LHS, unsigned shiftAmt)
Logical right-shift function.
uint64_t getZExtValue() const
Return the zero extended value.
class_match< ConstantInt > m_ConstantInt()
m_ConstantInt() - Match an arbitrary ConstantInt and ignore it.
unsigned getNumElements() const
Return the number of elements in the Vector type.
void ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout *TD=0, unsigned Depth=0)
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
bool isIntOrIntVectorTy() const
APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const
Truncate to new width.
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=0)
LLVM Constant Representation.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Value * getOperand(unsigned i) const
static UndefValue * get(Type *T)
LLVMContext & getContext() const
All values hold a context through their type.
bool hasNoSignedWrap() const
hasNoSignedWrap - Determine whether the no signed wrap flag is set.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static Constant * getIntegerValue(Type *Ty, const APInt &V)
void setIsExact(bool b=true)
unsigned getIntegerBitWidth() const
Class for constant integers.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
void setOperand(unsigned i, Value *Val)
Value * getArgOperand(unsigned i) const
Class for arbitrary precision integers.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
bool isAllOnesValue() const
Determine if all bits are set.
static IntegerType * getInt32Ty(LLVMContext &C)
void clearBit(unsigned bitPosition)
Set a given bit to 0.
void setArgOperand(unsigned i, Value *v)
const Type * getScalarType() const
LLVM Value Representation.
bool hasNoUnsignedWrap() const
hasNoUnsignedWrap - Determine whether the no unsigned wrap flag is set.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD