21 using namespace PatternMatch;
23 #define DEBUG_TYPE "instcombine"
125 bool IsBswapLHS = (IntrLHS && IntrLHS->getIntrinsicID() == Intrinsic::bswap);
126 bool IsBswapRHS = (IntrRHS && IntrRHS->getIntrinsicID() == Intrinsic::bswap);
128 if (!IsBswapLHS && !IsBswapRHS)
131 if (!IsBswapLHS && !ConstLHS)
134 if (!IsBswapRHS && !ConstRHS)
139 Value *NewLHS = IsBswapLHS ? IntrLHS->getOperand(0) :
142 Value *NewRHS = IsBswapRHS ? IntrRHS->getOperand(0) :
143 Builder->getInt(ConstRHS->getValue().byteSwap());
145 Value *BinOp =
nullptr;
147 BinOp = Builder->CreateAnd(NewLHS, NewRHS);
149 BinOp = Builder->CreateOr(NewLHS, NewRHS);
151 BinOp = Builder->CreateXor(NewLHS, NewRHS);
155 return Builder->CreateCall(F, BinOp);
174 Value *
And = Builder->CreateAnd(X, AndRHS);
176 return BinaryOperator::CreateXor(And, Together);
181 if (Together != OpRHS) {
183 Value *
Or = Builder->CreateOr(X, Together);
185 return BinaryOperator::CreateAnd(Or, AndRHS);
189 if (TogetherCI && !TogetherCI->
isZero()){
194 Value *And = Builder->CreateAnd(X, Together);
196 return BinaryOperator::CreateOr(And, OpRHS);
201 case Instruction::Add:
216 if ((AddRHS & (AndRHSV-1)) == 0) {
221 if ((AddRHS & AndRHSV) == 0) {
226 Value *NewAnd = Builder->CreateAnd(X, AndRHS);
228 return BinaryOperator::CreateXor(NewAnd, AndRHS);
235 case Instruction::Shl: {
246 return ReplaceInstUsesWith(TheAnd, Op);
254 case Instruction::LShr: {
266 return ReplaceInstUsesWith(TheAnd, Op);
274 case Instruction::AShr:
287 ShVal = Builder->CreateLShr(ShVal, OpRHS, Op->
getName());
288 return BinaryOperator::CreateAnd(ShVal, AndRHS, TheAnd.
getName());
302 bool isSigned,
bool Inside) {
305 "Lo is not <= Hi in range emission code!");
309 return Builder->getFalse();
312 if (cast<ConstantInt>(Lo)->isMinValue(isSigned)) {
315 return Builder->CreateICmp(pred, V, Hi);
320 Value *Add = Builder->CreateAdd(V, NegLo, V->
getName()+
".off");
322 return Builder->CreateICmpULT(Add, UpperBound);
326 return Builder->getTrue();
329 Hi =
SubOne(cast<ConstantInt>(Hi));
330 if (cast<ConstantInt>(Lo)->isMinValue(isSigned)) {
333 return Builder->CreateICmp(pred, V, Hi);
339 Value *Add = Builder->CreateAdd(V, NegLo, V->
getName()+
".off");
341 return Builder->CreateICmpUGT(Add, LowerBound);
354 MB = BitWidth - ((V - 1) ^ V).countLeadingZeros();
375 !isa<ConstantInt>(LHSI->
getOperand(1)))
return nullptr;
380 default:
return nullptr;
392 uint32_t MB = 0, ME = 0;
412 return Builder->CreateSub(LHSI->
getOperand(0), RHS,
"fold");
413 return Builder->CreateAdd(LHSI->
getOperand(0), RHS,
"fold");
461 bool icmp_abit = (ACst && !ACst->
isZero() &&
463 bool icmp_bbit = (BCst && !BCst->isZero() &&
464 BCst->getValue().isPowerOf2());
466 if (CCst && CCst->isZero()) {
498 }
else if (ACst && CCst &&
513 }
else if (BCst && CCst &&
576 if (!(C->
getValue() + 1).isPowerOf2())
610 Value *L11,*L12,*L21,*L22;
613 L21 = L22 = L1 =
nullptr;
644 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
646 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
651 E =
R2; R1 =
nullptr; ok =
true;
660 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
661 A = R11; D = R12; E =
R2; ok =
true;
662 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
663 A = R12; D = R11; E =
R2; ok =
true;
678 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
679 A = R11; D = R12; E = R1; ok =
true;
680 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
681 A = R12; D = R11; E = R1; ok =
true;
691 }
else if (L12 == A) {
693 }
else if (L21 == A) {
695 }
else if (L22 == A) {
701 return left_type & right_type;
708 Value *
A =
nullptr, *B =
nullptr, *C =
nullptr, *D =
nullptr, *E =
nullptr;
712 if (mask == 0)
return nullptr;
714 "foldLogOpOfMaskedICmpsHelper must return an equality predicate.");
744 return Builder->
CreateICmp(NEWCC, newAnd, zero);
751 return Builder->
CreateICmp(NEWCC, newAnd, newOr);
765 if (!BCst)
return nullptr;
767 if (!DCst)
return nullptr;
779 else if (NewMask == DCst->
getValue())
791 else if (NewMask == DCst->
getValue())
806 if (!CCst)
return nullptr;
808 if (!ECst)
return nullptr;
821 return Builder->
CreateICmp(NEWCC, newAnd, newOr2);
867 default:
return nullptr;
871 bool IsNegative, IsNotNegative;
879 return Builder->CreateICmp(NewPred, Input, RangeEnd);
905 if (
Value *V = simplifyRangeCheck(LHS, RHS,
false))
909 if (
Value *V = simplifyRangeCheck(RHS, LHS,
false))
916 if (!LHSCst || !RHSCst)
return nullptr;
918 if (LHSCst == RHSCst && LHSCC == RHSCC) {
923 Value *NewOr = Builder->CreateOr(Val, Val2);
924 return Builder->CreateICmp(LHSCC, NewOr, LHSCst);
929 Value *NewOr = Builder->CreateOr(Val, Val2);
930 return Builder->CreateICmp(LHSCC, NewOr, LHSCst);
940 ConstantInt *AndCst, *SmallCst =
nullptr, *BigCst =
nullptr;
954 if (SmallCst && BigCst) {
960 if ((Low & AndCst->
getValue()) == 0 && (Low & BigCst->getValue()) == 0) {
961 Value *NewAnd = Builder->CreateAnd(V, Low | AndCst->
getValue());
964 return Builder->CreateICmp(LHSCC, NewAnd, NewVal);
971 if (Val != Val2)
return nullptr;
999 ShouldSwap = LHSCst->
getValue().
sgt(RHSCst->getValue());
1001 ShouldSwap = LHSCst->
getValue().
ugt(RHSCst->getValue());
1015 assert(LHSCst != RHSCst &&
"Compares not folded above?");
1031 if (LHSCst ==
SubOne(RHSCst))
1032 return Builder->CreateICmpULT(Val, LHSCst);
1034 return InsertRangeTest(Val,
AddOne(LHSCst), RHSCst,
false,
true);
1037 if (LHSCst ==
SubOne(RHSCst))
1038 return Builder->CreateICmpSLT(Val, LHSCst);
1049 if (LHSCst ==
SubOne(RHSCst)){
1051 Value *Add = Builder->CreateAdd(Val, AddCST, Val->
getName()+
".off");
1094 if (RHSCst ==
AddOne(LHSCst))
1095 return Builder->CreateICmp(LHSCC, Val, RHSCst);
1098 return InsertRangeTest(Val,
AddOne(LHSCst), RHSCst,
false,
true);
1112 if (RHSCst ==
AddOne(LHSCst))
1113 return Builder->CreateICmp(LHSCC, Val, RHSCst);
1116 return InsertRangeTest(Val,
AddOne(LHSCst), RHSCst,
true,
true);
1140 if (LHSC->getValueAPF().isNaN() || RHSC->getValueAPF().isNaN())
1141 return Builder->getFalse();
1147 if (isa<ConstantAggregateZero>(LHS->
getOperand(1)) &&
1148 isa<ConstantAggregateZero>(RHS->
getOperand(1)))
1158 if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) {
1164 if (Op0LHS == Op1LHS && Op0RHS == Op1RHS) {
1177 unsigned Op0Pred =
getFCmpCode(Op0CC, Op0Ordered);
1178 unsigned Op1Pred =
getFCmpCode(Op1CC, Op1Ordered);
1180 if (Op0Pred == 0 && Op1Pred == 0 && Op0Ordered != Op1Ordered)
1190 if (!Op0Ordered && (Op0Ordered == Op1Ordered))
1192 if (Op0Ordered && (Op0Ordered == Op1Ordered))
1199 return getFCmpValue(
true, Op1Pred, Op0LHS, Op0RHS, Builder);
1207 bool Changed = SimplifyAssociativeOrCommutative(I);
1210 if (
Value *V = SimplifyVectorOp(I))
1211 return ReplaceInstUsesWith(I, V);
1214 return ReplaceInstUsesWith(I, V);
1217 if (
Value *V = SimplifyUsingDistributiveLaws(I))
1218 return ReplaceInstUsesWith(I, V);
1222 if (SimplifyDemandedInstructionBits(I))
1225 if (
Value *V = SimplifyBSwap(I))
1226 return ReplaceInstUsesWith(I, V);
1228 if (
ConstantInt *AndRHS = dyn_cast<ConstantInt>(Op1)) {
1233 Value *Op0LHS = Op0I->getOperand(0);
1234 Value *Op0RHS = Op0I->getOperand(1);
1235 switch (Op0I->getOpcode()) {
1240 if (!Op0I->hasOneUse())
break;
1242 APInt NotAndRHS(~AndRHSMask);
1245 Value *NewRHS = Builder->CreateAnd(Op0RHS, AndRHS,
1249 if (!isa<Constant>(Op0RHS) &&
1252 Value *NewLHS = Builder->CreateAnd(Op0LHS, AndRHS,
1259 case Instruction::Add:
1263 if (
Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS,
false, I))
1264 return BinaryOperator::CreateAnd(V, AndRHS);
1265 if (
Value *V = FoldLogicalPlusAnd(Op0RHS, Op0LHS, AndRHS,
false, I))
1266 return BinaryOperator::CreateAnd(V, AndRHS);
1269 case Instruction::Sub:
1273 if (
Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS,
true, I))
1274 return BinaryOperator::CreateAnd(V, AndRHS);
1278 if (Op0I->hasOneUse() && !
match(Op0LHS,
m_Zero())) {
1284 Value *NewNeg = Builder->CreateNeg(Op0RHS);
1285 return BinaryOperator::CreateAnd(NewNeg, AndRHS);
1290 case Instruction::Shl:
1291 case Instruction::LShr:
1294 if (AndRHSMask == 1 && Op0LHS == AndRHS) {
1302 if (
ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1)))
1303 if (
Instruction *Res = OptAndOp(Op0I, Op0CI, AndRHS, I))
1316 Value *NewCast = Builder->CreateTrunc(X, I.
getType(),
"and.shrunk");
1319 return BinaryOperator::CreateAnd(NewCast, C3);
1327 if (isa<PHINode>(Op0))
1336 if (Op0->
hasOneUse() && Op1->hasOneUse()) {
1337 Value *Or = Builder->CreateOr(Op0NotVal, Op1NotVal,
1343 Value *
A =
nullptr, *B =
nullptr, *C =
nullptr, *D =
nullptr;
1347 ((A == C && B == D) || (A == D && B == C)))
1348 return BinaryOperator::CreateXor(A, B);
1353 ((A == C && B == D) || (A == D && B == C)))
1354 return BinaryOperator::CreateXor(A, B);
1358 Value *tmpOp0 = Op0;
1359 Value *tmpOp1 = Op1;
1362 if (A == Op1 || B == Op1 ) {
1378 if (A == tmpOp0 && !isa<Constant>(A))
1379 return BinaryOperator::CreateAnd(A, Builder->CreateNot(B));
1386 return BinaryOperator::CreateAnd(A, Op1);
1389 return BinaryOperator::CreateAnd(A, Op0);
1394 if (Op1->hasOneUse() || cast<BinaryOperator>(Op1)->hasOneUse())
1395 return BinaryOperator::CreateAnd(Op0, Builder->CreateNot(C));
1400 if (Op0->
hasOneUse() || cast<BinaryOperator>(Op0)->hasOneUse())
1401 return BinaryOperator::CreateAnd(Op1, Builder->CreateNot(C));
1406 return BinaryOperator::CreateAnd(A, B);
1411 return BinaryOperator::CreateAnd(A, B);
1418 if (
Value *Res = FoldAndOfICmps(LHS, RHS))
1419 return ReplaceInstUsesWith(I, Res);
1425 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
1426 if (
Value *Res = FoldAndOfICmps(LHS, Cmp))
1427 return ReplaceInstUsesWith(I, Builder->CreateAnd(Res, Y));
1428 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
1429 if (
Value *Res = FoldAndOfICmps(LHS, Cmp))
1430 return ReplaceInstUsesWith(I, Builder->CreateAnd(Res, X));
1433 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
1434 if (
Value *Res = FoldAndOfICmps(Cmp, RHS))
1435 return ReplaceInstUsesWith(I, Builder->CreateAnd(Res, Y));
1436 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
1437 if (
Value *Res = FoldAndOfICmps(Cmp, RHS))
1438 return ReplaceInstUsesWith(I, Builder->CreateAnd(Res, X));
1445 if (
Value *Res = FoldAndOfFCmps(LHS, RHS))
1446 return ReplaceInstUsesWith(I, Res);
1450 if (
CastInst *Op0C = dyn_cast<CastInst>(Op0))
1451 if (
CastInst *Op1C = dyn_cast<CastInst>(Op1)) {
1452 Type *SrcTy = Op0C->getOperand(0)->getType();
1453 if (Op0C->getOpcode() == Op1C->getOpcode() &&
1454 SrcTy == Op1C->getOperand(0)->getType() &&
1456 Value *Op0COp = Op0C->getOperand(0), *Op1COp = Op1C->getOperand(0);
1459 if (ShouldOptimizeCast(Op0C->getOpcode(), Op0COp, I.
getType()) &&
1460 ShouldOptimizeCast(Op1C->getOpcode(), Op1COp, I.
getType())) {
1461 Value *NewOp = Builder->CreateAnd(Op0COp, Op1COp, I.
getName());
1467 if (
ICmpInst *RHS = dyn_cast<ICmpInst>(Op1COp))
1468 if (
ICmpInst *LHS = dyn_cast<ICmpInst>(Op0COp))
1469 if (
Value *Res = FoldAndOfICmps(LHS, RHS))
1474 if (
FCmpInst *RHS = dyn_cast<FCmpInst>(Op1COp))
1475 if (
FCmpInst *LHS = dyn_cast<FCmpInst>(Op0COp))
1476 if (
Value *Res = FoldAndOfFCmps(LHS, RHS))
1483 bool OpsSwapped =
false;
1509 return Changed ? &I :
nullptr;
1550 cast<ConstantInt>(I->
getOperand(1))->getLimitedValue(~0U);
1552 if ((ShAmt & 7) || (ShAmt > 8*ByteValues.
size()))
1555 unsigned ByteShift = ShAmt >> 3;
1556 if (I->
getOpcode() == Instruction::Shl) {
1558 OverallLeftShift += ByteShift;
1559 ByteMask >>= ByteShift;
1562 OverallLeftShift -= ByteShift;
1563 ByteMask <<= ByteShift;
1564 ByteMask &= (~0U >> (32-ByteValues.
size()));
1567 if (OverallLeftShift >= (
int)ByteValues.
size())
return true;
1568 if (OverallLeftShift <= -(
int)ByteValues.
size())
return true;
1579 unsigned NumBytes = ByteValues.
size();
1581 const APInt &AndMask = cast<ConstantInt>(I->
getOperand(1))->getValue();
1583 for (
unsigned i = 0; i != NumBytes; ++i, Byte <<= 8) {
1586 if ((ByteMask & (1 << i)) == 0)
1590 APInt MaskB = AndMask & Byte;
1592 ByteMask &= ~(1U << i);
1622 unsigned DestByteNo = InputByteNo + OverallLeftShift;
1623 if (ByteValues.
size()-1-DestByteNo != InputByteNo)
1628 if (ByteValues[DestByteNo] && ByteValues[DestByteNo] != V)
1630 ByteValues[DestByteNo] = V;
1649 uint32_t ByteMask = ~0U >> (32-ByteValues.
size());
1654 Value *V = ByteValues[0];
1655 if (!V)
return nullptr;
1658 for (
unsigned i = 1, e = ByteValues.
size(); i != e; ++i)
1659 if (ByteValues[i] != V)
1672 Value *Cond =
nullptr;
1710 Value *Mask =
nullptr;
1711 Value *Masked =
nullptr;
1712 if (LAnd->
getOperand(0) == RAnd->getOperand(0) &&
1717 Mask = Builder->CreateOr(LAnd->
getOperand(1), RAnd->getOperand(1));
1718 Masked = Builder->CreateAnd(LAnd->
getOperand(0), Mask);
1719 }
else if (LAnd->
getOperand(1) == RAnd->getOperand(1) &&
1724 Mask = Builder->CreateOr(LAnd->
getOperand(0), RAnd->getOperand(0));
1725 Masked = Builder->CreateAnd(LAnd->
getOperand(1), Mask);
1745 LHSCC == RHSCC && LHSCst && RHSCst && LHS->
hasOneUse() &&
1747 LHSCst->
getValue() == (RHSCst->getValue())) {
1752 Value *LAddOpnd, *RAddOpnd;
1760 if (LAddOpnd == RAddOpnd && DiffCst.
isPowerOf2()) {
1763 MaxAddCst = RAddCst;
1765 MaxAddCst = LAddCst;
1771 APInt LowRangeDiff = RRangeLow ^ LRangeLow;
1772 APInt HighRangeDiff = RRangeHigh ^ LRangeHigh;
1773 APInt RangeDiff = LRangeLow.
sgt(RRangeLow) ? LRangeLow - RRangeLow
1774 : RRangeLow - LRangeLow;
1776 if (LowRangeDiff.
isPowerOf2() && LowRangeDiff == HighRangeDiff &&
1780 Value *NewAnd = Builder->CreateAnd(LAddOpnd, MaskCst);
1781 Value *NewAdd = Builder->CreateAdd(NewAnd, MaxAddCst);
1782 return (Builder->CreateICmp(LHS->
getPredicate(), NewAdd, LHSCst));
1811 Value *
A =
nullptr, *B =
nullptr;
1829 return Builder->CreateICmp(
1835 if (
Value *V = simplifyRangeCheck(LHS, RHS,
true))
1839 if (
Value *V = simplifyRangeCheck(RHS, LHS,
true))
1843 if (!LHSCst || !RHSCst)
return nullptr;
1845 if (LHSCst == RHSCst && LHSCC == RHSCC) {
1848 Value *NewOr = Builder->CreateOr(Val, Val2);
1849 return Builder->CreateICmp(LHSCC, NewOr, LHSCst);
1859 return Builder->CreateICmpULE(Val, LHSCst);
1864 if (Val != Val2)
return nullptr;
1882 ShouldSwap = LHSCst->
getValue().
sgt(RHSCst->getValue());
1884 ShouldSwap = LHSCst->
getValue().
ugt(RHSCst->getValue());
1898 assert(LHSCst != RHSCst &&
"Compares not folded above?");
1913 Value *NegCst = Builder->getInt(~Xor);
1919 if (LHSCst ==
SubOne(RHSCst)) {
1922 Value *Add = Builder->CreateAdd(Val, AddCST, Val->
getName()+
".off");
1924 return Builder->CreateICmpULT(Add, AddCST);
1947 return Builder->getTrue();
1957 if (RHSCst->isMaxValue(
false))
1959 return InsertRangeTest(Val, LHSCst,
AddOne(RHSCst),
false,
false);
1977 if (RHSCst->isMaxValue(
true))
1979 return InsertRangeTest(Val, LHSCst,
AddOne(RHSCst),
true,
false);
1999 return Builder->getTrue();
2014 return Builder->getTrue();
2034 if (LHSC->getValueAPF().isNaN() || RHSC->getValueAPF().isNaN())
2035 return Builder->getTrue();
2044 if (isa<ConstantAggregateZero>(LHS->
getOperand(1)) &&
2045 isa<ConstantAggregateZero>(RHS->
getOperand(1)))
2055 if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) {
2060 if (Op0LHS == Op1LHS && Op0RHS == Op1RHS) {
2072 unsigned Op0Pred =
getFCmpCode(Op0CC, Op0Ordered);
2073 unsigned Op1Pred =
getFCmpCode(Op1CC, Op1Ordered);
2074 if (Op0Ordered == Op1Ordered) {
2077 return getFCmpValue(Op0Ordered, Op0Pred|Op1Pred, Op0LHS, Op0RHS, Builder);
2095 if (!CI1)
return nullptr;
2097 Value *V1 =
nullptr;
2104 if (V1 == A || V1 == B) {
2105 Value *NewOp = Builder->CreateAnd((V1 == A) ? B : A, CI1);
2106 return BinaryOperator::CreateOr(NewOp, V1);
2127 Value *V1 =
nullptr;
2136 if (V1 == A || V1 == B) {
2137 Value *NewOp = Builder->CreateAnd(V1 == A ? B : A, CI1);
2138 return BinaryOperator::CreateXor(NewOp, V1);
2145 bool Changed = SimplifyAssociativeOrCommutative(I);
2148 if (
Value *V = SimplifyVectorOp(I))
2149 return ReplaceInstUsesWith(I, V);
2152 return ReplaceInstUsesWith(I, V);
2155 if (
Value *V = SimplifyUsingDistributiveLaws(I))
2156 return ReplaceInstUsesWith(I, V);
2160 if (SimplifyDemandedInstructionBits(I))
2163 if (
Value *V = SimplifyBSwap(I))
2164 return ReplaceInstUsesWith(I, V);
2166 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
2171 (RHS->getValue() & C1->
getValue()) != 0 &&
2173 Value *Or = Builder->CreateOr(X, RHS);
2175 return BinaryOperator::CreateAnd(Or,
2176 Builder->getInt(RHS->getValue() | C1->
getValue()));
2182 Value *Or = Builder->CreateOr(X, RHS);
2184 return BinaryOperator::CreateXor(Or,
2185 Builder->getInt(C1->
getValue() & ~RHS->getValue()));
2193 if (isa<PHINode>(Op0))
2198 Value *
A =
nullptr, *B =
nullptr;
2215 Value *NOr = Builder->CreateOr(A, Op1);
2217 return BinaryOperator::CreateXor(NOr, C1);
2221 if (Op1->hasOneUse() &&
2224 Value *NOr = Builder->CreateOr(A, Op0);
2226 return BinaryOperator::CreateXor(NOr, C1);
2232 return BinaryOperator::CreateOr(A, B);
2237 return BinaryOperator::CreateOr(Builder->CreateNot(A), B);
2242 return BinaryOperator::CreateXor(A, B);
2247 return BinaryOperator::CreateXor(A, B);
2250 Value *C =
nullptr, *D =
nullptr;
2253 Value *V1 =
nullptr, *
V2 =
nullptr;
2257 if ((C1->
getValue() & C2->getValue()) == 0) {
2265 return BinaryOperator::CreateAnd(A,
2266 Builder->getInt(C1->
getValue()|C2->getValue()));
2273 return BinaryOperator::CreateAnd(B,
2274 Builder->getInt(C1->
getValue()|C2->getValue()));
2282 (C4->getValue() & ~C2->getValue()) == 0) {
2284 return BinaryOperator::CreateAnd(
V2,
2285 Builder->getInt(C1->
getValue()|C2->getValue()));
2307 return BinaryOperator::CreateXor(A, D);
2311 return BinaryOperator::CreateXor(C, D);
2315 return BinaryOperator::CreateXor(A, B);
2319 return BinaryOperator::CreateXor(C, B);
2325 if (Ret)
return Ret;
2331 if (Ret)
return Ret;
2337 if (Ret)
return Ret;
2343 if (Ret)
return Ret;
2350 if (Op1->hasOneUse() || cast<BinaryOperator>(Op1)->hasOneUse())
2351 return BinaryOperator::CreateOr(Op0, C);
2356 if (Op0->
hasOneUse() || cast<BinaryOperator>(Op0)->hasOneUse())
2357 return BinaryOperator::CreateOr(Op1, C);
2361 return BinaryOperator::CreateOr(Op1, Builder->CreateAnd(A, C));
2366 if (Op0->
hasOneUse() && Op1->hasOneUse()) {
2367 Value *And = Builder->CreateAnd(Op0NotVal, Op1NotVal,
2373 bool SwappedForXor =
false;
2376 SwappedForXor =
true;
2383 if (Op0 == A || Op0 == B)
2384 return BinaryOperator::CreateOr(A, B);
2388 return BinaryOperator::CreateOr(A, B);
2391 Value *
Not = Builder->CreateNot(B, B->getName()+
".not");
2392 return BinaryOperator::CreateOr(Not, Op0);
2396 return BinaryOperator::CreateOr(Not, Op0);
2404 if ((Op0 == B->getOperand(0) || Op0 == B->getOperand(1)) &&
2407 Value *NotOp = Op0 == B->getOperand(0) ? B->getOperand(1) :
2410 return BinaryOperator::CreateOr(Not, Op0);
2416 return BinaryOperator::CreateXor(Builder->CreateNot(A), B);
2421 return BinaryOperator::CreateXor(Builder->CreateNot(A), B);
2430 if (
Value *Res = FoldOrOfICmps(LHS, RHS, &I))
2431 return ReplaceInstUsesWith(I, Res);
2437 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
2438 if (
Value *Res = FoldOrOfICmps(LHS, Cmp, &I))
2439 return ReplaceInstUsesWith(I, Builder->CreateOr(Res, Y));
2440 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
2441 if (
Value *Res = FoldOrOfICmps(LHS, Cmp, &I))
2442 return ReplaceInstUsesWith(I, Builder->CreateOr(Res, X));
2445 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
2446 if (
Value *Res = FoldOrOfICmps(Cmp, RHS, &I))
2447 return ReplaceInstUsesWith(I, Builder->CreateOr(Res, Y));
2448 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
2449 if (
Value *Res = FoldOrOfICmps(Cmp, RHS, &I))
2450 return ReplaceInstUsesWith(I, Builder->CreateOr(Res, X));
2457 if (
Value *Res = FoldOrOfFCmps(LHS, RHS))
2458 return ReplaceInstUsesWith(I, Res);
2461 if (
CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
2464 Type *SrcTy = Op0C->getOperand(0)->getType();
2469 if ((!isa<ICmpInst>(Op0COp) || !isa<ICmpInst>(Op1COp)) &&
2472 ShouldOptimizeCast(Op0C->getOpcode(), Op0COp, I.
getType()) &&
2474 Value *NewOp = Builder->CreateOr(Op0COp, Op1COp, I.
getName());
2480 if (
ICmpInst *RHS = dyn_cast<ICmpInst>(Op1COp))
2481 if (
ICmpInst *LHS = dyn_cast<ICmpInst>(Op0COp))
2482 if (
Value *Res = FoldOrOfICmps(LHS, RHS, &I))
2487 if (
FCmpInst *RHS = dyn_cast<FCmpInst>(Op1COp))
2488 if (
FCmpInst *LHS = dyn_cast<FCmpInst>(Op0COp))
2489 if (
Value *Res = FoldOrOfFCmps(LHS, RHS))
2507 if (Op0->
hasOneUse() && !isa<ConstantInt>(Op1) &&
2509 Value *Inner = Builder->CreateOr(A, Op1);
2511 return BinaryOperator::CreateOr(Inner, C1);
2518 Value *X =
nullptr, *
Y =
nullptr;
2519 if (Op0->
hasOneUse() && Op1->hasOneUse() &&
2522 Value *orTrue = Builder->CreateOr(A, C);
2523 Value *orFalse = Builder->CreateOr(B, D);
2528 return Changed ? &I :
nullptr;
2532 bool Changed = SimplifyAssociativeOrCommutative(I);
2535 if (
Value *V = SimplifyVectorOp(I))
2536 return ReplaceInstUsesWith(I, V);
2539 return ReplaceInstUsesWith(I, V);
2542 if (
Value *V = SimplifyUsingDistributiveLaws(I))
2543 return ReplaceInstUsesWith(I, V);
2547 if (SimplifyDemandedInstructionBits(I))
2550 if (
Value *V = SimplifyBSwap(I))
2551 return ReplaceInstUsesWith(I, V);
2561 Op0I->swapOperands();
2564 Builder->CreateNot(Op0I->getOperand(1),
2565 Op0I->getOperand(1)->getName()+
".not");
2567 return BinaryOperator::CreateOr(Op0NotVal, NotY);
2568 return BinaryOperator::CreateAnd(Op0NotVal, NotY);
2574 Op0I->getOperand(0)->hasOneUse()) &&
2576 Op0I->getOperand(1)->hasOneUse())) {
2578 Builder->CreateNot(Op0I->getOperand(0),
"notlhs");
2580 Builder->CreateNot(Op0I->getOperand(1),
"notrhs");
2582 return BinaryOperator::CreateOr(NotX, NotY);
2583 return BinaryOperator::CreateAnd(NotX, NotY);
2586 }
else if (Op0I->getOpcode() == Instruction::AShr) {
2589 return BinaryOperator::CreateAShr(Op0NotVal, Op0I->getOperand(1));
2594 if (
Constant *RHS = dyn_cast<Constant>(Op1)) {
2595 if (RHS->isAllOnesValue() && Op0->
hasOneUse())
2597 if (
CmpInst *CI = dyn_cast<CmpInst>(Op0))
2599 CI->getInversePredicate(),
2603 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
2605 if (
CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
2606 if (
CmpInst *CI = dyn_cast<CmpInst>(Op0C->getOperand(0))) {
2607 if (CI->
hasOneUse() && Op0C->hasOneUse()) {
2609 if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
2611 Op0C->getDestTy()))) {
2612 CI->setPredicate(CI->getInversePredicate());
2621 if (Op0I->getOpcode() == Instruction::Sub && RHS->isAllOnesValue())
2622 if (
Constant *Op0I0C = dyn_cast<Constant>(Op0I->getOperand(0))) {
2629 if (
ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) {
2630 if (Op0I->getOpcode() == Instruction::Add) {
2632 if (RHS->isAllOnesValue()) {
2634 return BinaryOperator::CreateSub(
2638 }
else if (RHS->getValue().isSignBit()) {
2640 Constant *C = Builder->getInt(RHS->getValue() + Op0CI->getValue());
2659 }
else if (Op0I->getOpcode() == Instruction::LShr) {
2664 if (Op0I->hasOneUse() &&
2671 FoldConst ^= C3->getValue();
2675 cast<Instruction>(Opnd0)->setDebugLoc(I.
getDebugLoc());
2678 return BinaryOperator::CreateXor(Opnd0, FoldVal);
2688 if (isa<PHINode>(Op0))
2701 }
else if (B == Op0) {
2726 return BinaryOperator::CreateAnd(A, Builder->CreateNot(Op1));
2732 !isa<ConstantInt>(Op1)) {
2733 return BinaryOperator::CreateAnd(Builder->CreateNot(A), Op1);
2743 if ((A == C && B == D) || (A == D && B == C))
2744 return BinaryOperator::CreateXor(A, B);
2749 if ((A == C && B == D) || (A == D && B == C))
2750 return BinaryOperator::CreateXor(A, B);
2755 return BinaryOperator::CreateXor(A, B);
2760 return BinaryOperator::CreateXor(A, B);
2765 return BinaryOperator::CreateXor(A, B);
2770 return BinaryOperator::CreateXor(A, B);
2776 return BinaryOperator::CreateXor(
2777 Builder->CreateAnd(Builder->CreateNot(A), B), C);
2779 return BinaryOperator::CreateXor(
2780 Builder->CreateAnd(Builder->CreateNot(B),
A), C);
2786 return BinaryOperator::CreateXor(
2787 Builder->CreateAnd(Builder->CreateNot(A), B), C);
2789 return BinaryOperator::CreateXor(
2790 Builder->CreateAnd(Builder->CreateNot(B),
A), C);
2795 return BinaryOperator::CreateOr(A, B);
2799 return BinaryOperator::CreateOr(A, B);
2802 Value *
A =
nullptr, *B =
nullptr;
2812 if (LHS->getOperand(0) == RHS->getOperand(1) &&
2813 LHS->getOperand(1) == RHS->getOperand(0))
2814 LHS->swapOperands();
2815 if (LHS->getOperand(0) == RHS->getOperand(0) &&
2816 LHS->getOperand(1) == RHS->getOperand(1)) {
2817 Value *Op0 = LHS->getOperand(0), *Op1 = LHS->getOperand(1);
2819 bool isSigned = LHS->isSigned() || RHS->isSigned();
2820 return ReplaceInstUsesWith(I,
2827 if (
CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
2828 if (
CastInst *Op1C = dyn_cast<CastInst>(Op1))
2829 if (Op0C->getOpcode() == Op1C->getOpcode()) {
2830 Type *SrcTy = Op0C->getOperand(0)->getType();
2831 if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->
isIntegerTy() &&
2833 ShouldOptimizeCast(Op0C->getOpcode(), Op0C->getOperand(0),
2835 ShouldOptimizeCast(Op1C->getOpcode(), Op1C->getOperand(0),
2837 Value *NewOp = Builder->CreateXor(Op0C->getOperand(0),
2838 Op1C->getOperand(0), I.
getName());
2844 return Changed ? &I :
nullptr;
Value * FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction *CxtI)
FoldOrOfICmps - Fold (icmp)|(icmp) if possible.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
Value * FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS)
FoldAndOfICmps - Fold (icmp)&(icmp) if possible.
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class is the base class for the comparison instructions.
static APInt getSignBit(unsigned BitWidth)
Get the SignBit for a specific bit width.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT byteSwap() const
static bool IsFreeToInvert(Value *V, bool WillInvertAllUses)
Return true if the specified value is free to invert (apply ~ to).
Instruction * visitXor(BinaryOperator &I)
Instruction * visitOr(BinaryOperator &I)
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
A Module instance is used to store all the information related to an LLVM module. ...
match_zero m_Zero()
Match an arbitrary zero/null constant.
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
This class represents zero extension of integer types.
unsigned getNumOperands() const
static Value * foldLogOpOfMaskedICmps(ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, llvm::InstCombiner::BuilderTy *Builder)
foldLogOpOfMaskedICmps: try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single (ic...
unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred=false)
getICmpCode - Encode a icmp predicate into a three bit mask.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
bool isSigned() const
Determine if this instruction is using a signed comparison.
0 1 0 0 True if ordered and less than
1 1 1 0 True if unordered or not equal
MaskedICmpType
enum for classifying (icmp eq (A & B), C) and (icmp ne (A & B), C) One of A and B is considered the m...
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the smallest range such that all values that may satisfy the given predicate with any value c...
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
static Constant * getNullValue(Type *Ty)
StringRef getName() const
Return a constant reference to the value's name.
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool swapOperands()
Exchange the two operands to this instruction.
APInt Not(const APInt &APIVal)
Bitwise complement function.
1 0 0 1 True if unordered or equal
bool match(Val *V, const Pattern &P)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
SelectInst - This class represents the LLVM 'select' instruction.
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is the base class for all instructions that perform data casts.
const APInt & getValue() const
Return the constant as an APInt value reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static Constant * AddOne(Constant *C)
Add one to a Constant.
0 1 0 1 True if ordered and less than or equal
bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
MaskedValueIsZero - Return true if 'V & Mask' is known to be zero.
bool isShiftedMask(unsigned numBits, const APInt &APIVal)
Return true if the argument APInt value contains a sequence of ones with the remainder zero...
Instruction * FoldOrWithConstants(BinaryOperator &I, Value *Op, Value *A, Value *B, Value *C)
FoldOrWithConstants - This helper function folds:
static Instruction * MatchSelectFromAndOr(Value *A, Value *B, Value *C, Value *D)
MatchSelectFromAndOr - We have an expression of the form (A&C)|(B&D).
not_match< LHS > m_Not(const LHS &L)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
static unsigned foldLogOpOfMaskedICmpsHelper(Value *&A, Value *&B, Value *&C, Value *&D, Value *&E, ICmpInst *LHS, ICmpInst *RHS, ICmpInst::Predicate &LHSCC, ICmpInst::Predicate &RHSCC)
foldLogOpOfMaskedICmpsHelper: handle (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) return the set o...
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
bool isKnownToBeAPowerOfTwo(Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
isKnownToBeAPowerOfTwo - Return true if the given value is known to have exactly one bit set when def...
This instruction compares its operands according to the predicate given to the constructor.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
bool sgt(const APInt &RHS) const
Signed greather than comparison.
bool isLogicalShift() const
isLogicalShift - Return true if this is a logical shift left or a logical shift right.
unsigned getActiveBits() const
Compute the number of active bits in the value.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
void takeName(Value *V)
Transfer the name from V to this value.
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
static const Value * getNotArgument(const Value *BinOp)
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static bool CollectBSwapParts(Value *V, int OverallLeftShift, uint32_t ByteMask, SmallVectorImpl< Value * > &ByteValues)
CollectBSwapParts - Analyze the specified subexpression and see if it is capable of providing pieces ...
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
Value * SimplifyOrInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyOrInst - Given operands for an Or, see if we can fold the result.
static Value * getFCmpValue(bool isordered, unsigned code, Value *LHS, Value *RHS, InstCombiner::BuilderTy *Builder)
getFCmpValue - This is the complement of getFCmpCode, which turns an opcode and two operands into eit...
OneUse_match< T > m_OneUse(const T &SubPattern)
bool isIntOrIntVectorTy() const
isIntOrIntVectorTy - Return true if this is an integer type or a vector of integer types...
static CmpInst * Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
The instances of the Type class are immutable: once they are created, they are never changed...
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
bool isEquality() const
isEquality - Return true if this predicate is either EQ or NE.
This is an important base class in LLVM.
Value * FoldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS)
FoldAndOfFCmps - Optimize (fcmp)&(fcmp).
static Constant * getAnd(Constant *C1, Constant *C2)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
ConstantFP - Floating Point Values [float, double].
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static unsigned getFCmpCode(FCmpInst::Predicate CC, bool &isOrdered)
getFCmpCode - Similar to getICmpCode but for FCmpInst.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
static bool isNot(const Value *V)
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
Class to represent integer types.
unsigned countPopulation() const
Count the number of bits set.
static unsigned conjugateICmpMask(unsigned Mask)
Convert an analysis of a masked ICmp into its equivalent if all boolean operations had the opposite s...
Predicate getPredicate() const
Return the predicate for this instruction.
static Constant * getNot(Constant *C)
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeSignBit - Determine whether the sign bit is known to be zero or one.
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
1 1 1 1 Always true (always folded)
bool isEmptySet() const
Return true if this set contains no members.
void swapOperands()
Exchange the two operands to this instruction in such a way that it does not modify the semantics of ...
LLVMContext & getContext() const
All values hold a context through their type.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
1 1 0 1 True if unordered, less than, or equal
Instruction * visitAnd(BinaryOperator &I)
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
0 0 1 0 True if ordered and greater than
BinaryOps getOpcode() const
This is the shared class of boolean and integer constants.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
1 1 0 0 True if unordered or less than
Type * getType() const
All values are typed, get the type of this value.
BinOp2_match< LHS, RHS, Instruction::LShr, Instruction::Shl > m_LogicalShift(const LHS &L, const RHS &R)
Matches LShr or Shl.
This class represents a range of values.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
bool PredicatesFoldable(CmpInst::Predicate p1, CmpInst::Predicate p2)
PredicatesFoldable - Return true if both predicates match sign or if at least one of them is an equal...
static bool decomposeBitTestICmp(const ICmpInst *I, ICmpInst::Predicate &Pred, Value *&X, Value *&Y, Value *&Z)
decomposeBitTestICmp - Decompose an icmp into the form ((X & Y) pred Z) if possible.
void setOperand(unsigned i, Value *Val)
bool isAllOnesValue() const
isAllOnesValue - Return true if this is the value that would be returned by getAllOnesValue.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class for arbitrary precision integers.
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
bool isAllOnesValue() const
Determine if all bits are set.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Value * SimplifyAndInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyAndInst - Given operands for an And, see if we can fold the result.
Value * getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, CmpInst::Predicate &NewICmpPred)
getICmpValue - This is the complement of getICmpCode, which turns an opcode and two operands into eit...
unsigned greater or equal
static Value * dyn_castNotVal(Value *V)
static Constant * getOr(Constant *C1, Constant *C2)
bool hasOneUse() const
Return true if there is exactly one user of this value.
0 1 1 0 True if ordered and operands are unequal
1 0 1 0 True if unordered or greater than
OtherOps getOpcode() const
Get the opcode casted to the right type.
Value * SimplifyXorInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyXorInst - Given operands for a Xor, see if we can fold the result.
static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME)
Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
0 0 0 1 True if ordered and equal
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
This file provides internal interfaces used to implement the InstCombine.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static Value * getNewICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, InstCombiner::BuilderTy *Builder)
getNewICmpValue - This is the complement of getICmpCode, which turns an opcode and two operands into ...
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
C - The default llvm calling convention, compatible with C.
bool isPowerOf2_32(uint32_t Value)
isPowerOf2_32 - This function returns true if the argument is a power of two > 0. ...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
Value * simplifyRangeCheck(ICmpInst *Cmp0, ICmpInst *Cmp1, bool Inverted)
Try to fold a signed range checked with lower bound 0 to an unsigned icmp.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
0 0 1 1 True if ordered and greater than or equal
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
Instruction * FoldXorWithConstants(BinaryOperator &I, Value *Op, Value *A, Value *B, Value *C)
This helper function folds:
const BasicBlock * getParent() const
static Constant * SubOne(Constant *C)
Subtract one from a Constant.
static unsigned getTypeOfMaskedICmp(Value *A, Value *B, Value *C, ICmpInst::Predicate SCC)
return the set of pattern classes (from MaskedICmpType) that (icmp SCC (A & B), C) satisfies ...
0 0 0 0 Always false (always folded)
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
static Constant * getXor(Constant *C1, Constant *C2)
Value * FoldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS)
FoldOrOfFCmps - Optimize (fcmp)|(fcmp).