21 using namespace PatternMatch;
43 assert(!insaneIntVal(C) &&
"Insane coefficient");
56 void operator=(
const FAddendCoef &
A);
58 void operator-=(
const FAddendCoef &
A);
59 void operator*=(
const FAddendCoef &S);
61 bool isOne()
const {
return isInt() &&
IntVal == 1; }
62 bool isTwo()
const {
return isInt() &&
IntVal == 2; }
63 bool isMinusOne()
const {
return isInt() &&
IntVal == -1; }
64 bool isMinusTwo()
const {
return isInt() &&
IntVal == -2; }
67 bool insaneIntVal(
int V) {
return V > 4 || V < -4; }
69 {
return reinterpret_cast<APFloat*
>(&FpValBuf.buffer[0]); }
70 const APFloat *getFpValPtr(
void)
const
71 {
return reinterpret_cast<const APFloat*
>(&FpValBuf.buffer[0]); }
73 const APFloat &getFpVal(
void)
const {
74 assert(IsFp && BufHasFpVal &&
"Incorret state");
75 return *getFpValPtr();
79 assert(IsFp && BufHasFpVal &&
"Incorret state");
80 return *getFpValPtr();
83 bool isInt()
const {
return !IsFp; }
115 FAddend() { Val = 0; }
117 Value *getSymVal (
void)
const {
return Val; }
118 const FAddendCoef &getCoef(
void)
const {
return Coeff; }
120 bool isConstant()
const {
return Val == 0; }
121 bool isZero()
const {
return Coeff.isZero(); }
123 void set(
short Coefficient,
Value *V) { Coeff.set(Coefficient), Val = V; }
125 { Coeff.set(Coefficient); Val = V; }
127 { Coeff.set(Coefficient->
getValueAPF()); Val = V; }
129 void negate() { Coeff.negate(); }
133 static unsigned drillValueDownOneStep(
Value* V, FAddend &A0, FAddend &A1);
137 unsigned drillAddendDownOneStep(FAddend &Addend0, FAddend &Addend1)
const;
140 assert((Val == T.Val) &&
"Symbolic-values disagree");
145 void Scale(
const FAddendCoef& ScaleAmt) { Coeff *= ScaleAmt; }
163 Value *simplifyFAdd(AddendVect& V,
unsigned InstrQuota);
168 Value *createAddendVal(
const FAddend &
A,
bool& NeedNeg);
171 unsigned calcInstrNumber(
const AddendVect& Vect);
177 Value *createNaryFAdd(
const AddendVect& Opnds,
unsigned InstrQuota);
186 unsigned CreateInstrNum;
187 void initCreateInstNum() { CreateInstrNum = 0; }
188 void incCreateInstNum() { CreateInstrNum++; }
190 void initCreateInstNum() {}
191 void incCreateInstNum() {}
202 FAddendCoef::~FAddendCoef() {
204 getFpValPtr()->~APFloat();
207 void FAddendCoef::set(
const APFloat& C) {
217 IsFp = BufHasFpVal =
true;
220 void FAddendCoef::convertToFpType(
const fltSemantics &Sem) {
231 IsFp = BufHasFpVal =
true;
244 void FAddendCoef::operator=(
const FAddendCoef &That) {
248 set(That.getFpVal());
253 if (
isInt() == That.isInt()) {
257 getFpVal().add(That.getFpVal(), RndMode);
264 getFpVal().add(T, RndMode);
272 void FAddendCoef::operator-=(
const FAddendCoef &That) {
274 if (
isInt() == That.isInt()) {
278 getFpVal().subtract(That.getFpVal(), RndMode);
283 const APFloat &T = That.getFpVal();
285 getFpVal().subtract(T, RndMode);
293 void FAddendCoef::operator*=(
const FAddendCoef &That) {
297 if (That.isMinusOne()) {
302 if (
isInt() && That.isInt()) {
303 int Res =
IntVal * (int)That.IntVal;
304 assert(!insaneIntVal(Res) &&
"Insane int value");
310 isInt() ? That.getFpVal().getSemantics() : getFpVal().getSemantics();
313 convertToFpType(Semantic);
317 F0.
multiply(createAPFloatFromInt(Semantic, That.IntVal),
325 void FAddendCoef::negate() {
329 getFpVal().changeSign();
332 Value *FAddendCoef::getValue(
Type *Ty)
const {
335 ConstantFP::get(Ty->getContext(), getFpVal());
349 unsigned FAddend::drillValueDownOneStep
350 (
Value *Val, FAddend &Addend0, FAddend &Addend1) {
352 if (Val == 0 || !(I = dyn_cast<Instruction>(Val)))
357 if (Opcode == Instruction::FAdd || Opcode == Instruction::FSub) {
361 if ((C0 = dyn_cast<ConstantFP>(Opnd0)) && C0->
isZero())
364 if ((C1 = dyn_cast<ConstantFP>(Opnd1)) && C1->
isZero())
369 Addend0.set(1, Opnd0);
375 FAddend &Addend = Opnd0 ? Addend1 : Addend0;
377 Addend.set(1, Opnd1);
380 if (Opcode == Instruction::FSub)
385 return Opnd0 && Opnd1 ? 2 : 1;
392 if (I->
getOpcode() == Instruction::FMul) {
395 if (
ConstantFP *C = dyn_cast<ConstantFP>(V0)) {
400 if (
ConstantFP *C = dyn_cast<ConstantFP>(V1)) {
413 unsigned FAddend::drillAddendDownOneStep
414 (FAddend &Addend0, FAddend &Addend1)
const {
418 unsigned BreakNum = FAddend::drillValueDownOneStep(Val, Addend0, Addend1);
419 if (!BreakNum || Coeff.isOne())
422 Addend0.Scale(Coeff);
425 Addend1.Scale(Coeff);
439 assert((I->
getOpcode() == Instruction::FAdd ||
440 I->
getOpcode() == Instruction::FSub) &&
"Expect add/sub");
445 if (!I0 || !I1 || I0->
getOpcode() != I1->getOpcode())
449 if (I0->
getOpcode() == Instruction::FMul)
451 else if (I0->
getOpcode() != Instruction::FDiv)
456 Value *Opnd1_0 = I1->getOperand(0);
457 Value *Opnd1_1 = I1->getOperand(1);
465 Value *AddSub0 = 0, *AddSub1 = 0;
468 if (Opnd0_0 == Opnd1_0 || Opnd0_0 == Opnd1_1)
470 else if (Opnd0_1 == Opnd1_0 || Opnd0_1 == Opnd1_1)
474 AddSub0 = (Factor == Opnd0_0) ? Opnd0_1 : Opnd0_0;
475 AddSub1 = (Factor == Opnd1_0) ? Opnd1_1 : Opnd1_0;
477 }
else if (Opnd0_1 == Opnd1_1) {
488 createFAdd(AddSub0, AddSub1) :
489 createFSub(AddSub0, AddSub1);
490 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(NewAddSub)) {
491 const APFloat &
F = CFP->getValueAPF();
497 return createFMul(Factor, NewAddSub);
499 return createFDiv(NewAddSub, Factor);
509 assert((I->
getOpcode() == Instruction::FAdd ||
510 I->
getOpcode() == Instruction::FSub) &&
"Expect add/sub");
515 FAddend Opnd0, Opnd1, Opnd0_0, Opnd0_1, Opnd1_0, Opnd1_1;
517 unsigned OpndNum = FAddend::drillValueDownOneStep(I, Opnd0, Opnd1);
520 unsigned Opnd0_ExpNum = 0;
521 unsigned Opnd1_ExpNum = 0;
523 if (!Opnd0.isConstant())
524 Opnd0_ExpNum = Opnd0.drillAddendDownOneStep(Opnd0_0, Opnd0_1);
527 if (OpndNum == 2 && !Opnd1.isConstant())
528 Opnd1_ExpNum = Opnd1.drillAddendDownOneStep(Opnd1_0, Opnd1_1);
531 if (Opnd0_ExpNum && Opnd1_ExpNum) {
533 AllOpnds.push_back(&Opnd0_0);
534 AllOpnds.push_back(&Opnd1_0);
535 if (Opnd0_ExpNum == 2)
536 AllOpnds.push_back(&Opnd0_1);
537 if (Opnd1_ExpNum == 2)
538 AllOpnds.push_back(&Opnd1_1);
541 unsigned InstQuota = 0;
545 InstQuota = ((!isa<Constant>(V0) && V0->
hasOneUse()) &&
546 (!isa<Constant>(V1) && V1->
hasOneUse())) ? 2 : 1;
548 if (
Value *R = simplifyFAdd(AllOpnds, InstQuota))
557 const FAddendCoef &CE = Opnd0.getCoef();
558 return CE.isOne() ? Opnd0.getSymVal() : 0;
564 AllOpnds.push_back(&Opnd0);
565 AllOpnds.push_back(&Opnd1_0);
566 if (Opnd1_ExpNum == 2)
567 AllOpnds.push_back(&Opnd1_1);
569 if (
Value *R = simplifyFAdd(AllOpnds, 1))
576 AllOpnds.push_back(&Opnd1);
577 AllOpnds.push_back(&Opnd0_0);
578 if (Opnd0_ExpNum == 2)
579 AllOpnds.push_back(&Opnd0_1);
581 if (
Value *R = simplifyFAdd(AllOpnds, 1))
586 return performFactorization(I);
589 Value *FAddCombine::simplifyFAdd(AddendVect& Addends,
unsigned InstrQuota) {
591 unsigned AddendNum = Addends.size();
592 assert(AddendNum <= 4 &&
"Too many addends");
595 unsigned NextTmpIdx = 0;
596 FAddend TmpResult[3];
604 const FAddend *ConstAdd = 0;
613 for (
unsigned SymIdx = 0; SymIdx < AddendNum; SymIdx++) {
615 const FAddend *ThisAddend = Addends[SymIdx];
621 Value *Val = ThisAddend->getSymVal();
622 unsigned StartIdx = SimpVect.size();
623 SimpVect.push_back(ThisAddend);
631 for (
unsigned SameSymIdx = SymIdx + 1;
632 SameSymIdx < AddendNum; SameSymIdx++) {
633 const FAddend *T = Addends[SameSymIdx];
634 if (T && T->getSymVal() == Val) {
637 Addends[SameSymIdx] = 0;
638 SimpVect.push_back(T);
643 if (StartIdx + 1 != SimpVect.size()) {
644 FAddend &R = TmpResult[NextTmpIdx ++];
645 R = *SimpVect[StartIdx];
646 for (
unsigned Idx = StartIdx + 1; Idx < SimpVect.size(); Idx++)
650 SimpVect.resize(StartIdx);
653 SimpVect.push_back(&R);
664 "out-of-bound access");
667 SimpVect.push_back(ConstAdd);
670 if (!SimpVect.empty())
671 Result = createNaryFAdd(SimpVect, InstrQuota);
680 Value *FAddCombine::createNaryFAdd
681 (
const AddendVect &Opnds,
unsigned InstrQuota) {
682 assert(!Opnds.empty() &&
"Expect at least one addend");
686 unsigned InstrNeeded = calcInstrNumber(Opnds);
687 if (InstrNeeded > InstrQuota)
701 bool LastValNeedNeg =
false;
704 for (AddendVect::const_iterator I = Opnds.begin(), E = Opnds.end();
707 Value *V = createAddendVal(**I, NeedNeg);
710 LastValNeedNeg = NeedNeg;
714 if (LastValNeedNeg == NeedNeg) {
715 LastVal = createFAdd(LastVal, V);
720 LastVal = createFSub(V, LastVal);
722 LastVal = createFSub(LastVal, V);
724 LastValNeedNeg =
false;
727 if (LastValNeedNeg) {
728 LastVal = createFNeg(LastVal);
732 assert(CreateInstrNum == InstrNeeded &&
733 "Inconsistent in instruction numbers");
739 Value *FAddCombine::createFSub
741 Value *V = Builder->CreateFSub(Opnd0, Opnd1);
743 createInstPostProc(I);
749 return createFSub(Zero, V);
752 Value *FAddCombine::createFAdd
754 Value *V = Builder->CreateFAdd(Opnd0, Opnd1);
756 createInstPostProc(I);
761 Value *V = Builder->CreateFMul(Opnd0, Opnd1);
763 createInstPostProc(I);
768 Value *V = Builder->CreateFDiv(Opnd0, Opnd1);
770 createInstPostProc(I);
774 void FAddCombine::createInstPostProc(
Instruction *NewInstr) {
786 unsigned FAddCombine::calcInstrNumber(
const AddendVect &Opnds) {
787 unsigned OpndNum = Opnds.size();
788 unsigned InstrNeeded = OpndNum - 1;
791 unsigned NegOpndNum = 0;
794 for (AddendVect::const_iterator I = Opnds.begin(), E = Opnds.end();
796 const FAddend *Opnd = *
I;
797 if (Opnd->isConstant())
800 const FAddendCoef &CE = Opnd->getCoef();
801 if (CE.isMinusOne() || CE.isMinusTwo())
807 if (!CE.isMinusOne() && !CE.isOne())
810 if (NegOpndNum == OpndNum)
823 Value *FAddCombine::createAddendVal
824 (
const FAddend &Opnd,
bool &NeedNeg) {
825 const FAddendCoef &Coeff = Opnd.getCoef();
827 if (Opnd.isConstant()) {
829 return Coeff.getValue(Instr->getType());
832 Value *OpndVal = Opnd.getSymVal();
834 if (Coeff.isMinusOne() || Coeff.isOne()) {
835 NeedNeg = Coeff.isMinusOne();
839 if (Coeff.isTwo() || Coeff.isMinusTwo()) {
840 NeedNeg = Coeff.isMinusTwo();
841 return createFAdd(OpndVal, OpndVal);
845 return createFMul(OpndVal, Coeff.getValue(Instr->getType()));
869 if (I == 0)
return 0;
872 if ((CST = dyn_cast<ConstantInt>(I->
getOperand(1))))
875 if ((CST = dyn_cast<ConstantInt>(I->
getOperand(1)))) {
891 bool InstCombiner::WillNotOverflowSignedAdd(
Value *LHS,
Value *RHS) {
914 bool Changed = SimplifyAssociativeOrCommutative(I);
919 return ReplaceInstUsesWith(I, V);
922 if (
Value *V = SimplifyUsingDistributiveLaws(I))
923 return ReplaceInstUsesWith(I, V);
925 if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
927 const APInt &Val = CI->getValue();
929 return BinaryOperator::CreateXor(LHS, RHS);
933 if (SimplifyDemandedInstructionBits(I))
937 if (
ZExtInst *ZI = dyn_cast<ZExtInst>(LHS))
938 if (ZI->getSrcTy()->isIntegerTy(1))
944 const APInt &RHSVal = CI->getValue();
945 unsigned ExtendAmt = 0;
948 if (XorRHS->
getValue() == -RHSVal) {
950 ExtendAmt = TySizeBits - RHSVal.
logBase2() - 1;
963 Value *NewShl = Builder->CreateShl(XorLHS, ShAmt,
"sext");
964 return BinaryOperator::CreateAShr(NewShl, ShAmt);
974 if ((XorRHS->
getValue() | LHSKnownZero).isAllOnesValue())
981 return BinaryOperator::CreateAdd(XorLHS,
986 if (isa<Constant>(RHS) && isa<PHINode>(LHS))
991 return BinaryOperator::CreateXor(LHS, RHS);
1004 if (
Value *LHSV = dyn_castNegVal(LHS)) {
1005 if (!isa<Constant>(RHS))
1006 if (
Value *RHSV = dyn_castNegVal(RHS)) {
1007 Value *NewAdd = Builder->CreateAdd(LHSV, RHSV,
"sum");
1011 return BinaryOperator::CreateSub(RHS, LHSV);
1015 if (!isa<Constant>(RHS))
1016 if (
Value *V = dyn_castNegVal(RHS))
1017 return BinaryOperator::CreateSub(LHS, V);
1023 return BinaryOperator::CreateMul(RHS,
AddOne(C2));
1033 return BinaryOperator::CreateMul(LHS,
AddOne(C2));
1037 APInt LHSKnownOne(
IT->getBitWidth(), 0);
1038 APInt LHSKnownZero(
IT->getBitWidth(), 0);
1040 if (LHSKnownZero != 0) {
1041 APInt RHSKnownOne(
IT->getBitWidth(), 0);
1042 APInt RHSKnownZero(
IT->getBitWidth(), 0);
1046 if ((LHSKnownZero|RHSKnownZero).isAllOnesValue())
1047 return BinaryOperator::CreateOr(LHS, RHS);
1059 }
else if (Y == X) {
1061 }
else if (X == Z) {
1068 Value *NewAdd = Builder->CreateAdd(X, Z, LHS->
getName());
1069 return BinaryOperator::CreateMul(W, NewAdd);
1074 if (
ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
1077 return BinaryOperator::CreateSub(
SubOne(CRHS), X);
1082 CRHS->getValue() == (CRHS->getValue() & C2->
getValue())) {
1085 const APInt &AddRHSV = CRHS->getValue();
1088 APInt AddRHSHighBits(~((AddRHSV & -AddRHSV)-1));
1093 if (AddRHSHighBits == AddRHSHighBitsAnd) {
1095 Value *NewAdd = Builder->CreateAdd(X, CRHS, LHS->
getName());
1096 return BinaryOperator::CreateAnd(NewAdd, C2);
1101 if (
SelectInst *SI = dyn_cast<SelectInst>(LHS))
1133 if (
SExtInst *LHSConv = dyn_cast<SExtInst>(LHS)) {
1135 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
1138 if (LHSConv->hasOneUse() &&
1140 WillNotOverflowSignedAdd(LHSConv->getOperand(0), CI)) {
1142 Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
1149 if (
SExtInst *RHSConv = dyn_cast<SExtInst>(RHS)) {
1153 if (LHSConv->getOperand(0)->getType()==RHSConv->getOperand(0)->getType()&&
1154 (LHSConv->hasOneUse() || RHSConv->hasOneUse()) &&
1155 WillNotOverflowSignedAdd(LHSConv->getOperand(0),
1156 RHSConv->getOperand(0))) {
1158 Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
1159 RHSConv->getOperand(0),
"addconv");
1171 return BinaryOperator::CreateOr(A, B);
1176 return BinaryOperator::CreateOr(A, B);
1179 return Changed ? &I : 0;
1183 bool Changed = SimplifyAssociativeOrCommutative(I);
1187 return ReplaceInstUsesWith(I, V);
1189 if (isa<Constant>(RHS)) {
1190 if (isa<PHINode>(LHS))
1194 if (
SelectInst *SI = dyn_cast<SelectInst>(LHS))
1201 if (
Value *LHSV = dyn_castFNegVal(LHS))
1202 return BinaryOperator::CreateFSub(RHS, LHSV);
1205 if (!isa<Constant>(RHS))
1206 if (
Value *V = dyn_castFNegVal(RHS))
1207 return BinaryOperator::CreateFSub(LHS, V);
1211 if (
SIToFPInst *LHSConv = dyn_cast<SIToFPInst>(LHS)) {
1217 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(RHS)) {
1220 if (LHSConv->hasOneUse() &&
1222 WillNotOverflowSignedAdd(LHSConv->getOperand(0), CI)) {
1224 Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
1231 if (
SIToFPInst *RHSConv = dyn_cast<SIToFPInst>(RHS)) {
1235 if (LHSConv->getOperand(0)->getType()==RHSConv->getOperand(0)->getType()&&
1236 (LHSConv->hasOneUse() || RHSConv->hasOneUse()) &&
1237 WillNotOverflowSignedAdd(LHSConv->getOperand(0),
1238 RHSConv->getOperand(0))) {
1240 Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
1241 RHSConv->getOperand(0),
"addconv");
1249 Value *A1, *B1, *C1, *A2, *B2, *C2;
1273 if (
Value *V = FAddCombine(Builder).simplify(&I))
1274 return ReplaceInstUsesWith(I, V);
1277 return Changed ? &I : 0;
1287 assert(
TD &&
"Must have target data info for this");
1291 bool Swapped =
false;
1296 if (
GEPOperator *LHSGEP = dyn_cast<GEPOperator>(LHS)) {
1298 if (LHSGEP->getOperand(0) == RHS) {
1301 }
else if (
GEPOperator *RHSGEP = dyn_cast<GEPOperator>(RHS)) {
1303 if (LHSGEP->getOperand(0)->stripPointerCasts() ==
1304 RHSGEP->getOperand(0)->stripPointerCasts()) {
1312 if (
GEPOperator *RHSGEP = dyn_cast<GEPOperator>(RHS)) {
1314 if (RHSGEP->getOperand(0) == LHS) {
1317 }
else if (
GEPOperator *LHSGEP = dyn_cast<GEPOperator>(LHS)) {
1319 if (RHSGEP->getOperand(0)->stripPointerCasts() ==
1320 LHSGEP->getOperand(0)->stripPointerCasts()) {
1331 (GEP2 != 0 && !GEP2->hasAllConstantIndices() && !GEP2->hasOneUse()))
1341 Result = Builder->CreateSub(Result, Offset);
1346 Result = Builder->CreateNeg(Result,
"diff.neg");
1348 return Builder->CreateIntCast(Result, Ty,
true);
1357 return ReplaceInstUsesWith(I, V);
1360 if (
Value *V = SimplifyUsingDistributiveLaws(I))
1361 return ReplaceInstUsesWith(I, V);
1364 if (
Value *V = dyn_castNegVal(Op1)) {
1372 return BinaryOperator::CreateXor(Op0, Op1);
1378 if (
ConstantInt *C = dyn_cast<ConstantInt>(Op0)) {
1382 return BinaryOperator::CreateAdd(X,
AddOne(C));
1391 return BinaryOperator::CreateAShr(X, CI);
1396 return BinaryOperator::CreateLShr(X, CI);
1400 if (
SelectInst *SI = dyn_cast<SelectInst>(Op1))
1409 if (SimplifyDemandedInstructionBits(I))
1435 if (Op1->hasOneUse()) {
1442 return BinaryOperator::CreateAdd(Op0,
1443 Builder->CreateSub(Z,
Y, Op1->getName()));
1449 return BinaryOperator::CreateAnd(Op0,
1450 Builder->CreateNot(
Y,
Y->getName() +
".not"));
1459 if (
Value *XNeg = dyn_castNegVal(X))
1460 return BinaryOperator::CreateShl(XNeg,
Y);
1465 return BinaryOperator::CreateMul(Op0, CP1);
1472 return BinaryOperator::CreateMul(Op0, C);
1480 return BinaryOperator::CreateAdd(Op0, Builder->CreateMul(A, B));
1487 return BinaryOperator::CreateAdd(Op0, NewMul);
1494 return BinaryOperator::CreateMul(Op1,
SubOne(C1));
1504 Value *LHSOp, *RHSOp;
1507 if (
Value *Res = OptimizePointerDifference(LHSOp, RHSOp, I.
getType()))
1508 return ReplaceInstUsesWith(I, Res);
1513 if (
Value *Res = OptimizePointerDifference(LHSOp, RHSOp, I.
getType()))
1514 return ReplaceInstUsesWith(I, Res);
1524 return ReplaceInstUsesWith(I, V);
1526 if (isa<Constant>(Op0))
1527 if (
SelectInst *SI = dyn_cast<SelectInst>(Op1))
1533 if (
Value *V = dyn_castFNegVal(Op1)) {
1534 Instruction *NewI = BinaryOperator::CreateFAdd(Op0, V);
1538 if (
FPTruncInst *FPTI = dyn_cast<FPTruncInst>(Op1)) {
1539 if (
Value *V = dyn_castFNegVal(FPTI->getOperand(0))) {
1540 Value *NewTrunc = Builder->CreateFPTrunc(V, I.
getType());
1541 Instruction *NewI = BinaryOperator::CreateFAdd(Op0, NewTrunc);
1545 }
else if (
FPExtInst *FPEI = dyn_cast<FPExtInst>(Op1)) {
1546 if (
Value *V = dyn_castFNegVal(FPEI->getOperand(0))) {
1548 Instruction *NewI = BinaryOperator::CreateFAdd(Op0, NewExt);
1555 if (
Value *V = FAddCombine(Builder).simplify(&I))
1556 return ReplaceInstUsesWith(I, V);
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
std::string & operator+=(std::string &buffer, StringRef string)
class_match< Value > m_Value()
m_Value() - Match an arbitrary value and ignore it.
void setHasNoSignedWrap(bool b=true)
static Constant * getSIToFP(Constant *C, Type *Ty)
void setFastMathFlags(FastMathFlags FMF)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
unsigned getScalarSizeInBits()
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=0)
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.
Value * SimplifyFSubInst(Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout *TD=0, unsigned Depth=0)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
class_match< Constant > m_Constant()
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &TD, User *GEP, bool NoAssumptions=false)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
Value * SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
static Value * dyn_castFoldableMul(Value *V, ConstantInt *&CST)
Instruction * visitFSub(BinaryOperator &I)
FastMathFlags getFastMathFlags() const
This class represents a sign extension of integer types.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
StringRef getName() const
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool isNegativeZeroValue() const
bool match(Val *V, const Pattern &P)
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT,"arm-default-it","Generate IT block based on arch"), clEnumValN(RestrictedIT,"arm-restrict-it","Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT,"arm-no-restrict-it","Allow IT blocks based on ARMv7"), clEnumValEnd))
const APInt & getValue() const
Return the constant's value.
void setHasNoUnsignedWrap(bool b=true)
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
m_Trunc
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
not_match< LHS > m_Not(const LHS &L)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
size_t array_lengthof(T(&)[N])
Find the length of an array.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
m_ZExt
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
Get the constant's value with a saturation limit.
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
class_match< ConstantInt > m_ConstantInt()
m_ConstantInt() - Match an arbitrary ConstantInt and ignore it.
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
bool isZero() const
isZero - Return true if the value is positive or negative zero.
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.
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Value * OptimizePointerDifference(Value *LHS, Value *RHS, Type *Ty)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
LLVM Constant Representation.
const Value * getCondition() const
cst_pred_ty< is_all_ones > m_AllOnes()
m_AllOnes() - Match an integer or vector with all bits set to true.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
specificval_ty m_Specific(const Value *V)
m_Specific - Match if we have a specific specified value.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
NUW NUW NUW NUW Exact static Exact BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=0)
Value * getOperand(unsigned i) const
Integer representation type.
Instruction * visitFAdd(BinaryOperator &I)
match_combine_or< match_zero, match_neg_zero > m_AnyZero()
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Create a ZExt or BitCast cast instruction.
LLVMContext & getContext() const
All values hold a context through their type.
bool hasNoSignedWrap() const
hasNoSignedWrap - Determine whether the no signed wrap flag is set.
const Value * getTrueValue() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
neg_match< LHS > m_Neg(const LHS &L)
m_Neg - Match an integer negate.
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
m_SExt
static CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Create a SExt or BitCast cast instruction.
static bool isZero(Value *V, DataLayout *DL)
roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
Class for constant integers.
opStatus add(const APFloat &, roundingMode)
unsigned logBase2() const
opStatus multiply(const APFloat &, roundingMode)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
static Constant * getTrunc(Constant *C, Type *Ty)
void copyFastMathFlags(const Instruction *I)
Copy I's fast-math flags.
static Constant * get(Type *Ty, double V)
static Constant * getFPToSI(Constant *C, Type *Ty)
static Constant * SubOne(ConstantInt *C)
SubOne - Subtract one from a ConstantInt.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class for arbitrary precision integers.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
m_PtrToInt
This union template exposes a suitably aligned and sized character array member which can hold elemen...
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
static Constant * getSExt(Constant *C, Type *Ty)
Instruction * visitAdd(BinaryOperator &I)
static Constant * AddOne(Constant *C)
AddOne - Add one to a ConstantInt.
bool isSignBit() const
Check if the APInt's value is returned by getSignBit.
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
unsigned getPrimitiveSizeInBits() const
unsigned ComputeNumSignBits(Value *Op, const DataLayout *TD=0, unsigned Depth=0)
const APFloat & getValueAPF() const
This class represents a cast from signed integer to floating point.
This class represents a truncation of floating point types.
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.
bool isZero() const
Returns true if and only if the float is plus or minus zero.
bool isInt(int64_t x)
isInt - Checks if an integer fits into the given bit width.
const Value * getFalseValue() const
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
Value * SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=0)
This class represents an extension of floating point types.
const fltSemantics & getSemantics() const
opStatus subtract(const APFloat &, roundingMode)
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
Instruction * visitSub(BinaryOperator &I)
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
Value * SimplifyFAddInst(Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
static Constant * getXor(Constant *C1, Constant *C2)