23 case Instruction::Add:
24 case Instruction::Sub:
25 case Instruction::Mul:
26 case Instruction::Shl: {
27 auto *OBO = cast<OverflowingBinaryOperator>(
this);
28 return OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap();
30 case Instruction::Trunc: {
31 if (
auto *TI = dyn_cast<TruncInst>(
this))
32 return TI->hasNoUnsignedWrap() || TI->hasNoSignedWrap();
35 case Instruction::UDiv:
36 case Instruction::SDiv:
37 case Instruction::AShr:
38 case Instruction::LShr:
39 return cast<PossiblyExactOperator>(
this)->isExact();
41 return cast<PossiblyDisjointInst>(
this)->isDisjoint();
42 case Instruction::GetElementPtr: {
43 auto *
GEP = cast<GEPOperator>(
this);
46 GEP->getInRange() != std::nullopt;
48 case Instruction::UIToFP:
49 case Instruction::ZExt:
50 if (
auto *NNI = dyn_cast<PossiblyNonNegInst>(
this))
51 return NNI->hasNonNeg();
54 if (
const auto *
FP = dyn_cast<FPMathOperator>(
this))
55 return FP->hasNoNaNs() ||
FP->hasNoInfs();
63 auto *
I = dyn_cast<Instruction>(
this);
64 return I && (
I->hasPoisonGeneratingReturnAttributes() ||
65 I->hasPoisonGeneratingMetadata());
69 if (
auto *
I = dyn_cast<GetElementPtrInst>(
this))
70 return I->getSourceElementType();
71 return cast<GetElementPtrConstantExpr>(
this)->getSourceElementType();
75 if (
auto *
I = dyn_cast<GetElementPtrInst>(
this))
76 return I->getResultElementType();
77 return cast<GetElementPtrConstantExpr>(
this)->getResultElementType();
81 if (
auto *CE = dyn_cast<GetElementPtrConstantExpr>(
this))
82 return CE->getInRange();
94 ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand());
96 if (
StructType *STy = GTI.getStructTypeOrNull()) {
100 assert(GTI.isSequential() &&
"should be sequencial");
104 Offset = GTI.getSequentialElementStride(
DL) * ElemCount;
116 "The offset bit width does not match DL specification.");
126 if (SourceType->
isIntegerTy(8) && !ExternalAnalysis) {
127 if (
auto *CI = dyn_cast<ConstantInt>(
Index.front())) {
128 Offset += CI->getValue().sextOrTrunc(
Offset.getBitWidth());
134 bool UsedExternalAnalysis =
false;
139 if (!UsedExternalAnalysis) {
144 bool Overflow =
false;
155 SourceType,
Index.begin());
157 for (
auto GTI = begin, GTE = end; GTI != GTE; ++GTI) {
161 Value *V = GTI.getOperand();
164 if (
auto ConstOffset = dyn_cast<ConstantInt>(V)) {
165 if (ConstOffset->isZero())
173 unsigned ElementIdx = ConstOffset->getZExtValue();
176 if (!AccumulateOffset(
182 if (!AccumulateOffset(ConstOffset->getValue(),
183 GTI.getSequentialElementStride(
DL)))
190 if (!ExternalAnalysis || STy || ScalableType)
193 if (!ExternalAnalysis(*V, AnalysisIndex))
195 UsedExternalAnalysis =
true;
196 if (!AccumulateOffset(AnalysisIndex, GTI.getSequentialElementStride(
DL)))
205 APInt &ConstantOffset)
const {
207 "The offset bit width does not match DL specification.");
212 ConstantOffset +=
Index * IndexedSize;
218 bool ScalableType = GTI.getIndexedType()->isScalableTy();
220 Value *V = GTI.getOperand();
223 if (
auto ConstOffset = dyn_cast<ConstantInt>(V)) {
224 if (ConstOffset->isZero())
235 unsigned ElementIdx = ConstOffset->getZExtValue();
242 CollectConstantOffset(ConstOffset->getValue(),
243 GTI.getSequentialElementStride(
DL));
247 if (STy || ScalableType)
252 if (!IndexedSize.
isZero()) {
254 It->second += IndexedSize;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Class for arbitrary precision integers.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
APInt smul_ov(const APInt &RHS, bool &Overflow) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
A parsed version of the target data layout string in and methods for querying it.
bool noSignedZeros() const
bool allowReciprocal() const
void print(raw_ostream &O) const
Print fast-math flags to O.
bool allowReassoc() const
Flag queries.
bool allowContract() const
static GEPNoWrapFlags none()
bool collectOffset(const DataLayout &DL, unsigned BitWidth, MapVector< Value *, APInt > &VariableOffsets, APInt &ConstantOffset) const
Collect the offset of this GEP as a map of Values to their associated APInt multipliers,...
std::optional< ConstantRange > getInRange() const
Returns the offset of the index with an inrange attachment, or std::nullopt if none.
Type * getSourceElementType() const
Type * getResultElementType() const
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset, function_ref< bool(Value &, APInt &)> ExternalAnalysis=nullptr) const
Accumulate the constant address offset of this GEP if possible.
Align getMaxPreservedAlignment(const DataLayout &DL) const
Compute the maximum alignment that this GEP is garranteed to preserve.
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
This class implements a map that also provides access to all stored values in a deterministic order.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
bool hasPoisonGeneratingAnnotations() const
Return true if this operator has poison-generating flags, return attributes or metadata.
bool hasPoisonGeneratingFlags() const
Return true if this operator has flags which may cause this operator to evaluate to poison despite ha...
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
TypeSize getElementOffset(unsigned Idx) const
Class to represent struct types.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isScalableTy() const
Return true if this is a type whose size is a known multiple of vscale.
bool isIntegerTy() const
True if this is an instance of IntegerType.
iterator_range< value_op_iterator > operand_values()
LLVM Value Representation.
static constexpr uint64_t MaximumAlignment
An efficient, type-erasing, non-owning reference to a callable.
Type * getIndexedType() const
This class implements an extremely fast bulk output stream that can only output to a stream.
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.
gep_type_iterator gep_type_end(const User *GEP)
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
constexpr unsigned BitWidth
gep_type_iterator gep_type_begin(const User *GEP)
This struct is a compact representation of a valid (non-zero power of two) alignment.