48#define DEBUG_TYPE "correlated-value-propagation"
51STATISTIC(NumPhiCommon,
"Number of phis deleted via common incoming value");
52STATISTIC(NumSelects,
"Number of selects propagated");
53STATISTIC(NumCmps,
"Number of comparisons propagated");
54STATISTIC(NumReturns,
"Number of return values propagated");
55STATISTIC(NumDeadCases,
"Number of switch cases removed");
57 "Number of sdivs/srems whose width was decreased");
58STATISTIC(NumSDivs,
"Number of sdiv converted to udiv");
60 "Number of udivs/urems whose width was decreased");
61STATISTIC(NumAShrsConverted,
"Number of ashr converted to lshr");
62STATISTIC(NumAShrsRemoved,
"Number of ashr removed");
63STATISTIC(NumSRems,
"Number of srem converted to urem");
64STATISTIC(NumSExt,
"Number of sext converted to zext");
65STATISTIC(NumSIToFP,
"Number of sitofp converted to uitofp");
66STATISTIC(NumSICmps,
"Number of signed icmp preds simplified to unsigned");
69STATISTIC(NumNSW,
"Number of no-signed-wrap deductions");
70STATISTIC(NumNUW,
"Number of no-unsigned-wrap deductions");
71STATISTIC(NumAddNW,
"Number of no-wrap deductions for add");
72STATISTIC(NumAddNSW,
"Number of no-signed-wrap deductions for add");
73STATISTIC(NumAddNUW,
"Number of no-unsigned-wrap deductions for add");
74STATISTIC(NumSubNW,
"Number of no-wrap deductions for sub");
75STATISTIC(NumSubNSW,
"Number of no-signed-wrap deductions for sub");
76STATISTIC(NumSubNUW,
"Number of no-unsigned-wrap deductions for sub");
77STATISTIC(NumMulNW,
"Number of no-wrap deductions for mul");
78STATISTIC(NumMulNSW,
"Number of no-signed-wrap deductions for mul");
79STATISTIC(NumMulNUW,
"Number of no-unsigned-wrap deductions for mul");
80STATISTIC(NumShlNW,
"Number of no-wrap deductions for shl");
81STATISTIC(NumShlNSW,
"Number of no-signed-wrap deductions for shl");
82STATISTIC(NumShlNUW,
"Number of no-unsigned-wrap deductions for shl");
83STATISTIC(NumAbs,
"Number of llvm.abs intrinsics removed");
84STATISTIC(NumOverflows,
"Number of overflow checks removed");
86 "Number of saturating arithmetics converted to normal arithmetics");
87STATISTIC(NumNonNull,
"Number of function pointer arguments marked non-null");
88STATISTIC(NumCmpIntr,
"Number of llvm.[us]cmp intrinsics removed");
89STATISTIC(NumMinMax,
"Number of llvm.[us]{min,max} intrinsics removed");
91 "Number of llvm.s{min,max} intrinsics simplified to unsigned");
93 "Number of bound udiv's/urem's expanded");
94STATISTIC(NumNNeg,
"Number of zext/uitofp non-negative deductions");
102 auto *
C = dyn_cast<CmpInst>(V);
106 Value *Op0 =
C->getOperand(0);
107 Constant *Op1 = dyn_cast<Constant>(
C->getOperand(1));
119 bool Changed =
false;
121 auto *
I = cast<Instruction>(U.getUser());
123 if (
auto *PN = dyn_cast<PHINode>(
I))
129 auto *CI = dyn_cast_or_null<ConstantInt>(
C);
159 Value *CommonValue =
nullptr;
160 for (
unsigned i = 0, e =
P->getNumIncomingValues(); i != e; ++i) {
162 if (
auto *IncomingConstant = dyn_cast<Constant>(
Incoming)) {
163 IncomingConstants.
push_back(std::make_pair(IncomingConstant, i));
164 }
else if (!CommonValue) {
167 }
else if (
Incoming != CommonValue) {
173 if (!CommonValue || IncomingConstants.
empty())
178 if (
auto *CommonInst = dyn_cast<Instruction>(CommonValue))
185 for (
auto &IncomingConstant : IncomingConstants) {
187 BasicBlock *IncomingBB =
P->getIncomingBlock(IncomingConstant.second);
200 P->replaceAllUsesWith(CommonValue);
201 P->eraseFromParent();
216 auto *SI = dyn_cast<SelectInst>(
Incoming);
222 Value *Condition = SI->getCondition();
226 return SI->getTrueValue();
227 if (
C->isZeroValue())
228 return SI->getFalseValue();
238 if (
auto *
C = dyn_cast<Constant>(SI->getFalseValue()))
239 if (
auto *Res = dyn_cast_or_null<ConstantInt>(
241 Res && Res->isZero())
242 return SI->getTrueValue();
246 if (
auto *
C = dyn_cast<Constant>(SI->getTrueValue()))
247 if (
auto *Res = dyn_cast_or_null<ConstantInt>(
249 Res && Res->isZero())
250 return SI->getFalseValue();
257 bool Changed =
false;
260 for (
unsigned i = 0, e =
P->getNumIncomingValues(); i < e; ++i) {
262 if (isa<Constant>(
Incoming))
continue;
266 P->setIncomingValue(i, V);
272 P->replaceAllUsesWith(V);
273 P->eraseFromParent();
288 if (!Cmp->getOperand(0)->getType()->isIntOrIntVectorTy())
291 if (!Cmp->isSigned() && (!Cmp->isUnsigned() || Cmp->hasSameSign()))
294 bool Changed =
false;
301 if (Cmp->isSigned()) {
304 Cmp->getPredicate(), CR1, CR2);
306 if (UnsignedPred == ICmpInst::Predicate::BAD_ICMP_PREDICATE)
310 Cmp->setPredicate(UnsignedPred);
327 Value *Op0 = Cmp->getOperand(0);
328 Value *Op1 = Cmp->getOperand(1);
335 Cmp->replaceAllUsesWith(Res);
336 Cmp->eraseFromParent();
344 if (
auto *ICmp = dyn_cast<ICmpInst>(Cmp))
365 bool Changed =
false;
368 SuccessorsCount[Succ]++;
373 unsigned ReachableCaseCount = 0;
375 for (
auto CI = SI->case_begin(), CE = SI->case_end(); CI != CE;) {
377 auto *Res = dyn_cast_or_null<ConstantInt>(
381 if (Res && Res->isZero()) {
385 CI = SI.removeCase(CI);
390 Cond = SI->getCondition();
394 if (--SuccessorsCount[Succ] == 0)
398 if (Res && Res->isOne()) {
402 SI->setCondition(Case);
403 NumDeadCases += SI->getNumCases();
410 ++ReachableCaseCount;
413 BasicBlock *DefaultDest = SI->getDefaultDest();
414 if (ReachableCaseCount > 1 &&
426 SI->setDefaultDest(NewUnreachableBB);
428 if (SuccessorsCount[DefaultDest] == 1)
429 DTU.
applyUpdates({{DominatorTree::Delete, BB, DefaultDest}});
430 DTU.
applyUpdates({{DominatorTree::Insert, BB, NewUnreachableBB}});
458 bool NewNSW,
bool NewNUW) {
461 case Instruction::Add:
466 case Instruction::Sub:
471 case Instruction::Mul:
476 case Instruction::Shl:
485 auto *Inst = dyn_cast<Instruction>(V);
492 Inst->setHasNoSignedWrap();
500 Inst->setHasNoUnsignedWrap();
511 bool IsIntMinPoison = cast<ConstantInt>(
II->getArgOperand(1))->isOne();
514 II->getOperandUse(0), IsIntMinPoison);
519 II->replaceAllUsesWith(
X);
520 II->eraseFromParent();
527 Value *NegX =
B.CreateNeg(
X,
II->getName(),
530 II->replaceAllUsesWith(NegX);
531 II->eraseFromParent();
534 if (
auto *BO = dyn_cast<BinaryOperator>(NegX))
569 if (LHS_CR.
icmp(ICmpInst::ICMP_EQ, RHS_CR)) {
587 if (LHS_CR.
icmp(Pred, RHS_CR)) {
593 if (RHS_CR.
icmp(Pred, LHS_CR)) {
637 if (
auto *BO = dyn_cast<BinaryOperator>(NewOp))
645 bool NSW = SI->isSigned();
646 bool NUW = !SI->isSigned();
648 Opcode, SI->getLHS(), SI->getRHS(), SI->getName(), SI->getIterator());
652 SI->replaceAllUsesWith(BinOp);
653 SI->eraseFromParent();
657 if (
auto *BO = dyn_cast<BinaryOperator>(BinOp))
670 if (
auto *CI = dyn_cast<CmpIntrinsic>(&CB)) {
674 if (
auto *MM = dyn_cast<MinMaxIntrinsic>(&CB)) {
678 if (
auto *WO = dyn_cast<WithOverflowInst>(&CB)) {
683 if (
auto *SI = dyn_cast<SaturatingInst>(&CB)) {
688 bool Changed =
false;
698 for (
const Use &ConstU : DeoptBundle->Inputs) {
699 Use &U =
const_cast<Use&
>(ConstU);
701 if (V->getType()->isVectorTy())
continue;
702 if (isa<Constant>(V))
continue;
721 if (
auto *Res = dyn_cast_or_null<ConstantInt>(LVI->
getPredicateAt(
724 Res && Res->isZero())
729 assert(ArgNo == CB.
arg_size() &&
"Call arguments not processed correctly.");
734 NumNonNull += ArgNos.
size();
758 assert(Instr->getOpcode() == Instruction::SDiv ||
759 Instr->getOpcode() == Instruction::SRem);
763 unsigned OrigWidth = Instr->getType()->getScalarSizeInBits();
767 unsigned MinSignedBits =
777 unsigned NewWidth = std::max<unsigned>(
PowerOf2Ceil(MinSignedBits), 8);
781 if (NewWidth >= OrigWidth)
784 ++NumSDivSRemsNarrowed;
786 auto *TruncTy = Instr->getType()->getWithNewBitWidth(NewWidth);
787 auto *
LHS =
B.CreateTruncOrBitCast(Instr->getOperand(0), TruncTy,
788 Instr->getName() +
".lhs.trunc");
789 auto *
RHS =
B.CreateTruncOrBitCast(Instr->getOperand(1), TruncTy,
790 Instr->getName() +
".rhs.trunc");
791 auto *BO =
B.CreateBinOp(Instr->getOpcode(),
LHS,
RHS, Instr->getName());
792 auto *Sext =
B.CreateSExt(BO, Instr->getType(), Instr->getName() +
".sext");
793 if (
auto *BinOp = dyn_cast<BinaryOperator>(BO))
794 if (BinOp->getOpcode() == Instruction::SDiv)
795 BinOp->setIsExact(Instr->isExact());
797 Instr->replaceAllUsesWith(Sext);
798 Instr->eraseFromParent();
804 Type *Ty = Instr->getType();
805 assert(Instr->getOpcode() == Instruction::UDiv ||
806 Instr->getOpcode() == Instruction::URem);
807 bool IsRem = Instr->getOpcode() == Instruction::URem;
809 Value *
X = Instr->getOperand(0);
810 Value *
Y = Instr->getOperand(1);
814 if (XCR.
icmp(ICmpInst::ICMP_ULT, YCR)) {
816 Instr->eraseFromParent();
817 ++NumUDivURemsNarrowedExpanded;
850 if (XCR.
icmp(ICmpInst::ICMP_UGE, YCR)) {
853 ExpandedOp =
B.CreateNUWSub(
X,
Y);
855 ExpandedOp = ConstantInt::get(Instr->getType(), 1);
861 FrozenX =
B.CreateFreeze(
X,
X->getName() +
".frozen");
864 FrozenY =
B.CreateFreeze(
Y,
Y->getName() +
".frozen");
865 auto *AdjX =
B.CreateNUWSub(FrozenX, FrozenY, Instr->getName() +
".urem");
866 auto *Cmp =
B.CreateICmp(ICmpInst::ICMP_ULT, FrozenX, FrozenY,
867 Instr->getName() +
".cmp");
868 ExpandedOp =
B.CreateSelect(Cmp, FrozenX, AdjX);
871 B.CreateICmp(ICmpInst::ICMP_UGE,
X,
Y, Instr->getName() +
".cmp");
872 ExpandedOp =
B.CreateZExt(Cmp, Ty, Instr->getName() +
".udiv");
875 Instr->replaceAllUsesWith(ExpandedOp);
876 Instr->eraseFromParent();
877 ++NumUDivURemsNarrowedExpanded;
885 assert(Instr->getOpcode() == Instruction::UDiv ||
886 Instr->getOpcode() == Instruction::URem);
895 unsigned NewWidth = std::max<unsigned>(
PowerOf2Ceil(MaxActiveBits), 8);
899 if (NewWidth >= Instr->getType()->getScalarSizeInBits())
902 ++NumUDivURemsNarrowed;
904 auto *TruncTy = Instr->getType()->getWithNewBitWidth(NewWidth);
905 auto *
LHS =
B.CreateTruncOrBitCast(Instr->getOperand(0), TruncTy,
906 Instr->getName() +
".lhs.trunc");
907 auto *
RHS =
B.CreateTruncOrBitCast(Instr->getOperand(1), TruncTy,
908 Instr->getName() +
".rhs.trunc");
909 auto *BO =
B.CreateBinOp(Instr->getOpcode(),
LHS,
RHS, Instr->getName());
910 auto *Zext =
B.CreateZExt(BO, Instr->getType(), Instr->getName() +
".zext");
911 if (
auto *BinOp = dyn_cast<BinaryOperator>(BO))
912 if (BinOp->getOpcode() == Instruction::UDiv)
913 BinOp->setIsExact(Instr->isExact());
915 Instr->replaceAllUsesWith(Zext);
916 Instr->eraseFromParent();
921 assert(Instr->getOpcode() == Instruction::UDiv ||
922 Instr->getOpcode() == Instruction::URem);
957 for (Operand &
Op : Ops) {
966 auto *URem = BinaryOperator::CreateURem(Ops[0].V, Ops[1].V, SDI->
getName(),
1018 for (Operand &
Op : Ops) {
1027 auto *UDiv = BinaryOperator::CreateUDiv(Ops[0].V, Ops[1].V, SDI->
getName(),
1030 UDiv->setIsExact(SDI->
isExact());
1035 if (Ops[0].
D != Ops[1].
D) {
1051 assert(Instr->getOpcode() == Instruction::SDiv ||
1052 Instr->getOpcode() == Instruction::SRem);
1058 if (Instr->getOpcode() == Instruction::SDiv)
1062 if (Instr->getOpcode() == Instruction::SRem) {
1076 if (NegOneOrZero.
contains(LRange)) {
1087 ++NumAShrsConverted;
1092 BO->setIsExact(SDI->
isExact());
1108 ZExt->takeName(SDI);
1121 const Use &
Base =
I->getOperandUse(0);
1149 UIToFP->takeName(SIToFP);
1151 UIToFP->setNonNeg();
1172 bool Changed =
false;
1173 bool NewNUW =
false, NewNSW =
false;
1176 Opcode, RRange, OBO::NoUnsignedWrap);
1177 NewNUW = NUWRange.
contains(LRange);
1182 Opcode, RRange, OBO::NoSignedWrap);
1183 NewNSW = NSWRange.
contains(LRange);
1217 bool FnChanged =
false;
1218 std::optional<ConstantRange> RetRange;
1219 if (
F.hasExactDefinition() &&
F.getReturnType()->isIntOrIntVectorTy())
1221 ConstantRange::getEmpty(
F.getReturnType()->getScalarSizeInBits());
1229 bool BBChanged =
false;
1231 switch (
II.getOpcode()) {
1232 case Instruction::Select:
1235 case Instruction::PHI:
1236 BBChanged |=
processPHI(cast<PHINode>(&
II), LVI, DT, SQ);
1238 case Instruction::ICmp:
1239 case Instruction::FCmp:
1242 case Instruction::Call:
1243 case Instruction::Invoke:
1246 case Instruction::SRem:
1247 case Instruction::SDiv:
1250 case Instruction::UDiv:
1251 case Instruction::URem:
1254 case Instruction::AShr:
1257 case Instruction::SExt:
1260 case Instruction::ZExt:
1263 case Instruction::UIToFP:
1266 case Instruction::SIToFP:
1269 case Instruction::Add:
1270 case Instruction::Sub:
1271 case Instruction::Mul:
1272 case Instruction::Shl:
1275 case Instruction::And:
1276 BBChanged |=
processAnd(cast<BinaryOperator>(&
II), LVI);
1282 switch (Term->getOpcode()) {
1283 case Instruction::Switch:
1284 BBChanged |=
processSwitch(cast<SwitchInst>(Term), LVI, DT);
1286 case Instruction::Ret: {
1287 auto *RI = cast<ReturnInst>(Term);
1291 auto *RetVal = RI->getReturnValue();
1293 if (RetRange && !RetRange->isFullSet())
1298 if (isa<Constant>(RetVal))
break;
1301 RI->replaceUsesOfWith(RetVal,
C);
1307 FnChanged |= BBChanged;
1311 if (RetRange && !RetRange->isFullSet()) {
1312 Attribute RangeAttr =
F.getRetAttribute(Attribute::Range);
1314 RetRange = RetRange->intersectWith(RangeAttr.
getRange());
1317 if (!RetRange->isEmptySet() && !RetRange->isSingleElement()) {
1318 F.addRangeRetAttr(*RetRange);
1336#if defined(EXPENSIVE_CHECKS)
1337 assert(DT->
verify(DominatorTree::VerificationLevel::Full));
1339 assert(DT->
verify(DominatorTree::VerificationLevel::Fast));
This file contains the simple types necessary to represent the attributes associated with functions a...
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
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.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool runImpl(Function &F, const TargetLowering &TLI)
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.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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.
APInt sext(unsigned width) const
Sign extend to a new width.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
const ConstantRange & getRange() const
Returns the value of the range attribute.
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
bool isValid() const
Return true if the attribute is any kind of attribute.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
LLVMContext & getContext() const
Get the context in which this basic block lives.
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
This class represents an intrinsic that is based on a binary operation.
unsigned getNoWrapKind() const
Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
bool isSigned() const
Whether the intrinsic is signed or unsigned.
Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
static 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 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.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
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.
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 CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
static 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 ...
This class is the base class for the comparison instructions.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_ULT
unsigned less than
@ ICMP_ULE
unsigned less or equal
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
This class represents a ucmp/scmp intrinsic.
static CmpInst::Predicate getGTPredicate(Intrinsic::ID ID)
static CmpInst::Predicate getLTPredicate(Intrinsic::ID ID)
This is the shared class of boolean and integer constants.
static ConstantInt * getTrue(LLVMContext &Context)
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
static ConstantInt * getFalse(LLVMContext &Context)
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This class represents a range of values.
unsigned getActiveBits() const
Compute the maximal number of active bits needed to represent every value in this range.
static 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.
bool isAllNegative() const
Return true if all values in this range are negative.
bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const
Does the predicate Pred hold between ranges this and Other? NOTE: false does not mean that inverse pr...
bool isSizeLargerThan(uint64_t MaxSize) const
Compare set size of this range with Value.
ConstantRange abs(bool IntMinIsPoison=false) const
Calculate absolute value range.
ConstantRange uadd_sat(const ConstantRange &Other) const
Perform an unsigned saturating addition of two constant ranges.
bool isAllNonNegative() const
Return true if all values in this range are non-negative.
ConstantRange sdiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed division of a value in th...
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
static bool areInsensitiveToSignednessOfICmpPredicate(const ConstantRange &CR1, const ConstantRange &CR2)
Return true iff CR1 ult CR2 is equivalent to CR1 slt CR2.
static 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)...
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 Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
This class represents an Operation in the Expression.
Analysis pass which computes a DominatorTree.
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
void applyUpdatesPermissive(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
This instruction compares its operands according to the predicate given to the constructor.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
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.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
bool isExact() const LLVM_READONLY
Determine whether the exact flag is set.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
Analysis to compute lazy value information.
This pass computes, caches, and vends lazy value constraint information.
ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed)
Return the ConstantRange constraint that is known to hold for the value at a specific use-site.
ConstantRange getConstantRange(Value *V, Instruction *CxtI, bool UndefAllowed)
Return the ConstantRange constraint that is known to hold for the specified value at the specified in...
Constant * getPredicateOnEdge(CmpInst::Predicate Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Determine whether the specified value comparison with a constant is known to be true or false on the ...
Constant * getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Determine whether the specified value is known to be a constant on the specified edge.
Constant * getConstant(Value *V, Instruction *CxtI)
Determine whether the specified value is known to be a constant at the specified instruction.
Constant * getPredicateAt(CmpInst::Predicate Pred, Value *V, Constant *C, Instruction *CxtI, bool UseBlockValue)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
This class represents min/max intrinsics.
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 PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Instruction that can have a nneg flag (zext/uitofp).
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.
void abandon()
Mark an analysis as abandoned.
void preserve()
Mark an analysis as preserved.
This class represents a sign extension of integer types.
This class represents a cast from signed integer to floating point.
Represents a saturating add/sub intrinsic.
This class represents the LLVM 'select' instruction.
const Value * getFalseValue() const
const Value * getCondition() const
const Value * getTrueValue() const
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Class to represent struct types.
A wrapper class to simplify modification of SwitchInst cases along with their prof branch_weights met...
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.
This class represents a cast unsigned integer to floating point.
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
const Use & getOperandUse(unsigned i) const
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
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()
StringRef getName() const
Return a constant reference to the value's name.
void takeName(Value *V)
Transfer the name from V to this value.
Represents an op.with.overflow intrinsic.
This class represents zero extension of integer types.
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
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)
This is an optimization pass for GlobalISel generic memory operations.
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...
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...
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.
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
iterator_range< df_iterator< T > > depth_first(const T &G)
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.
const SimplifyQuery getBestSimplifyQuery(Pass &, Function &)
Incoming for lane maks phi as machine instruction, incoming register Reg and incoming block Block are...