56#define DEBUG_TYPE "constraint-elimination"
58STATISTIC(NumCondsRemoved,
"Number of instructions removed");
60 "Number of doesHold queries cut off by the nesting depth limit");
62 "Controls which conditions are eliminated");
70 UserI = Phi->getIncomingBlock(U)->getTerminator();
79 for (
Use &U :
I.uses()) {
100 Value *Op0 =
nullptr;
101 Value *Op1 =
nullptr;
143 FactOrCheck(EntryTy Ty,
DomTreeNode *DTN, Instruction *Inst,
144 Instruction *ContextInst =
nullptr)
145 : Inst(Inst), ContextInst(ContextInst ? ContextInst : Inst),
146 NumIn(DTN->getDFSNumIn()), NumOut(DTN->getDFSNumOut()), Ty(Ty) {}
149 :
U(
U), ContextInst(nullptr), NumIn(DTN->getDFSNumIn()),
150 NumOut(DTN->getDFSNumOut()), Ty(EntryTy::UseCheck) {}
154 :
Cond(
Pred, Op0, Op1), DoesHold(Precond), NumIn(DTN->getDFSNumIn()),
155 NumOut(DTN->getDFSNumOut()), Ty(EntryTy::ConditionFact) {}
157 static FactOrCheck getConditionFact(
DomTreeNode *DTN, CmpPredicate
Pred,
160 return FactOrCheck(DTN,
Pred, Op0, Op1, Precond);
163 static FactOrCheck getInstFact(
DomTreeNode *DTN, Instruction *Inst) {
164 return FactOrCheck(EntryTy::InstFact, DTN, Inst);
167 static FactOrCheck getCheck(
DomTreeNode *DTN, Use *U) {
168 return FactOrCheck(DTN, U);
171 static FactOrCheck getCheck(
DomTreeNode *DTN, Instruction *
I,
172 Instruction *ContextInst =
nullptr) {
174 "anchoring instruction must be in DTN's block");
175 return FactOrCheck(EntryTy::InstCheck, DTN,
I, ContextInst);
178 bool isCheck()
const {
179 return Ty == EntryTy::InstCheck || Ty == EntryTy::UseCheck;
183 assert(!isConditionFact());
184 if (Ty == EntryTy::UseCheck)
191 if (Ty == EntryTy::InstCheck)
197 bool isConditionFact()
const {
return Ty == EntryTy::ConditionFact; }
202struct MonotonicInfo {
204 bool Decreasing =
false;
206 bool Unsigned =
false;
217 TargetLibraryInfo &TLI;
220 State(DominatorTree &DT, LoopInfo &LI, ScalarEvolution *SE,
221 TargetLibraryInfo &TLI)
222 : DT(DT), LI(LI), SE(SE), TLI(TLI) {}
225 void addInfoFor(BasicBlock &BB);
229 void addBoundsForHeaderInductions(BasicBlock &BB);
233 void addInfoForInductions(BasicBlock &BB);
237 MonotonicInfo getMonotonicityInfo(PHINode &PN,
Value *Step);
241 bool canAddSuccessor(BasicBlock &BB, BasicBlock *Succ)
const {
242 return DT.dominates(BasicBlockEdge(&BB, Succ), Succ);
251 bool IsSigned =
false;
254 SmallVector<Value *, 2> ValuesToRelease;
256 StackEntry(
unsigned NumIn,
unsigned NumOut,
bool IsSigned,
257 SmallVector<Value *, 2> ValuesToRelease)
258 : NumIn(NumIn), NumOut(NumOut), IsSigned(IsSigned),
259 ValuesToRelease(std::
move(ValuesToRelease)) {}
266 unsigned NumVars = 0;
268 bool IsSigned =
false;
270 ConstraintTy() =
default;
272 ConstraintTy(RowTy Coefficients,
unsigned NumVars,
bool IsSigned,
bool IsEq,
274 : Coefficients(std::
move(Coefficients)), NumVars(NumVars),
275 IsSigned(IsSigned), IsEq(IsEq), IsNe(IsNe) {}
277 bool empty()
const {
return Coefficients.empty(); }
279 bool isEq()
const {
return IsEq; }
281 bool isNe()
const {
return IsNe; }
288 std::optional<bool> isImpliedBy(
const ConstraintSystem &CS)
const;
300 DecompEntry(int64_t Coefficient,
Value *Variable)
301 : Coefficient(Coefficient), Variable(Variable) {}
305struct Decomposition {
309 Decomposition(int64_t Offset) : Offset(Offset) {}
310 Decomposition(
Value *
V) { Vars.emplace_back(1,
V); }
312 : Offset(Offset), Vars(Vars) {}
316 [[nodiscard]]
bool add(int64_t OtherOffset) {
322 [[nodiscard]]
bool add(
const Decomposition &
Other) {
331 [[nodiscard]]
bool sub(
const Decomposition &
Other) {
332 Decomposition Tmp =
Other;
343 [[nodiscard]]
bool mul(int64_t Factor) {
346 for (
auto &Var : Vars)
347 if (
MulOverflow(Var.Coefficient, Factor, Var.Coefficient))
359class ConstraintInfo {
361 ConstraintSystem UnsignedCS;
362 ConstraintSystem SignedCS;
364 const DataLayout &DL;
369 static constexpr unsigned MaxDoesHoldDepth = 2;
371 using DecomposeKey = std::pair<PointerIntPair<Value *, 1, bool>,
unsigned>;
376 DenseMap<DecomposeKey, Decomposition> DecomposeCache;
379 unsigned DoesHoldDepth = 0;
382 DenseMap<DecomposeKey, Decomposition> &getDecomposeCache() {
383 return DecomposeCache;
386 unsigned getDoesHoldDepth()
const {
return DoesHoldDepth; }
388 static DecomposeKey getDecomposeKey(
Value *
V,
bool IsSigned,
unsigned Depth) {
389 return {{
V, IsSigned},
Depth};
393 : UnsignedCS(FunctionArgs), SignedCS(FunctionArgs), DL(DL) {
394 auto &Value2Index = getValue2Index(
false);
396 for (
Value *Arg : FunctionArgs)
397 UnsignedCS.addRow({
Entry(0, 0),
Entry(-1, Value2Index.at(Arg))},
401 DenseMap<Value *, unsigned> &getValue2Index(
bool Signed) {
402 return Signed ? SignedCS.getValue2Index() : UnsignedCS.getValue2Index();
404 const DenseMap<Value *, unsigned> &getValue2Index(
bool Signed)
const {
405 return Signed ? SignedCS.getValue2Index() : UnsignedCS.getValue2Index();
408 ConstraintSystem &getCS(
bool Signed) {
409 return Signed ? SignedCS : UnsignedCS;
411 const ConstraintSystem &getCS(
bool Signed)
const {
412 return Signed ? SignedCS : UnsignedCS;
415 void popLastConstraint(
bool Signed) {
416 assert(DecomposeCache.empty() &&
"Cache must be cleared");
417 getCS(
Signed).popLastConstraint();
419 void popLastNVariables(
bool Signed,
unsigned N) {
420 assert(DecomposeCache.empty() &&
"Cache must be cleared");
421 getCS(
Signed).popLastNVariables(
N);
431 function_ref<std::optional<bool>()> Solve);
449 unsigned NumOut, SmallVectorImpl<StackEntry> &DFSInStack);
456 SmallVectorImpl<Value *> &NewVariables,
457 bool ForceSignedSystem =
false);
472 unsigned NumIn,
unsigned NumOut,
473 SmallVectorImpl<StackEntry> &DFSInStack);
480 unsigned NumOut, SmallVectorImpl<StackEntry> &DFSInStack,
481 bool ForceSignedSystem);
485 void tightenBoundUsingNe(
Value *
A,
Value *
B,
unsigned NumIn,
unsigned NumOut,
486 SmallVectorImpl<StackEntry> &DFSInStack);
492 APInt ConstantOffset;
493 SmallMapVector<Value *, APInt, 4> VariableOffsets;
498 OffsetResult(GEPOperator &
GEP,
const DataLayout &
DL)
500 ConstantOffset = APInt(
DL.getIndexTypeSizeInBits(
BasePtr->getType()), 0);
510 unsigned BitWidth = Result.ConstantOffset.getBitWidth();
512 Result.ConstantOffset))
520 bool CanCollectInner = InnerGEP->collectOffset(
521 DL,
BitWidth, VariableOffsets2, ConstantOffset2);
523 if (!CanCollectInner || Result.VariableOffsets.size() > 1 ||
524 VariableOffsets2.
size() > 1 ||
525 (Result.VariableOffsets.size() >= 1 && VariableOffsets2.
size() >= 1)) {
531 bool Overflow =
false;
532 APInt CombinedOffset =
533 Result.ConstantOffset.sadd_ov(ConstantOffset2, Overflow);
537 Result.BasePtr = InnerGEP->getPointerOperand();
538 Result.ConstantOffset = CombinedOffset;
539 if (Result.VariableOffsets.size() == 0 && VariableOffsets2.
size() == 1)
540 Result.VariableOffsets = std::move(VariableOffsets2);
541 Result.NW &= InnerGEP->getNoWrapFlags();
546static Decomposition
decompose(
Value *
V, ConstraintInfo &Info,
bool IsSigned,
562 int64_t RequiredOffset = -
static_cast<int64_t
>(Slack.
getZExtValue());
564 const auto &Value2Index = Info.getValue2Index(
Signed);
565 unsigned OpIdx = Value2Index.lookup(
Op);
569 int64_t OpCoefficient =
Upper ? 1 : -1;
570 unsigned OpSize =
Op->getType()->getScalarSizeInBits();
574 if (Row.size() != 3 || Row[0].Id != 0 ||
575 Row[0].Coefficient > RequiredOffset)
577 bool OpFirst = Row[1].Id == OpIdx;
578 const Entry &OpE = Row[OpFirst ? 1 : 2];
579 const Entry &WitnessE = Row[OpFirst ? 2 : 1];
580 if (OpE.Id != OpIdx || OpE.Coefficient != OpCoefficient ||
581 WitnessE.Coefficient != -OpCoefficient)
585 Value2Index, [&](
const auto &KV) {
return KV.second == WitnessE.Id; });
586 assert(Witness != Value2Index.end() &&
"row variables must be mapped");
587 Type *WitnessTy = Witness->first->getType();
598 if (R.isEmptySet() || (
Signed ? R.isSignWrappedSet() : R.isWrappedSet()))
604 unsigned BitWidth = R.getBitWidth();
605 APInt Min =
Signed ? R.getSignedMin() : R.getUnsignedMin();
606 APInt Max =
Signed ? R.getSignedMax() : R.getUnsignedMax();
612 APInt UpperSlack = MaxVal - Max;
620 ConstantInt::get(Ty, Min)) &&
625 ConstantInt::get(Ty, Max)) &&
634 unsigned NoWrapFlags, ConstraintInfo &Info,
638 if (NoWrapFlags & (
Signed ? OBO::NoSignedWrap : OBO::NoUnsignedWrap))
641 if (Opcode == Instruction::Sub) {
646 if (
auto Op1Sign = Info.getKnownSign(Op1,
false)) {
653 if (Info.getKnownSign(Op0,
true) == Op1Sign)
658 if (!
Signed && (NoWrapFlags & OBO::NoSignedWrap) &&
659 (Opcode == Instruction::Shl || Info.isKnownNonNegative(Op1)) &&
660 Info.isKnownNonNegative(Op0))
667 Opcode,
C->getValue(),
668 Signed ? OBO::NoSignedWrap : OBO::NoUnsignedWrap);
673 if (
Signed && Opcode == Instruction::Add) {
674 if (
auto Op0Sign = Info.getKnownSign(Op0,
false))
675 if (
auto Op1Sign = Info.getKnownSign(Op1,
false))
676 if (*Op0Sign != *Op1Sign)
690 return isKnownNoWrap(WO->getBinaryOp(), WO->getLHS(), WO->getRHS(),
695 return Trunc->hasNoSignedWrap();
699 return Trunc->hasNoUnsignedWrap() ||
700 (
Trunc->hasNoSignedWrap() &&
701 Info.isKnownNonNegative(
Trunc->getOperand(0)));
707 BO->getOperand(0), BO->getOperand(1),
708 BO->getNoWrapKind(), Info,
Signed);
715 if (
DL.getIndexTypeSizeInBits(
GEP.getPointerOperand()->getType()) > 64)
718 assert(!IsSigned &&
"The logic below only supports decomposition for "
719 "unsigned predicates at the moment.");
720 const auto &[BasePtr, ConstantOffset, VariableOffsets, NW] =
729 if (!NW.hasNoUnsignedSignedWrap() && ConstantOffset.isNegative())
732 Decomposition Result(ConstantOffset.getSExtValue(), DecompEntry(1, BasePtr));
733 for (
auto [Index, Scale] : VariableOffsets) {
736 if (Index->getType()->getScalarSizeInBits() != Scale.getBitWidth())
738 if (!NW.hasNoUnsignedWrap()) {
741 assert(NW.hasNoUnsignedSignedWrap() &&
"Must have nusw flag");
742 if (!Info.isKnownNonNegative(Index))
744 }
else if (!NW.hasNoUnsignedSignedWrap()) {
747 if (Scale.isNegative())
751 auto IdxResult =
decompose(Index, Info, IsSigned,
DL);
752 if (IdxResult.mul(Scale.getSExtValue()))
754 if (Result.add(IdxResult))
774 switch (
Op->getOpcode()) {
775 case Instruction::GetElementPtr:
776 case Instruction::Add:
777 case Instruction::Sub:
778 case Instruction::Mul:
779 case Instruction::Shl:
780 case Instruction::LShr:
781 case Instruction::AShr:
782 case Instruction::ZExt:
783 case Instruction::SExt:
784 case Instruction::Trunc:
785 case Instruction::Or:
786 case Instruction::Xor:
800 auto &Cache = Info.getDecomposeCache();
801 unsigned CurDepth = Info.getDoesHoldDepth();
803 auto It = Cache.find(ConstraintInfo::getDecomposeKey(
V, IsSigned,
Depth));
804 if (It != Cache.end())
809 Info.getDecomposeCache().insert(
810 {ConstraintInfo::getDecomposeKey(
V, IsSigned, CurDepth), Result});
816 auto MergeResults = [&Info, IsSigned,
818 bool IsSignedB) -> std::optional<Decomposition> {
821 if (
Opc == Instruction::Sub ? ResA.sub(ResB) : ResA.add(ResB))
834 if ((
Opc == Instruction::Add ||
Opc == Instruction::Sub) &&
837 if (
auto Decomp = MergeResults(
Opc, WO->getLHS(), WO->getRHS(), IsSigned))
842 Type *Ty =
V->getType()->getScalarType();
843 if (Ty->isPointerTy() && !IsSigned) {
855 if (!Ty->isIntegerTy() || Ty->getIntegerBitWidth() > 64)
861 return CI->getSExtValue();
863 return int64_t(CI->getZExtValue());
879 if (!IsSigned && !Info.isKnownNonNegative(Op0))
883 if (
Trunc->getSrcTy()->getScalarSizeInBits() <= 64 &&
890 if (
auto Decomp = MergeResults(Instruction::Add, Op0, Op1, IsSigned))
901 MergeResults(Instruction::Add, Op0, CI,
true))
908 Decomposition Result(-1);
909 if (!Result.sub(
decompose(Op0, Info, IsSigned,
DL)))
939 (IsSigned == IsAShr || Info.isKnownNonNegative(Op0))) {
942 if (Result.Offset % Factor == 0 &&
943 all_of(Result.Vars, [Factor](
const DecompEntry &
E) {
944 return E.Coefficient % Factor == 0;
946 Result.Offset /= Factor;
947 for (
auto &
E : Result.Vars)
948 E.Coefficient /= Factor;
959 int64_t MaxShift = IsSigned ? Ty->getIntegerBitWidth() - 1 : 63;
977 const Decomposition &BDec,
983 if (
SubOverflow(BDec.Offset, ADec.Offset, OffsetSum))
985 RowTy R(1, Entry(OffsetSum, 0));
986 auto GetCoefficient = [&R](
unsigned Idx) -> int64_t & {
991 if (
I == R.end() ||
I->Id != Idx)
992 I = R.insert(
I, Entry(0, Idx));
993 return I->Coefficient;
997 auto GetOrAddIndex = [&Value2Index, &NewVariables](
Value *
V) ->
unsigned {
998 auto V2I = Value2Index.
find(
V);
999 if (V2I != Value2Index.
end())
1001 unsigned Idx =
find(NewVariables,
V) - NewVariables.
begin();
1002 if (Idx == NewVariables.
size())
1004 return Value2Index.
size() + Idx + 1;
1006 for (
const DecompEntry &KV : ADec.Vars)
1007 GetCoefficient(GetOrAddIndex(KV.Variable)) += KV.Coefficient;
1009 for (
const DecompEntry &KV : BDec.Vars) {
1010 auto &Coeff = GetCoefficient(GetOrAddIndex(KV.Variable));
1016 erase_if(R, [](
const Entry &
E) {
return E.Id != 0 &&
E.Coefficient == 0; });
1023 bool ForceSignedSystem) {
1024 assert(NewVariables.
empty() &&
"NewVariables must be empty when passed in");
1026 "signed system can only be forced on eq/ne");
1067 auto &Value2Index = getValue2Index(IsSigned);
1077 if (
AddOverflow(R[0].Coefficient, int64_t(-1), R[0].Coefficient))
1081 unsigned NumV2I = Value2Index.size();
1082 NewVariables.
truncate(
R.back().Id > NumV2I ?
R.back().Id - NumV2I : 0);
1084 return ConstraintTy(std::move(R), Value2Index.size() + NewVariables.
size(),
1085 IsSigned, IsEq, IsNe);
1096 return ConstraintTy(RowTy(1,
Entry(0, 0)), 0,
1097 false,
false,
false);
1109 ConstraintTy
R = getConstraint(
Pred, Op0, Op1, NewVariables);
1110 if (!NewVariables.
empty())
1116ConstraintTy::isImpliedBy(
const ConstraintSystem &CS)
const {
1117 const auto &[SubCS, NewCoefficients] = CS.
getSubSystem(Coefficients);
1118 bool IsConditionImplied = SubCS.isConditionImplied(NewCoefficients);
1122 bool IsNegatedOrEqualImplied =
1123 !NegatedOrEqual.empty() && SubCS.isConditionImplied(NegatedOrEqual);
1128 if (IsConditionImplied && IsNegatedOrEqualImplied)
1132 bool IsNegatedImplied =
1133 !Negated.empty() && SubCS.isConditionImplied(Negated);
1136 bool IsStrictLessThanImplied =
1137 !StrictLessThan.empty() && SubCS.isConditionImplied(StrictLessThan);
1143 if (IsNegatedImplied || IsStrictLessThanImplied)
1146 return std::nullopt;
1149 if (IsConditionImplied)
1153 auto IsNegatedImplied = !Negated.empty() && SubCS.isConditionImplied(Negated);
1154 if (IsNegatedImplied)
1158 return std::nullopt;
1162 ConstraintInfo &Info,
1163 const DataLayout &
DL);
1166ConstraintInfo::tryWithLinkRows(
Value *
A,
Value *
B,
const ConstraintTy &
C,
1167 function_ref<std::optional<bool>()> Solve) {
1168 if (std::optional<bool> Res = Solve())
1171 return std::nullopt;
1173 auto &CS = getCS(
C.IsSigned);
1174 unsigned NumVars = getValue2Index(
C.IsSigned).size();
1175 unsigned NumPushed = 0;
1179 if (Row.empty() || Negated.empty())
1181 NumPushed += CS.
addRow(Row, NumVars);
1182 NumPushed += CS.
addRow(Negated, NumVars);
1185 return std::nullopt;
1187 unsigned NumRows = CS.
size();
1189 std::optional<bool> Res = Solve();
1190 assert(CS.
size() == NumRows &&
"rows added while link rows are pushed");
1199 if (DoesHoldDepth >= MaxDoesHoldDepth) {
1200 ++NumDoesHoldDepthLimitHit;
1205 auto R = getConstraintForSolving(
Pred,
A,
B);
1208 auto &CS = getCS(
R.IsSigned);
1209 return tryWithLinkRows(
A,
B, R,
1210 [&]() -> std::optional<bool> {
1213 return std::nullopt;
1218bool ConstraintInfo::isKnownNonNegative(
Value *
V) {
1220 return !CI->isNegative();
1221 return ::isKnownNonNegative(
V,
DL) ||
1225bool ConstraintInfo::isKnownPositive(
Value *
V) {
1227 return CI->getValue().isStrictlyPositive();
1228 return ::isKnownPositive(
V,
DL) ||
1232std::optional<bool> ConstraintInfo::getKnownSign(
Value *
V,
1233 bool StrictlyNegative) {
1235 return CI->isNegative();
1237 if (
Known.isNonNegative())
1239 if (
Known.isNegative())
1244 if (!StrictlyNegative &&
Known.isNonPositive())
1247 if (doesHold(NegativePred,
V,
Zero))
1249 return std::nullopt;
1252void ConstraintInfo::transferToOtherSystem(
1254 unsigned NumOut, SmallVectorImpl<StackEntry> &DFSInStack) {
1257 if (!
A->getType()->isIntegerTy())
1270 NumOut, DFSInStack);
1280 NumOut, DFSInStack);
1294 NumOut, DFSInStack);
1320static std::pair<Value *, Value *>
1323 "LoopPred must be a predecessor of the phi's block");
1325 return {
nullptr,
nullptr};
1332template <
typename PhiMatchTy>
1341MonotonicInfo State::getMonotonicityInfo(PHINode &PN,
Value *Step) {
1343 const APInt *StepOffset =
nullptr;
1347 Info.Unsigned = !
Info.Decreasing &&
Add->hasNoUnsignedWrap();
1348 Info.Signed =
Add->hasNoSignedWrap();
1354 APInt GEPOffset(
DL.getIndexTypeSizeInBits(
GEP->getType()), 0);
1355 Info.Unsigned =
GEP->getPointerOperand() == &PN &&
1356 (
GEP->hasNoUnsignedWrap() ||
1357 ((
GEP->hasNoUnsignedSignedWrap() &&
1358 GEP->accumulateConstantOffset(
DL, GEPOffset) &&
1359 !GEPOffset.isNegative())));
1364 if (
Info.Unsigned ||
Info.Signed || !StepOffset)
1381void State::addBoundsForHeaderInductions(BasicBlock &BB) {
1383 if (!L ||
L->getHeader() != &BB)
1390 for (PHINode &PN : BB.
phis()) {
1398 MonotonicInfo
Info = getMonotonicityInfo(PN, Step);
1402 Info.Unsigned =
false;
1403 if (!
Info.Unsigned && !
Info.Signed)
1409 if (
Info.Decreasing)
1417void State::addInfoForInductions(BasicBlock &BB) {
1424 if (Header != &BB && Latch != &BB)
1431 PHINode *PN =
nullptr;
1432 const APInt *IncStep =
nullptr;
1442 std::optional<bool> PeeledOnEdge;
1443 if (!
match(Br->getCondition(), CountingCmp)) {
1447 PeeledOnEdge =
true;
1449 PeeledOnEdge =
false;
1458 bool ContinueOnTrue =
1462 BasicBlock *InLoopSucc = Br->getSuccessor(ContinueOnTrue ? 0 : 1);
1466 if (PeeledOnEdge && *PeeledOnEdge != ContinueOnTrue)
1469 if (!
L->contains(InLoopSucc) || !
L->isLoopExiting(&BB))
1473 if (!LoopPred || !
L->isLoopInvariant(
B))
1485 bool HasHeaderBound =
1489 if (HasHeaderBound) {
1491 WorkList.
push_back(FactOrCheck::getConditionFact(
1492 HeaderDTN, BoundPred, PN,
B,
ConditionTy(BoundPred, StartValue,
B)));
1501 if (&BB == Latch && !IncStep)
1511 WorkList.
push_back(FactOrCheck::getConditionFact(
1512 HeaderDTN, ContinuePred, PN,
B,
1518 if (ICmpInst::isSigned(ContinuePred)) {
1521 "Expected a signed less-than continuation predicate");
1522 MonotonicInfo
Info = getMonotonicityInfo(*PN, Backedge);
1523 if (
Info.Signed && !
Info.Decreasing) {
1525 WorkList.
push_back(FactOrCheck::getConditionFact(
1526 HeaderDTN, UPred, PN,
B,
ConditionTy(UPred, StartValue,
B)));
1535 const APInt *StepOffset =
nullptr;
1536 const SCEV *StartSCEV =
nullptr;
1538 if (StepOffset->
isZero())
1541 const SCEV *Expr = SE->
getSCEV(PN);
1550 if (IncStep && *IncStep != *StepOffset)
1553 MonotonicInfo
Info = getMonotonicityInfo(*PN, Backedge);
1558 if (!(-*StepOffset).isOne())
1568 ConditionTy BBeforeStartUnsigned = {UPrecond,
B, StartValue};
1574 WorkList.
push_back(FactOrCheck::getConditionFact(
1576 if (!(
Info.Decreasing &&
Info.Signed))
1577 WorkList.
push_back(FactOrCheck::getConditionFact(
1581 B, BBeforeStartUnsigned));
1583 B, BBeforeStartSigned));
1593 if (!StepOffset->
isOne()) {
1596 StartSCEV = SE->
getSCEV(StartValue);
1610 ConditionTy StartBeforeBoundUnsigned = {UPrecond, StartValue,
B};
1616 WorkList.
push_back(FactOrCheck::getConditionFact(
1619 WorkList.
push_back(FactOrCheck::getConditionFact(
1624 if (!HasHeaderBound || !canAddSuccessor(BB, InLoopSucc)) {
1625 WorkList.
push_back(FactOrCheck::getConditionFact(
1627 WorkList.
push_back(FactOrCheck::getConditionFact(
1640 L->getExitBlocks(ExitBBs);
1641 for (BasicBlock *EB : ExitBBs) {
1655 if (!
GEP.hasNoUnsignedWrap())
1660 Base = InnerGEP->getPointerOperand();
1676 if (
Offset.VariableOffsets.size() != 1)
1680 auto &[Index, Scale] =
Offset.VariableOffsets.front();
1682 if (Index->getType()->getScalarSizeInBits() !=
BitWidth)
1695 B = ConstantInt::get(Index->getType(), MaxIndex);
1703 return Trunc->getType()->isIntegerTy() &&
Trunc->hasNoSignedWrap() &&
1704 !
Trunc->hasNoUnsignedWrap();
1707 if (!BO || !BO->getType()->isIntegerTy())
1710 switch (BO->getOpcode()) {
1711 case Instruction::Sub:
1712 if (BO->hasNoUnsignedWrap() && BO->hasNoSignedWrap())
1717 case Instruction::Add:
1718 case Instruction::Mul:
1719 case Instruction::Shl:
1720 if (BO->hasNoUnsignedWrap() && BO->hasNoSignedWrap())
1739 I->setHasNoSignedWrap();
1744 I->setHasNoUnsignedWrap();
1750void State::addInfoFor(BasicBlock &BB) {
1751 addBoundsForHeaderInductions(BB);
1752 addInfoForInductions(BB);
1758 bool GuaranteedToExecute =
true;
1760 for (Instruction &
I : BB) {
1762 for (Use &U :
I.uses()) {
1764 auto *DTN = DT.
getNode(UserI->getParent());
1767 WorkList.
push_back(FactOrCheck::getCheck(DTN, &U));
1772 auto AddFactFromMemoryAccess = [&](
Value *Ptr,
Type *AccessType) {
1776 TypeSize AccessSize =
DL.getTypeStoreSize(AccessType);
1779 if (GuaranteedToExecute) {
1789 FactOrCheck::getInstFact(DT.
getNode(
I.getParent()), &
I));
1794 if (!LI->isVolatile())
1795 AddFactFromMemoryAccess(LI->getPointerOperand(), LI->getAccessType());
1798 if (!
SI->isVolatile())
1799 AddFactFromMemoryAccess(
SI->getPointerOperand(),
SI->getAccessType());
1805 case Intrinsic::assume: {
1808 if (GuaranteedToExecute) {
1815 FactOrCheck::getInstFact(DT.
getNode(
I.getParent()), &
I));
1820 case Intrinsic::uadd_with_overflow:
1821 case Intrinsic::sadd_with_overflow:
1822 case Intrinsic::usub_with_overflow:
1823 case Intrinsic::ssub_with_overflow:
1824 case Intrinsic::umul_with_overflow:
1825 case Intrinsic::smul_with_overflow:
1826 case Intrinsic::ucmp:
1827 case Intrinsic::scmp:
1832 case Intrinsic::umin:
1833 case Intrinsic::umax:
1834 case Intrinsic::smin:
1835 case Intrinsic::smax:
1836 case Intrinsic::usub_sat:
1841 case Intrinsic::uadd_sat:
1847 case Intrinsic::abs:
1862 if ((BO->getOpcode() == Instruction::URem ||
1863 BO->getOpcode() == Instruction::UDiv ||
1864 BO->getOpcode() == Instruction::LShr ||
1865 BO->getOpcode() == Instruction::SRem ||
1866 BO->getOpcode() == Instruction::SDiv) &&
1875 WorkList.
push_back(FactOrCheck::getCheck(
1883 for (
auto &Case :
Switch->cases()) {
1885 Value *
V = Case.getCaseValue();
1886 if (!canAddSuccessor(BB, Succ))
1902 WithOverflowInst *WO;
1905 canAddSuccessor(BB, Br->getSuccessor(1)))
1906 for (User *U : WO->
users())
1908 WorkList.
push_back(FactOrCheck::getConditionFact(
1926 SmallPtrSet<Value *, 8> SeenCond;
1927 auto QueueValue = [&CondWorkList, &SeenCond](
Value *
V) {
1928 if (SeenCond.
insert(
V).second)
1933 while (!CondWorkList.
empty()) {
1958 if (canAddSuccessor(BB, Br->getSuccessor(0)))
1961 if (canAddSuccessor(BB, Br->getSuccessor(1)))
1969 OS <<
"icmp " <<
Pred <<
' ';
1970 LHS->printAsOperand(OS,
true);
1972 RHS->printAsOperand(OS,
false);
1981struct ReproducerEntry {
1982 ICmpInst::Predicate
Pred;
2017 auto &Value2Index = Info.getValue2Index(IsSigned);
2019 while (!WorkList.
empty()) {
2023 if (Old2New.
find(
V) != Old2New.
end())
2029 if (Value2Index.contains(
V) || !
I ||
2040 for (
auto &Entry : Stack)
2043 CollectArguments(
Cond, IsSigned);
2046 for (
auto *
P : Args)
2052 Cond->getModule()->getName() +
2053 Cond->getFunction()->getName() +
"repro",
2056 for (
unsigned I = 0;
I < Args.size(); ++
I) {
2058 Old2New[Args[
I]] =
F->getArg(
I);
2063 Builder.CreateRet(Builder.getTrue());
2064 Builder.SetInsertPoint(Entry->getTerminator());
2073 auto &Value2Index = Info.getValue2Index(IsSigned);
2074 while (!WorkList.
empty()) {
2076 if (Old2New.
find(
V) != Old2New.
end())
2080 if (!Value2Index.contains(
V) &&
I) {
2081 Old2New[
V] =
nullptr;
2091 Old2New[
I] = Cloned;
2092 Old2New[
I]->setName(
I->getName());
2104 for (
auto &Entry : Stack) {
2113 auto *Cmp = Builder.CreateICmp(Entry.Pred, Entry.LHS, Entry.RHS);
2114 Builder.CreateAssumption(Cmp);
2119 CloneInstructions(
Cond, IsSigned);
2120 Entry->getTerminator()->setOperand(0,
Cond);
2131 ConstraintInfo &Info,
2133 const auto &Value2Index = Info.getValue2Index(
C.IsSigned);
2134 auto It = Value2Index.find(
V);
2135 if (It == Value2Index.end() ||
2137 [Id = It->second](
const Entry &
E) { return E.Id == Id; }))
2143 Value2Index, NewVariables);
2144 return NewVariables.
empty() ? Row : RowTy();
2149 ConstraintInfo &Info) {
2152 auto TryWithConstraint = [&](
const ConstraintTy &R) -> std::optional<bool> {
2155 return std::nullopt;
2158 auto &CSToUse = Info.getCS(R.IsSigned);
2159 if (
auto ImpliedCondition = R.isImpliedBy(CSToUse)) {
2161 return std::nullopt;
2163 dbgs() <<
"Condition ";
2165 *ImpliedCondition ?
Pred
2168 dbgs() <<
" implied by dominating constraints\n";
2171 return ImpliedCondition;
2173 return std::nullopt;
2178 auto TryWithLinkedDecomposition =
2179 [&](
const ConstraintTy &
C) -> std::optional<bool> {
2180 return Info.tryWithLinkRows(
A,
B,
C, [&] {
return TryWithConstraint(
C); });
2183 auto R = Info.getConstraintForSolving(
Pred,
A,
B);
2184 if (
auto ImpliedCondition = TryWithLinkedDecomposition(R))
2185 return ImpliedCondition;
2193 if (NewVariables.
empty() && !SR.empty() && Info.isKnownNonNegative(
A) &&
2194 Info.isKnownNonNegative(
B))
2195 if (
auto ImpliedCondition = TryWithConstraint(SR))
2196 return ImpliedCondition;
2202 const auto &Value2Index = Info.getValue2Index(
true);
2203 if (!Value2Index.contains(
A) && !Value2Index.contains(
B))
2204 return std::nullopt;
2207 auto SR = Info.getConstraint(
Pred,
A,
B, NewVariables,
2209 if (NewVariables.
empty()) {
2210 if (
auto ImpliedCondition = TryWithLinkedDecomposition(SR))
2211 return ImpliedCondition;
2214 return std::nullopt;
2219 ConstraintInfo &Info,
unsigned NumIn,
unsigned NumOut,
2223 auto ReplaceCmpWithConstant = [&](
Instruction *CheckInst,
bool IsTrue) {
2225 ReproducerCondStack, Info, DT);
2230 auto *DTN = DT.
getNode(UserI->getParent());
2233 if (UserI->getParent() == ContextInst->
getParent() &&
2234 UserI->comesBefore(ContextInst))
2240 return !
II ||
II->getIntrinsicID() != Intrinsic::assume;
2249 for (
auto *DVR : DVRUsers) {
2250 auto *DTN = DT.
getNode(DVR->getParent());
2254 auto *MarkedI = DVR->getInstruction();
2255 if (MarkedI->getParent() == ContextInst->
getParent() &&
2256 MarkedI->comesBefore(ContextInst))
2259 DVR->replaceVariableLocationOp(CheckInst, ConstantC);
2269 return ReplaceCmpWithConstant(CheckInst, *ImpliedCondition);
2276 return ReplaceCmpWithConstant(CheckInst, *ImpliedCondition);
2285 MinMax->replaceAllUsesWith(
MinMax->getOperand(UseLHS ? 0 : 1));
2294 return ReplaceMinMaxWithOperand(
MinMax, *ImpliedCondition);
2297 return ReplaceMinMaxWithOperand(
MinMax, !*ImpliedCondition);
2306 I->replaceAllUsesWith(ConstantInt::get(
I->getType(), 1));
2316 I->replaceAllUsesWith(ConstantInt::get(
I->getType(), 0));
2334 Value *
Sub = Builder.CreateSub(
A,
B,
"",
true,
2335 Info.isKnownNonNegative(
A));
2337 Sub->takeName(USub);
2344 Module *ReproducerModule,
2347 Info.getDecomposeCache().clear();
2348 Info.popLastConstraint(
E.IsSigned);
2350 auto &Mapping = Info.getValue2Index(
E.IsSigned);
2351 for (
Value *
V :
E.ValuesToRelease)
2353 Info.popLastNVariables(
E.IsSigned,
E.ValuesToRelease.size());
2355 if (ReproducerModule)
2362 FactOrCheck &CB, ConstraintInfo &Info,
Module *ReproducerModule,
2371 unsigned OtherOpIdx = JoinOp->
getOperand(0) == CmpToCheck ? 1 : 0;
2379 unsigned OldSize = DFSInStack.
size();
2382 while (OldSize < DFSInStack.
size()) {
2383 StackEntry
E = DFSInStack.
back();
2391 while (!Worklist.empty()) {
2392 Value *Val = Worklist.pop_back_val();
2400 Info.addFact(
Pred,
LHS,
RHS, CB.NumIn, CB.NumOut, DFSInStack);
2405 Worklist.push_back(
LHS);
2406 Worklist.push_back(
RHS);
2409 if (OldSize == DFSInStack.
size())
2414 [[maybe_unused]]
bool Matched =
2416 assert(Matched &&
"expected icmp-like match");
2419 if (IsOr == *ImpliedCondition)
2432 unsigned NumIn,
unsigned NumOut,
2433 SmallVectorImpl<StackEntry> &DFSInStack) {
2434 addFactImpl(
Pred,
A,
B, NumIn, NumOut, DFSInStack,
false);
2437 addFactImpl(
Pred,
A,
B, NumIn, NumOut, DFSInStack,
true);
2439 tightenBoundUsingNe(
A,
B, NumIn, NumOut, DFSInStack);
2442void ConstraintInfo::tightenBoundUsingNe(
2444 SmallVectorImpl<StackEntry> &DFSInStack) {
2445 if (!
A->getType()->isIntOrPtrTy())
2448 for (
bool IsSigned : {
false,
true}) {
2455 const auto &Value2Index = getValue2Index(IsSigned);
2457 [&Value2Index](
const DecompEntry &
E) {
2458 return !Value2Index.contains(
E.Variable);
2469 if (!doesHold(NonStrict,
A,
B))
2475 dbgs() <<
"' using inequality\n");
2476 addFactImpl(
Strict,
A,
B, NumIn, NumOut, DFSInStack,
2484 unsigned NumIn,
unsigned NumOut,
2485 SmallVectorImpl<StackEntry> &DFSInStack,
2486 bool ForceSignedSystem) {
2488 auto R = getConstraint(
Pred,
A,
B, NewVariables, ForceSignedSystem);
2491 if (
R.empty() ||
R.isNe())
2494 auto &CSToUse = getCS(
R.IsSigned);
2498 if (!
R.isEq() && NewVariables.
empty()) {
2500 if (CSToUse.isImpliedBySingleRow(
R.Coefficients))
2505 bool Added = CSToUse.addRow(
R.Coefficients,
R.NumVars);
2509 DecomposeCache.
clear();
2513 SmallVector<Value *, 2> ValuesToRelease;
2514 auto &Value2Index = getValue2Index(
R.IsSigned);
2515 for (
Value *
V : NewVariables) {
2516 Value2Index.try_emplace(
V, Value2Index.size() + 1);
2521 dbgs() <<
" constraint: ";
2527 std::move(ValuesToRelease));
2530 for (
Value *
V : NewVariables) {
2532 CSToUse.addRow({
Entry(0, 0),
Entry(-1, Value2Index.at(
V))},
2533 Value2Index.size());
2535 SmallVector<Value *, 2>());
2541 for (Entry &
E :
R.Coefficients)
2544 CSToUse.addRow(
R.Coefficients,
R.NumVars);
2547 SmallVector<Value *, 2>());
2557 Value *Res =
nullptr;
2561 Res = Builder.CreateNoWrapBinOp(
II->getBinaryOp(),
II->getLHS(),
2565 I->replaceAllUsesWith(Res);
2573 if (
I->use_empty()) {
2580 if (
II->use_empty()) {
2582 for (
Use &Arg :
II->args())
2606 ConstraintInfo Info(
F.getDataLayout(), FunctionArgs);
2607 State S(DT, LI, SE,
TLI);
2608 std::unique_ptr<Module> ReproducerModule(
2609 Opts.constraint_elimination_dump_reproducers
2610 ?
new Module(
F.getName(),
F.getContext())
2629 stable_sort(S.WorkList, [](
const FactOrCheck &
A,
const FactOrCheck &
B) {
2630 auto HasNoConstOp = [](const FactOrCheck &B) {
2631 Value *V0 = B.isConditionFact() ? B.Cond.Op0 : B.Inst->getOperand(0);
2632 Value *V1 = B.isConditionFact() ? B.Cond.Op1 : B.Inst->getOperand(1);
2633 return !isa<ConstantInt>(V0) && !isa<ConstantInt>(V1);
2637 if (
A.NumIn ==
B.NumIn) {
2638 if (A.isConditionFact() && B.isConditionFact()) {
2639 bool NoConstOpA = HasNoConstOp(A);
2640 bool NoConstOpB = HasNoConstOp(B);
2641 return NoConstOpA < NoConstOpB;
2643 if (
A.isConditionFact())
2645 if (
B.isConditionFact())
2647 auto *InstA =
A.getContextInst();
2648 auto *InstB =
B.getContextInst();
2649 return InstA->comesBefore(InstB);
2651 return A.NumIn <
B.NumIn;
2654 SmallVector<Instruction *>
ToRemove;
2659 for (FactOrCheck &CB : S.WorkList) {
2662 while (!DFSInStack.
empty()) {
2663 auto &
E = DFSInStack.
back();
2666 LLVM_DEBUG(
dbgs() <<
"CB: " << CB.NumIn <<
" " << CB.NumOut <<
"\n");
2668 if (CB.NumOut <=
E.NumOut)
2671 dbgs() <<
"Removing ";
2673 Info.getValue2Index(
E.IsSigned));
2685 Instruction *Inst = CB.getInstructionToSimplify();
2692 LLVM_DEBUG(
dbgs() <<
"Processing condition to simplify: " << *Inst
2698 Pred,
A,
B, Inst, Info, CB.NumIn, CB.NumOut, CB.getContextInst(),
2699 ReproducerModule.get(), ReproducerCondStack, S.DT,
ToRemove);
2703 CB, Info, ReproducerModule.get(), ReproducerCondStack, DFSInStack,
2722 Opts.constraint_elimination_max_rows) {
2725 <<
"Skip adding constraint because system has too many rows.\n");
2729 Info.addFact(
Pred,
A,
B, CB.NumIn, CB.NumOut, DFSInStack);
2732 if (ReproducerModule && DFSInStack.
size() > ReproducerCondStack.
size() &&
2733 A->getType() ==
B->getType())
2740 if (
Pred.hasSameSign()) {
2742 CB.NumIn, CB.NumOut, DFSInStack);
2745 if (
A->getType()->isIntegerTy()) {
2746 std::optional<bool> ASign =
2747 Info.getKnownSign(
A,
true);
2748 std::optional<bool> BSign =
2749 Info.getKnownSign(
B,
true);
2750 if (ASign.has_value() != BSign.has_value()) {
2751 bool IsNegative = ASign ? *ASign : *BSign;
2752 Value *OtherOp = ASign ?
B :
A;
2755 CB.NumIn, CB.NumOut, DFSInStack);
2759 Info.transferToOtherSystem(
Pred,
A,
B, CB.NumIn, CB.NumOut,
2774 SmallPtrSet<Value *, 4> Seen;
2775 while (!Worklist.
empty()) {
2778 if (!BO || BO->getOpcode() !=
Opc)
2780 for (
Value *
Op : {BO->getOperand(0), BO->getOperand(1)}) {
2784 Info.addFact(
Pred,
Op,
B, CB.NumIn, CB.NumOut, DFSInStack);
2789 if (ReproducerModule && DFSInStack.
size() > ReproducerCondStack.
size()) {
2792 for (
unsigned I = 0,
2793 E = (DFSInStack.
size() - ReproducerCondStack.
size());
2795 ReproducerCondStack.
emplace_back(ICmpInst::BAD_ICMP_PREDICATE,
2801 if (!CB.isConditionFact()) {
2807 ConstantInt::get(CB.Inst->getType(), 0));
2813 Pred = ICmpInst::getNonStrictPredicate(MinMax->getPredicate());
2814 AddFact(
Pred, MinMax, MinMax->getLHS());
2815 AddFact(
Pred, MinMax, MinMax->getRHS());
2819 switch (USatI->getIntrinsicID()) {
2822 case Intrinsic::uadd_sat:
2823 AddFact(ICmpInst::ICMP_UGE, USatI, USatI->getLHS());
2824 AddFact(ICmpInst::ICMP_UGE, USatI, USatI->getRHS());
2826 case Intrinsic::usub_sat:
2827 AddFact(ICmpInst::ICMP_ULE, USatI, USatI->getLHS());
2834 if (BO->getOpcode() == Instruction::URem) {
2841 if (BO->getOpcode() == Instruction::UDiv) {
2846 if (BO->getOpcode() == Instruction::LShr) {
2851 if (BO->getOpcode() == Instruction::SRem) {
2852 Value *
X = BO->getOperand(0);
2853 Value *
N = BO->getOperand(1);
2871 if (BO->getOpcode() == Instruction::SDiv) {
2872 Value *
X = BO->getOperand(0);
2873 Value *
N = BO->getOperand(1);
2874 if (!
Info.isKnownNonNegative(
X) || !
Info.isKnownPositive(
N))
2877 bool IsStrict =
Info.isKnownPositive(
X) &&
2879 ConstantInt::get(
N->getType(), 1));
2886 auto &
DL =
F.getDataLayout();
2887 auto AddFactsAboutIndices = [&](
Value *Ptr,
Type *AccessType) {
2892 DL.getTypeStoreSize(AccessType).getFixedValue(),
Pred,
A,
B,
DL,
2898 AddFactsAboutIndices(LI->getPointerOperand(), LI->getAccessType());
2902 AddFactsAboutIndices(
SI->getPointerOperand(),
SI->getAccessType());
2907 if (CB.isConditionFact()) {
2908 Pred = CB.Cond.Pred;
2917 dbgs() <<
"Not adding fact ";
2919 dbgs() <<
" because the intrinsic was replaced.\n";
2924 !
Info.doesHold(CB.DoesHold.Pred, CB.DoesHold.Op0, CB.DoesHold.Op1)) {
2926 dbgs() <<
"Not adding fact ";
2928 dbgs() <<
" because precondition ";
2931 dbgs() <<
" does not hold.\n";
2936 [[maybe_unused]]
bool Matched =
2940 "Must have an assume intrinsic with a icmp like operand");
2945 if (ReproducerModule && !ReproducerModule->functions().empty()) {
2947 raw_string_ostream StringS(S);
2948 ReproducerModule->print(StringS,
nullptr);
2949 OptimizationRemark Rem(
DEBUG_TYPE,
"Reproducer", &
F);
2950 Rem <<
ore::NV(
"module") << S;
2955 unsigned SignedEntries =
2956 count_if(DFSInStack, [](
const StackEntry &
E) {
return E.IsSigned; });
2957 assert(
Info.getCS(
false).size() - FunctionArgs.size() ==
2958 DFSInStack.
size() - SignedEntries &&
2959 "updates to CS and DFSInStack are out of sync");
2960 assert(
Info.getCS(
true).size() == SignedEntries &&
2961 "updates to CS and DFSInStack are out of sync");
2965 I->eraseFromParent();
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ReachingDefInfo InstSet & ToRemove
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
std::pair< ICmpInst *, unsigned > ConditionTy
static int64_t MaxConstraintValue
static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI, ScalarEvolution *SE, OptimizationRemarkEmitter &ORE, TargetLibraryInfo &TLI)
static bool canStrengthenFlags(Instruction *I)
Returns true if I is a candidate whose poison-generating flags may be strengthened using the constrai...
static bool doesHoldInRange(ConstraintInfo &Info, Value *Op, const ConstantRange &R, bool Signed)
Returns true if Info implies that Op is in R, interpreting R as a signed range if Signed is set and a...
static RowTy getDecompositionLinkRow(Value *V, const ConstraintTy &C, ConstraintInfo &Info, const DataLayout &DL)
If V is a variable in the system and constraint C does not contain V, we managed to decompose V at th...
static int64_t MinSignedConstraintValue
static bool tryToSimplifyOverflowMath(WithOverflowInst *II, ConstraintInfo &Info, SmallVectorImpl< Instruction * > &ToRemove)
static auto m_IncrementOf(const PhiMatchTy &PhiM, const APInt *&Off)
Matches an increment of PhiM by a constant offset, captured in Off.
static Instruction * getContextInstForUse(Use &U)
static bool isKnownNoWrap(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, unsigned NoWrapFlags, ConstraintInfo &Info, bool Signed)
Returns true if Opcode applied to Op0 and Op1 with NoWrapFlags is known to not wrap in signed or unsi...
static bool mayLookThrough(Value *V)
Returns true if V is an operation decomposeImpl can look through.
static bool canUseSExt(ConstantInt *CI)
static void removeEntryFromStack(const StackEntry &E, ConstraintInfo &Info, Module *ReproducerModule, SmallVectorImpl< ReproducerEntry > &ReproducerCondStack, SmallVectorImpl< StackEntry > &DFSInStack)
static std::optional< bool > checkCondition(CmpInst::Predicate Pred, Value *A, Value *B, Instruction *CheckInst, ConstraintInfo &Info)
static Decomposition decompose(Value *V, ConstraintInfo &Info, bool IsSigned, const DataLayout &DL)
static bool checkOrAndOpImpliedByOther(FactOrCheck &CB, ConstraintInfo &Info, Module *ReproducerModule, SmallVectorImpl< ReproducerEntry > &ReproducerCondStack, SmallVectorImpl< StackEntry > &DFSInStack, SmallVectorImpl< Instruction * > &ToRemove)
Check if either the first condition of an AND or OR is implied by the (negated in case of OR) second ...
static OffsetResult collectOffsets(GEPOperator &GEP, const DataLayout &DL)
static bool checkAndReplaceMinMax(MinMaxIntrinsic *MinMax, ConstraintInfo &Info, SmallVectorImpl< Instruction * > &ToRemove)
static bool tryToStrengthenFlags(Instruction *I, ConstraintInfo &Info)
Try to strengthen I's poison generating flags using Info.
static RowTy getRowForLessEqual(const Decomposition &ADec, const Decomposition &BDec, const DenseMap< Value *, unsigned > &Value2Index, SmallVectorImpl< Value * > &NewVariables)
Build the row for 'ADec <= BDec', using the indices from Value2Index.
static void dumpConstraint(ArrayRef< Entry > C, const DenseMap< Value *, unsigned > &Value2Index)
static bool replaceOverflowUses(WithOverflowInst *II, SmallVectorImpl< Instruction * > &ToRemove)
Replace the uses of II, which is known not to overflow, by the corresponding plain binary operation a...
static bool getConstraintFromMemoryAccess(GetElementPtrInst &GEP, uint64_t AccessSize, CmpPredicate &Pred, Value *&A, Value *&B, const DataLayout &DL, const TargetLibraryInfo &TLI)
static void dumpUnpackedICmp(raw_ostream &OS, ICmpInst::Predicate Pred, Value *LHS, Value *RHS)
static void generateReproducer(Instruction *Cond, bool IsSigned, Module *M, ArrayRef< ReproducerEntry > Stack, ConstraintInfo &Info, DominatorTree &DT)
Helper function to generate a reproducer function for simplifying Cond.
static bool checkAndReplaceUSubSat(SaturatingInst *USub, ConstraintInfo &Info, SmallVectorImpl< Instruction * > &ToRemove)
Try to replace USub by a plain subtract, if Info proves it cannot saturate.
static bool hasLimitWitness(const ConstraintInfo &Info, Value *Op, const APInt &Slack, bool Signed, bool Upper)
Returns true if Op <= MaxVal - Slack holds in the system for Signed, by scanning it for a row of the ...
static bool checkAndReplaceCondition(CmpPredicate Pred, Value *A, Value *B, Instruction *CheckInst, ConstraintInfo &Info, unsigned NumIn, unsigned NumOut, Instruction *ContextInst, Module *ReproducerModule, ArrayRef< ReproducerEntry > ReproducerCondStack, DominatorTree &DT, SmallVectorImpl< Instruction * > &ToRemove)
static Instruction * findCommonDominatorOfUses(Instruction &I, DominatorTree &DT)
Returns the closest program point dominating all uses of I.
static Decomposition decomposeImpl(Value *V, ConstraintInfo &Info, bool IsSigned, const DataLayout &DL)
static bool checkAndReplaceCmp(CmpIntrinsic *I, ConstraintInfo &Info, SmallVectorImpl< Instruction * > &ToRemove)
static std::pair< Value *, Value * > getStartAndBackedgeValue(const PHINode &PN, const BasicBlock *LoopPred)
Splits the induction phi PN into the start value, coming from the loop predecessor LoopPred,...
static Decomposition decomposeGEP(GEPOperator &GEP, ConstraintInfo &Info, bool IsSigned, const DataLayout &DL)
This file provides an implementation of debug counters.
#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
This is the interface for a simple mod/ref and alias analysis over globals.
Module.h This file contains the declarations for the Module class.
static std::optional< bool > getKnownSign(Value *Op, const SimplifyQuery &SQ)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
SmallVector< MachineOperand, 4 > Cond
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
This file defines the PointerIntPair class.
static StringRef getName(Value *V)
This file provides utility classes that use RAII to save and restore values.
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
LLVM_ABI APInt urem(const APInt &RHS) const
Unsigned remainder operation.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
bool isNegative() const
Determine sign of this APInt.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
bool slt(const APInt &RHS) const
Signed less than comparison.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
bool isOne() const
Determine if this is a value of 1.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
LLVM_ABI Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
Represents analyses that only rely on functions' control flow.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Predicate getStrictPredicate() const
For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.
bool isEquality() const
Determine if this is an equals/not equals predicate.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
static LLVM_ABI bool isEquality(Predicate pred)
Determine if this is an equals/not equals predicate.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
This class represents a ucmp/scmp intrinsic.
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI CmpPredicate getInverse(CmpPredicate P)
Get the inverse predicate of a CmpPredicate.
This is the shared class of boolean and integer constants.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
static LLVM_ABI ConstantInt * getBool(LLVMContext &Context, bool V)
This class represents a range of values.
static LLVM_ABI ConstantRange makeExactNoWrapRegion(Instruction::BinaryOps BinOp, const APInt &Other, unsigned NoWrapKind)
Produce the range that contains X if and only if "X BinOp Other" does not wrap.
This is an important base class in LLVM.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
bool addRow(ArrayRef< Entry > R, size_t NumVars)
static RowTy negate(RowTy R)
unsigned size() const
Returns the number of rows in the constraint system.
LLVM_ABI std::pair< ConstraintSystem, RowTy > getSubSystem(ArrayRef< Entry > R) const
Build and return a sub-system of constraints connected (transitively) to query R, with variables comp...
static RowTy toStrictLessThan(RowTy R)
Converts the given row to form a strict less than inequality.
static LLVM_ABI void normalizeByGCD(MutableArrayRef< Entry > R)
Divide the variable coefficients of R by their greatest common divisor G and round the constant down ...
LLVM_ABI bool isConditionImpliedInSubSystem(ArrayRef< Entry > R) const
SmallVector< Entry, 8 > RowTy
A single constraint of the form 'c >= v1 * c1 + ... + vn * cn'.
static RowTy negateOrEqual(RowTy R)
Multiplies each coefficient in the given row by -1.
LLVM_ABI void dump() const
Print the constraints in the system.
A parsed version of the target data layout string in and methods for querying it.
static bool shouldExecute(CounterInfo &Counter)
iterator find(const_arg_type_t< KeyT > Val)
unsigned getDFSNumIn() const
getDFSNumIn/getDFSNumOut - These return the DFS visitation order for nodes in the dominator tree.
unsigned getDFSNumOut() const
Analysis pass which computes a DominatorTree.
void updateDFSNumbers() const
updateDFSNumbers - Assign In and Out numbers to the nodes while walking dominator tree in dfs order.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI Instruction * findNearestCommonDominator(Instruction *I1, Instruction *I2) const
Find the nearest instruction I that dominates both I1 and I2, in the sense that a result produced bef...
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
static GEPNoWrapFlags none()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
@ ExternalLinkage
Externally visible function.
static bool isLT(Predicate P)
Return true if the predicate is SLT or ULT.
Predicate getFlippedSignednessPredicate() const
For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
static bool isLE(Predicate P)
Return true if the predicate is SLE or ULE.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
iterator_range< user_iterator > users()
LLVM_ABI void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs={})
Drop all unknown metadata except for debug locations.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
This is an important class for using LLVM in a threaded context.
Analysis pass that exposes the LoopInfo for a function.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
This class represents min/max intrinsics.
A Module instance is used to store all the information related to an LLVM module.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Represents a saturating add/sub intrinsic.
Analysis pass that exposes the ScalarEvolution for a function.
The main scalar evolution driver.
LLVM_ABI const SCEV * getMinusSCEV(SCEVUse LHS, SCEVUse RHS, SCEVFlags Flags=SCEV::FlagNone, unsigned Depth=0)
Return LHS-RHS.
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
MonotonicPredicateType
A predicate is said to be monotonically increasing if may go from being false to being true as the lo...
@ MonotonicallyDecreasing
@ MonotonicallyIncreasing
LLVM_ABI APInt getConstantMultiple(const SCEV *S, const Instruction *CtxI=nullptr)
Returns the max constant multiple of S.
LLVM_ABI std::optional< MonotonicPredicateType > getMonotonicPredicateType(const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred)
If, for all loop invariant X, the predicate "LHS `Pred` X" is monotonically increasing or decreasing,...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void truncate(size_type N)
Like resize, but requires that N is less than size().
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getIntegerBitWidth() const
bool isPointerTy() const
True if this is an instance of PointerType.
bool isIntegerTy() const
True if this is an instance of IntegerType.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
iterator find(const KeyT &Val)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
LLVM_ABI bool replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
Represents an op.with.overflow intrinsic.
constexpr ScalarTy getFixedValue() const
constexpr bool isFixed() const
Returns true if the quantity is not scaled by vscale.
const ParentTy * getParent() const
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BasicBlock
Various leaf nodes.
AllOnesConstantMatch m_AllOnes()
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
match_bind< PHINode > m_Phi(PHINode *&PN)
Match a PHI node, capturing it if we match.
auto m_LogicalOp()
Matches either L && R or L || R where L and R are arbitrary values.
CommutativeBinaryIntrinsic_match< IntrID, T0, T1 > m_c_Intrinsic(const T0 &Op0, const T1 &Op1)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
DisjointOr_match< LHS, RHS > m_DisjointOr(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
CmpClass_match< LHS, RHS, ICmpInst, true > m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
ICmpLike_match< LHS, RHS > m_ICmpLike(CmpPredicate &Pred, const LHS &L, const RHS &R)
auto m_Value()
Match an arbitrary value and ignore it.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
match_bind< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
is_zero< true > m_Zero()
Match any null constant or a vector with all elements equal to 0.
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Add >, DisjointOr_match< LHS, RHS > > m_AddLike(const LHS &L, const RHS &R)
Match either "add" or "or disjoint".
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
Exact_match< T > m_Exact(const T &SubPattern)
LogicalOp_match< LHS, RHS, Instruction::And, true > m_c_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
bind_cst_ty m_scev_APInt(const APInt *&C)
Match an SCEV constant and bind it to an APInt.
specificloop_ty m_SpecificLoop(const Loop *L)
bool match(const SCEV *S, const Pattern &P)
SCEVAffineAddRec_match< Op0_t, Op1_t, match_isa< const Loop > > m_scev_AffineAddRec(const Op0_t &Op0, const Op1_t &Op1)
@ Switch
The "resume-switch" lowering, where there are separate resume and destroy functions that are shared b...
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< UseNode * > Use
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
void stable_sort(R &&Range)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
SaveAndRestore(T &) -> SaveAndRestore< T >
@ Known
Known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
constexpr std::enable_if_t< std::is_signed_v< T >, std::pair< T, bool > > AddOverflow(T X, T Y)
Add two signed integers, computing the two's complement truncated result, returning a pair {result,...
const ScalarOptions & getScalarOptions(const LLVMContext &C)
LLVM_ABI void remapInstructionsInBlocks(ArrayRef< BasicBlock * > Blocks, ValueToValueMapTy &VMap, AssumptionCache *AC=nullptr)
Remaps instructions in Blocks using the mapping in VMap.
LLVM_ABI std::optional< TypeSize > getBaseObjectSize(const Value *Ptr, const DataLayout &DL, const TargetLibraryInfo *TLI, ObjectSizeOpts Opts={})
Like getObjectSize(), but only returns the size of base objects (like allocas, global variables and a...
const Value * getPointerOperand(const Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
DomTreeNodeBase< BasicBlock > DomTreeNode
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
constexpr std::enable_if_t< std::is_signed_v< T >, std::pair< T, bool > > SubOverflow(T X, T Y)
Subtract two signed integers, computing the two's complement truncated result, returning a pair {resu...
constexpr unsigned MaxAnalysisRecursionDepth
LLVM_ABI bool isKnownPositive(const WithCache< const Value * > &V, const SimplifyQuery &SQ, unsigned Depth=0)
Returns true if the given value is known be positive (i.e.
@ Off
Use window algorithm after SMS algorithm fails.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ Sub
Subtraction of integers.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
constexpr std::enable_if_t< std::is_signed_v< T >, std::pair< T, bool > > MulOverflow(T X, T Y)
Multiply two signed integers, computing the two's complement truncated result, returning a pair {resu...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
LLVM_ABI bool isKnownNonNegative(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Returns true if the give value is known to be non-negative.
LLVM_ABI void findDbgUsers(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the debug info records describing a value.
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Various options to control the behavior of getObjectSize.
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated.
bool RoundToAlign
Whether to round the result up to the alignment of allocas, byval arguments, and global variables.
A MapVector that performs no allocations if smaller than a certain size.