51#define DEBUG_TYPE "correlated-value-propagation"
54STATISTIC(NumPhiCommon,
"Number of phis deleted via common incoming value");
55STATISTIC(NumSelects,
"Number of selects propagated");
56STATISTIC(NumCmps,
"Number of comparisons propagated");
57STATISTIC(NumReturns,
"Number of return values propagated");
58STATISTIC(NumDeadCases,
"Number of switch cases removed");
60 "Number of sdivs/srems whose width was decreased");
61STATISTIC(NumSDivs,
"Number of sdiv converted to udiv");
63 "Number of udivs/urems whose width was decreased");
64STATISTIC(NumAShrsConverted,
"Number of ashr converted to lshr");
65STATISTIC(NumAShrsRemoved,
"Number of ashr removed");
66STATISTIC(NumSRems,
"Number of srem converted to urem");
67STATISTIC(NumSExt,
"Number of sext converted to zext");
68STATISTIC(NumSIToFP,
"Number of sitofp converted to uitofp");
69STATISTIC(NumSICmps,
"Number of signed icmp preds simplified to unsigned");
72STATISTIC(NumNSW,
"Number of no-signed-wrap deductions");
73STATISTIC(NumNUW,
"Number of no-unsigned-wrap deductions");
74STATISTIC(NumAddNW,
"Number of no-wrap deductions for add");
75STATISTIC(NumAddNSW,
"Number of no-signed-wrap deductions for add");
76STATISTIC(NumAddNUW,
"Number of no-unsigned-wrap deductions for add");
77STATISTIC(NumSubNW,
"Number of no-wrap deductions for sub");
78STATISTIC(NumSubNSW,
"Number of no-signed-wrap deductions for sub");
79STATISTIC(NumSubNUW,
"Number of no-unsigned-wrap deductions for sub");
80STATISTIC(NumMulNW,
"Number of no-wrap deductions for mul");
81STATISTIC(NumMulNSW,
"Number of no-signed-wrap deductions for mul");
82STATISTIC(NumMulNUW,
"Number of no-unsigned-wrap deductions for mul");
83STATISTIC(NumShlNW,
"Number of no-wrap deductions for shl");
84STATISTIC(NumShlNSW,
"Number of no-signed-wrap deductions for shl");
85STATISTIC(NumShlNUW,
"Number of no-unsigned-wrap deductions for shl");
86STATISTIC(NumAbs,
"Number of llvm.abs intrinsics removed");
87STATISTIC(NumOverflows,
"Number of overflow checks removed");
89 "Number of saturating arithmetics converted to normal arithmetics");
90STATISTIC(NumNonNull,
"Number of function pointer arguments marked non-null");
91STATISTIC(NumCmpIntr,
"Number of llvm.[us]cmp intrinsics removed");
92STATISTIC(NumMinMax,
"Number of llvm.[us]{min,max} intrinsics removed");
94 "Number of llvm.s{min,max} intrinsics simplified to unsigned");
96 "Number of bound udiv's/urem's expanded");
97STATISTIC(NumNNeg,
"Number of zext/uitofp non-negative deductions");
107 std::optional<ConstantRange> RetRange;
112 :
F(
F), LVI(LVI), DT(DT), SQ(SQ) {}
118 bool processInstruction(Instruction &
I);
119 bool inferReturnRangeAttr();
122 bool processSelect(SelectInst *S);
123 bool processPHI(PHINode *
P);
124 bool processICmp(ICmpInst *Cmp);
125 bool processCmp(CmpInst *Cmp);
126 bool processSwitch(SwitchInst *
I);
127 bool processBinOp(BinaryOperator *BinOp);
128 bool processAbsIntrinsic(IntrinsicInst *
II);
129 bool processCmpIntrinsic(CmpIntrinsic *CI);
130 bool processMinMaxIntrinsic(MinMaxIntrinsic *MM);
131 bool processOverflowIntrinsic(WithOverflowInst *WO);
132 bool processSaturatingInst(SaturatingInst *SI);
133 bool processCallSite(CallBase &CB);
134 bool processUDivOrURem(BinaryOperator *Instr);
135 bool processSRem(BinaryOperator *SDI,
const ConstantRange &LCR,
136 const ConstantRange &RCR);
137 bool processSDiv(BinaryOperator *SDI,
const ConstantRange &LCR,
138 const ConstantRange &RCR);
139 bool processSDivOrSRem(BinaryOperator *Instr);
140 bool processAShr(BinaryOperator *SDI);
141 bool processSExt(SExtInst *SDI);
142 bool processPossibleNonNeg(PossiblyNonNegInst *
I);
143 bool processSIToFP(SIToFPInst *SIToFP);
144 bool processAnd(BinaryOperator *BinOp);
145 bool processTrunc(TruncInst *TI);
146 bool processReturn(ReturnInst *RI);
149 Constant *getConstantAt(
Value *
V, Instruction *At,
const Use *U =
nullptr);
150 bool simplifyCommonValuePhi(PHINode *
P);
151 bool constantFoldCmp(CmpInst *Cmp);
152 bool willNotOverflow(BinaryOpIntrinsic *BO);
153 Value *getValueOnEdge(
const Use &IncomingUse, BasicBlock *From,
154 BasicBlock *To, Instruction *CtxI);
155 NoWrapFlags inferNoWrapFromUses(BinaryOperator *BinOp,
bool WantNSW,
170 Value *Op0 =
C->getOperand(0);
179bool CVPImpl::processSelect(SelectInst *S) {
219bool CVPImpl::simplifyCommonValuePhi(PHINode *
P) {
222 Value *CommonValue =
nullptr;
223 for (
unsigned I = 0,
E =
P->getNumIncomingValues();
I !=
E; ++
I) {
224 Value *Incoming =
P->getIncomingValue(
I);
226 IncomingConstants.
push_back(std::make_pair(IncomingConstant,
I));
227 }
else if (!CommonValue) {
229 CommonValue = Incoming;
230 }
else if (Incoming != CommonValue) {
236 if (!CommonValue || IncomingConstants.
empty())
248 const DataLayout &
DL =
P->getDataLayout();
249 for (
auto &IncomingConstant : IncomingConstants) {
251 unsigned Idx = IncomingConstant.second;
255 IncomingBB, ToBB,
P);
273 P->replaceAllUsesWith(CommonValue);
279Value *CVPImpl::getValueOnEdge(
const Use &IncomingUse, BasicBlock *From,
280 BasicBlock *To, Instruction *CtxI) {
281 Value *Incoming = IncomingUse.
get();
296 Value *Condition =
SI->getCondition();
300 return SI->getTrueValue();
301 if (
C->isNullValue())
302 return SI->getFalseValue();
315 Res && Res->isZero())
316 return SI->getTrueValue();
323 Res && Res->isZero())
324 return SI->getFalseValue();
329bool CVPImpl::processPHI(PHINode *
P) {
333 for (
unsigned I = 0,
E =
P->getNumIncomingValues();
I <
E; ++
I) {
334 const Use &IncomingUse =
P->getOperandUse(
I);
338 Value *
V = getValueOnEdge(IncomingUse,
P->getIncomingBlock(
I), BB,
P);
340 P->setIncomingValue(
I,
V);
346 P->replaceAllUsesWith(
V);
347 P->eraseFromParent();
352 Changed = simplifyCommonValuePhi(
P);
360bool CVPImpl::processICmp(ICmpInst *Cmp) {
362 if (!
Cmp->getOperand(0)->getType()->isIntOrIntVectorTy())
365 if (!
Cmp->isSigned() && (!
Cmp->isUnsigned() ||
Cmp->hasSameSign()))
376 if (
Cmp->isSigned()) {
377 ICmpInst::Predicate UnsignedPred =
379 Cmp->getPredicate(), CR1, CR2);
381 if (UnsignedPred == ICmpInst::Predicate::BAD_ICMP_PREDICATE)
386 for (
auto *Record : DebugUsers)
387 Record->setKillLocation();
390 Cmp->setPredicate(UnsignedPred);
406bool CVPImpl::constantFoldCmp(CmpInst *Cmp) {
416 if (
Cmp->use_empty()) {
417 Cmp->eraseFromParent();
427bool CVPImpl::processCmp(CmpInst *Cmp) {
428 if (constantFoldCmp(Cmp))
432 if (processICmp(ICmp))
445bool CVPImpl::processSwitch(SwitchInst *
I) {
446 DomTreeUpdater DTU(*DT, DomTreeUpdater::UpdateStrategy::Lazy);
452 DenseMap<BasicBlock*, int> SuccessorsCount;
454 SuccessorsCount[Succ]++;
458 SwitchInstProfUpdateWrapper
SI(*
I);
461 unsigned ReachableCaseCount = 0;
463 for (
auto CI =
SI->case_begin(), CE =
SI->case_end(); CI != CE;) {
464 ConstantInt *Case = CI->getCaseValue();
465 std::optional<bool>
Predicate = std::nullopt;
476 if (Res && Res->isZero())
478 else if (Res && Res->isOne())
482 if (Predicate && !*Predicate) {
486 CI =
SI.removeCase(CI);
491 Cond =
SI->getCondition();
495 if (--SuccessorsCount[Succ] == 0)
496 DTU.applyUpdatesPermissive({{DominatorTree::Delete, BB, Succ}});
499 if (Predicate && *Predicate) {
503 SI->setCondition(Case);
504 NumDeadCases +=
SI->getNumCases();
511 ++ReachableCaseCount;
515 if (!
SI->defaultDestUnreachable() &&
521 auto *UI =
new UnreachableInst(BB->
getContext(), NewUnreachableBB);
525 SI->setDefaultDest(NewUnreachableBB);
527 if (SuccessorsCount[DefaultDest] == 1)
528 DTU.applyUpdates({{DominatorTree::Delete, BB, DefaultDest}});
529 DTU.applyUpdates({{DominatorTree::Insert, BB, NewUnreachableBB}});
545bool CVPImpl::willNotOverflow(BinaryOpIntrinsic *BO) {
546 ConstantRange LRange =
548 ConstantRange RRange =
556 bool NewNSW,
bool NewNUW) {
559 case Instruction::Add:
564 case Instruction::Sub:
569 case Instruction::Mul:
574 case Instruction::Shl:
590 Inst->setHasNoSignedWrap();
598 Inst->setHasNoUnsignedWrap();
605bool CVPImpl::processAbsIntrinsic(IntrinsicInst *
II) {
610 II->getOperandUse(0), IsIntMinPoison);
615 II->replaceAllUsesWith(
X);
616 II->eraseFromParent();
623 Value *NegX =
B.CreateNeg(
X,
II->getName(),
626 II->replaceAllUsesWith(NegX);
627 II->eraseFromParent();
647bool CVPImpl::processCmpIntrinsic(CmpIntrinsic *CI) {
648 ConstantRange LRange =
650 ConstantRange RRange =
665 if (LRange.
icmp(ICmpInst::ICMP_EQ, RRange)) {
677bool CVPImpl::processMinMaxIntrinsic(MinMaxIntrinsic *MM) {
702 auto TryFoldWithFreeze = [&](
unsigned OpIdx,
703 const ConstantRange &OtherRange) {
706 false,
nullptr,
true);
707 if (!FrozenRange.
icmp(
Pred, OtherRange))
710 auto *FI =
new FreezeInst(
Op,
Op->getName() +
".fr", MM->
getIterator());
712 FI->eraseFromParent();
720 if (TryFoldWithFreeze(0, RRange) || TryFoldWithFreeze(1, LRange))
741bool CVPImpl::processOverflowIntrinsic(WithOverflowInst *WO) {
755 Value *NewI =
B.CreateInsertValue(Struct, NewOp, 0);
767bool CVPImpl::processSaturatingInst(SaturatingInst *SI) {
769 bool NSW =
SI->isSigned();
770 bool NUW = !
SI->isSigned();
772 Opcode,
SI->getLHS(),
SI->getRHS(),
SI->getName(),
SI->getIterator());
777 SI->replaceAllUsesWith(BinOp);
778 SI->eraseFromParent();
788bool CVPImpl::processCallSite(CallBase &CB) {
795 return processCmpIntrinsic(CI);
799 return processMinMaxIntrinsic(MM);
803 if (willNotOverflow(WO))
804 return processOverflowIntrinsic(WO);
808 if (willNotOverflow(SI))
809 return processSaturatingInst(SI);
822 for (
const Use &ConstU : DeoptBundle->Inputs) {
823 Use &
U =
const_cast<Use&
>(ConstU);
825 if (
V->getType()->isVectorTy())
continue;
835 SmallVector<unsigned, 4> ArgNos;
848 Res && Res->isZero())
853 assert(ArgNo == CB.
arg_size() &&
"Call arguments not processed correctly.");
858 NumNonNull += ArgNos.
size();
861 AS = AS.addParamAttribute(Ctx, ArgNos,
862 Attribute::get(Ctx, Attribute::NonNull));
882 assert(Instr->getOpcode() == Instruction::SDiv ||
883 Instr->getOpcode() == Instruction::SRem);
887 unsigned OrigWidth = Instr->getType()->getScalarSizeInBits();
891 unsigned MinSignedBits =
901 unsigned NewWidth = std::max<unsigned>(
PowerOf2Ceil(MinSignedBits), 8);
905 if (NewWidth >= OrigWidth)
908 ++NumSDivSRemsNarrowed;
910 auto *TruncTy = Instr->getType()->getWithNewBitWidth(NewWidth);
911 auto *
LHS =
B.CreateTruncOrBitCast(Instr->getOperand(0), TruncTy,
912 Instr->getName() +
".lhs.trunc");
913 auto *
RHS =
B.CreateTruncOrBitCast(Instr->getOperand(1), TruncTy,
914 Instr->getName() +
".rhs.trunc");
915 auto *BO =
B.CreateBinOp(Instr->getOpcode(),
LHS,
RHS, Instr->getName());
916 auto *Sext =
B.CreateSExt(BO, Instr->getType(), Instr->getName() +
".sext");
918 if (BinOp->
getOpcode() == Instruction::SDiv)
921 Instr->replaceAllUsesWith(Sext);
922 Instr->eraseFromParent();
928 Type *Ty = Instr->getType();
929 assert(Instr->getOpcode() == Instruction::UDiv ||
930 Instr->getOpcode() == Instruction::URem);
931 bool IsRem = Instr->getOpcode() == Instruction::URem;
933 Value *
X = Instr->getOperand(0);
934 Value *
Y = Instr->getOperand(1);
941 Instr->eraseFromParent();
942 ++NumUDivURemsNarrowedExpanded;
978 ExpandedOp =
B.CreateNUWSub(
X,
Y);
980 ExpandedOp = ConstantInt::get(Instr->getType(), 1);
986 FrozenX =
B.CreateFreeze(
X,
X->getName() +
".frozen");
989 FrozenY =
B.CreateFreeze(
Y,
Y->getName() +
".frozen");
990 auto *AdjX =
B.CreateNUWSub(FrozenX, FrozenY, Instr->getName() +
".urem");
992 Instr->getName() +
".cmp");
994 B.CreateSelectWithUnknownProfile(Cmp, FrozenX, AdjX,
DEBUG_TYPE);
998 ExpandedOp =
B.CreateZExt(Cmp, Ty, Instr->getName() +
".udiv");
1001 Instr->replaceAllUsesWith(ExpandedOp);
1002 Instr->eraseFromParent();
1003 ++NumUDivURemsNarrowedExpanded;
1011 assert(Instr->getOpcode() == Instruction::UDiv ||
1012 Instr->getOpcode() == Instruction::URem);
1021 unsigned NewWidth = std::max<unsigned>(
PowerOf2Ceil(MaxActiveBits), 8);
1025 if (NewWidth >= Instr->getType()->getScalarSizeInBits())
1028 ++NumUDivURemsNarrowed;
1030 auto *TruncTy = Instr->getType()->getWithNewBitWidth(NewWidth);
1031 auto *
LHS =
B.CreateTruncOrBitCast(Instr->getOperand(0), TruncTy,
1032 Instr->getName() +
".lhs.trunc");
1033 auto *
RHS =
B.CreateTruncOrBitCast(Instr->getOperand(1), TruncTy,
1034 Instr->getName() +
".rhs.trunc");
1035 auto *BO =
B.CreateBinOp(Instr->getOpcode(),
LHS,
RHS, Instr->getName());
1036 auto *Zext =
B.CreateZExt(BO, Instr->getType(), Instr->getName() +
".zext");
1038 if (BinOp->
getOpcode() == Instruction::UDiv)
1041 Instr->replaceAllUsesWith(Zext);
1042 Instr->eraseFromParent();
1046bool CVPImpl::processUDivOrURem(BinaryOperator *Instr) {
1048 Instr->getOpcode() == Instruction::URem);
1060bool CVPImpl::processSRem(BinaryOperator *SDI,
const ConstantRange &LCR,
1061 const ConstantRange &RCR) {
1084 for (Operand &
Op :
Ops) {
1093 auto *URem = BinaryOperator::CreateURem(
Ops[0].
V,
Ops[1].
V, SDI->
getName(),
1111 processUDivOrURem(URem);
1121bool CVPImpl::processSDiv(BinaryOperator *SDI,
const ConstantRange &LCR,
1122 const ConstantRange &RCR) {
1126 ConstantRange DivCR = LCR.
sdiv(RCR);
1147 for (Operand &
Op :
Ops) {
1156 auto *UDiv = BinaryOperator::CreateUDiv(
Ops[0].
V,
Ops[1].
V, SDI->
getName(),
1159 UDiv->setIsExact(SDI->
isExact());
1175 processUDivOrURem(UDiv);
1180bool CVPImpl::processSDivOrSRem(BinaryOperator *Instr) {
1182 Instr->getOpcode() == Instruction::SRem);
1188 if (
Instr->getOpcode() == Instruction::SDiv)
1189 if (processSDiv(Instr, LCR, RCR))
1192 if (
Instr->getOpcode() == Instruction::SRem) {
1193 if (processSRem(Instr, LCR, RCR))
1200bool CVPImpl::processAShr(BinaryOperator *SDI) {
1201 ConstantRange LRange =
1204 ConstantRange NegOneOrZero =
1205 ConstantRange(APInt(OrigWidth, (
uint64_t)-1,
true), APInt(OrigWidth, 1));
1206 if (NegOneOrZero.
contains(LRange)) {
1218 ++NumAShrsConverted;
1231bool CVPImpl::processSExt(SExtInst *SDI) {
1240 ZExt->takeName(SDI);
1250bool CVPImpl::processPossibleNonNeg(PossiblyNonNegInst *
I) {
1254 const Use &
Base =
I->getOperandUse(0);
1265bool CVPImpl::processSIToFP(SIToFPInst *SIToFP) {
1274 UIToFP->takeName(SIToFP);
1276 UIToFP->setNonNeg();
1296 bool CheckNSW,
bool CheckNUW) {
1301 OBO::NoUnsignedWrap)
1313NoWrapFlags CVPImpl::inferNoWrapFromUses(BinaryOperator *BinOp,
bool WantNSW,
1317 const unsigned MaxUsesToInspect = 4;
1319 unsigned NumUses = 0;
1320 for (Use &U : BinOp->
uses()) {
1321 if (++NumUses > MaxUsesToInspect)
1324 if (
isa<PHINode>(UserI) || UserI->getParent() == DefBB)
1332 Flags.NSW = WantNSW;
1333 Flags.NUW = WantNUW;
1334 for (Use &U : BinOp->
uses()) {
1349bool CVPImpl::processBinOp(BinaryOperator *BinOp) {
1368 bool WantNSW = !NSW && !
New.NSW;
1369 bool WantNUW = !NUW && !
New.NUW;
1370 if (WantNSW || WantNUW) {
1371 NoWrapFlags FromUses = inferNoWrapFromUses(BinOp, WantNSW, WantNUW);
1372 New.NSW |= FromUses.NSW;
1373 New.NUW |= FromUses.NUW;
1378 return New.NSW ||
New.NUW;
1381bool CVPImpl::processAnd(BinaryOperator *BinOp) {
1382 using namespace llvm::PatternMatch;
1393 ConstantRange LRange =
1405bool CVPImpl::processTrunc(TruncInst *TI) {
1409 ConstantRange
Range =
1433bool CVPImpl::processReturn(ReturnInst *RI) {
1440 if (RetRange && !RetRange->isFullSet())
1441 RetRange = RetRange->unionWith(
1446 if (Constant *
C = getConstantAt(RetVal, RI, &RI->
getOperandUse(0))) {
1454bool CVPImpl::processInstruction(Instruction &
I) {
1455 switch (
I.getOpcode()) {
1456 case Instruction::Select:
1458 case Instruction::PHI:
1460 case Instruction::ICmp:
1461 case Instruction::FCmp:
1463 case Instruction::Call:
1464 case Instruction::Invoke:
1466 case Instruction::SRem:
1467 case Instruction::SDiv:
1469 case Instruction::UDiv:
1470 case Instruction::URem:
1472 case Instruction::AShr:
1474 case Instruction::SExt:
1476 case Instruction::ZExt:
1477 case Instruction::UIToFP:
1479 case Instruction::SIToFP:
1481 case Instruction::Add:
1482 case Instruction::Sub:
1483 case Instruction::Mul:
1484 case Instruction::Shl:
1486 case Instruction::And:
1488 case Instruction::Trunc:
1490 case Instruction::Switch:
1492 case Instruction::Ret:
1499bool CVPImpl::inferReturnRangeAttr() {
1501 if (!RetRange || RetRange->isFullSet())
1503 Attribute RangeAttr =
F.getRetAttribute(Attribute::Range);
1505 RetRange = RetRange->intersectWith(RangeAttr.
getRange());
1508 if (RetRange->isEmptySet() || RetRange->isSingleElement())
1510 F.addRangeRetAttr(*RetRange);
1514bool CVPImpl::run() {
1515 if (
F.hasExactDefinition() &&
F.getReturnType()->isIntOrIntVectorTy())
1517 ConstantRange::getEmpty(
F.getReturnType()->getScalarSizeInBits());
1529 Changed |= inferReturnRangeAttr();
1545#if defined(EXPENSIVE_CHECKS)
1546 assert(DT->verify(DominatorTree::VerificationLevel::Full));
1548 assert(DT->verify(DominatorTree::VerificationLevel::Fast));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
This is the interface for a simple mod/ref and alias analysis over globals.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This header defines various interfaces for pass management in LLVM.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
SmallVector< MachineOperand, 4 > Cond
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)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
bool isNonPositive() const
Determine if this APInt Value is non-positive (<= 0).
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM_ABI const ConstantRange & getRange() const
Returns the value of the range attribute.
bool isValid() const
Return true if the attribute is any kind of attribute.
const Function * getParent() const
Return the enclosing method, or null if none.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVM_ABI void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
LLVM_ABI unsigned getNoWrapKind() const
Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
LLVM_ABI bool isSigned() const
Whether the intrinsic is signed or unsigned.
LLVM_ABI Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
static LLVM_ABI BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
BinaryOps getOpcode() const
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
void setAttributes(AttributeList A)
Set the attributes for this call.
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
static LLVM_ABI CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Type * getDestTy() const
Return the destination type, as a convenience.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLE
signed less or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_ULT
unsigned less than
@ ICMP_ULE
unsigned less or equal
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
static CmpInst::Predicate getGTPredicate(Intrinsic::ID ID)
static CmpInst::Predicate getLTPredicate(Intrinsic::ID ID)
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
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)
const APInt & getValue() const
Return the constant as an APInt value reference.
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This class represents a range of values.
LLVM_ABI unsigned getActiveBits() const
Compute the maximal number of active bits needed to represent every value in this range.
static LLVM_ABI CmpInst::Predicate getEquivalentPredWithFlippedSignedness(CmpInst::Predicate Pred, const ConstantRange &CR1, const ConstantRange &CR2)
If the comparison between constant ranges this and Other is insensitive to the signedness of the comp...
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
LLVM_ABI bool isAllNegative() const
Return true if all values in this range are negative.
LLVM_ABI bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const
Does the predicate Pred hold between ranges this and Other?
LLVM_ABI bool isSizeLargerThan(uint64_t MaxSize) const
Compare set size of this range with Value.
LLVM_ABI ConstantRange abs(bool IntMinIsPoison=false) const
Calculate absolute value range.
LLVM_ABI ConstantRange uadd_sat(const ConstantRange &Other) const
Perform an unsigned saturating addition of two constant ranges.
bool isSingleElement() const
Return true if this set contains exactly one member.
LLVM_ABI bool isAllNonNegative() const
Return true if all values in this range are non-negative.
LLVM_ABI ConstantRange sdiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed division of a value in th...
LLVM_ABI bool contains(const APInt &Val) const
Return true if the specified value is in the set.
LLVM_ABI APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
LLVM_ABI APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
static LLVM_ABI bool areInsensitiveToSignednessOfICmpPredicate(const ConstantRange &CR1, const ConstantRange &CR2)
Return true iff CR1 ult CR2 is equivalent to CR1 slt CR2.
static LLVM_ABI ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind)
Produce the largest range containing all X such that "X BinOp Y" is guaranteed not to wrap (overflow)...
LLVM_ABI unsigned getMinSignedBits() const
Compute the maximal number of bits needed to represent every value in this signed range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
LLVM_ABI bool isOneValue() const
Returns true if the value is one.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static DebugLoc getTemporary()
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
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.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
LLVM_ABI bool hasNoSignedWrap() const LLVM_READONLY
Determine whether the no signed wrap flag is set.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI bool isExact() const LLVM_READONLY
Determine whether the exact flag is set.
LLVM_ABI void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Analysis to compute lazy value information.
This pass computes, caches, and vends lazy value constraint information.
LLVM_ABI ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed, SmallVectorImpl< DbgVariableRecord * > *DebugUsers=nullptr, bool AssumeFrozen=false)
Return the ConstantRange constraint that is known to hold for the value at a specific use-site.
LLVM_ABI Constant * getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr, const Use *U=nullptr)
Determine whether the specified value is known to be a constant on the specified edge.
LLVM_ABI Constant * getConstant(Value *V, Instruction *CtxI, const Use *U=nullptr)
Determine whether the specified value is known to be a constant at the specified instruction.
LLVM_ABI Constant * getPredicateAt(CmpInst::Predicate Pred, Value *V, Constant *C, Instruction *CtxI, bool UseBlockValue)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
LLVM_ABI ConstantRange getConstantRange(Value *V, Instruction *CtxI, bool UndefAllowed)
Return the ConstantRange constraint that is known to hold for the specified value at the specified in...
LLVM_ABI Constant * getPredicateOnEdge(CmpInst::Predicate Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr)
Determine whether the specified value comparison with a constant is known to be true or false on the ...
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
static ICmpInst::Predicate getPredicate(Intrinsic::ID ID)
Returns the comparison predicate underlying the intrinsic.
static bool isSigned(Intrinsic::ID ID)
Whether the intrinsic is signed or unsigned.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
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 & abandon()
Mark an analysis as abandoned.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
const Value * getFalseValue() const
const Value * getCondition() const
const Value * getTrueValue() const
void push_back(const T &Elt)
void setHasNoSignedWrap(bool B)
void setHasNoUnsignedWrap(bool B)
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property.
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
A Use represents the edge between a Value definition and its users.
const Use & getOperandUse(unsigned i) const
LLVM_ABI bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Value * getOperand(unsigned i) const
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.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BasicBlock
Various leaf nodes.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
bool match(Val *V, const Pattern &P)
@ CE
Windows NT (Windows on ARM)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
NodeAddr< InstrNode * > Instr
NodeAddr< UseNode * > Use
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DomTreeUpdater *DTU=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
@ Unknown
Not known to have no common set bits.
LLVM_ABI bool freezeUsesAfterDef(FreezeInst &FI, DominatorTree &DT, SmallVectorImpl< User * > *Users=nullptr)
Move FI right after the definition of its operand, and replace the uses of the operand that it domina...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
auto successors(const MachineBasicBlock *BB)
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 bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI bool canReplacePointersInUseIfEqual(const Use &U, const Value *To, const DataLayout &DL)
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
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...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
iterator_range< df_iterator< T > > depth_first(const T &G)
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 const SimplifyQuery getBestSimplifyQuery(Pass &, Function &)