13 #include "llvm/Support/Debug.h"
16 #define DEBUG_TYPE "int-range-analysis"
28 auto constAttr = llvm::dyn_cast_or_null<IntegerAttr>(getValue());
30 const APInt &value = constAttr.getValue();
41 setResultRange(getResult(),
inferAdd(argRanges));
50 setResultRange(getResult(),
inferSub(argRanges));
59 setResultRange(getResult(),
inferMul(argRanges));
68 setResultRange(getResult(),
inferDivU(argRanges));
77 setResultRange(getResult(),
inferDivS(argRanges));
84 void arith::CeilDivUIOp::inferResultRanges(
93 void arith::CeilDivSIOp::inferResultRanges(
102 void arith::FloorDivSIOp::inferResultRanges(
113 setResultRange(getResult(),
inferRemU(argRanges));
122 setResultRange(getResult(),
inferRemS(argRanges));
131 setResultRange(getResult(),
inferAnd(argRanges));
140 setResultRange(getResult(),
inferOr(argRanges));
149 setResultRange(getResult(),
inferXor(argRanges));
158 setResultRange(getResult(),
inferMaxS(argRanges));
167 setResultRange(getResult(),
inferMaxU(argRanges));
176 setResultRange(getResult(),
inferMinS(argRanges));
185 setResultRange(getResult(),
inferMinU(argRanges));
196 setResultRange(getResult(),
extUIRange(argRanges[0], destWidth));
207 setResultRange(getResult(),
extSIRange(argRanges[0], destWidth));
218 setResultRange(getResult(),
truncRange(argRanges[0], destWidth));
225 void arith::IndexCastOp::inferResultRanges(
227 Type sourceType = getOperand().getType();
228 Type destType = getResult().getType();
232 if (srcWidth < destWidth)
233 setResultRange(getResult(),
extSIRange(argRanges[0], destWidth));
234 else if (srcWidth > destWidth)
235 setResultRange(getResult(),
truncRange(argRanges[0], destWidth));
237 setResultRange(getResult(), argRanges[0]);
244 void arith::IndexCastUIOp::inferResultRanges(
246 Type sourceType = getOperand().getType();
247 Type destType = getResult().getType();
251 if (srcWidth < destWidth)
252 setResultRange(getResult(),
extUIRange(argRanges[0], destWidth));
253 else if (srcWidth > destWidth)
254 setResultRange(getResult(),
truncRange(argRanges[0], destWidth));
256 setResultRange(getResult(), argRanges[0]);
265 arith::CmpIPredicate arithPred = getPredicate();
270 APInt
max = APInt::getAllOnes(1);
273 if (truthValue.has_value() && *truthValue)
275 else if (truthValue.has_value() && !(*truthValue))
287 std::optional<APInt> mbCondVal = argRanges[0].getConstantValue();
290 if (mbCondVal->isZero())
291 setResultRange(getResult(), argRanges[2]);
293 setResultRange(getResult(), argRanges[1]);
296 setResultRange(getResult(), argRanges[1].rangeUnion(argRanges[2]));
305 setResultRange(getResult(),
inferShl(argRanges));
314 setResultRange(getResult(),
inferShrU(argRanges));
323 setResultRange(getResult(),
inferShrS(argRanges));
static Value getZero(OpBuilder &b, Location loc, Type elementType)
Get zero value for an element type.
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
A set of arbitrary-precision integers representing bounds on a given integer value.
static ConstantIntRanges constant(const APInt &value)
Create a ConstantIntRanges with a constant value - that is, with the bounds [value,...
static ConstantIntRanges fromUnsigned(const APInt &umin, const APInt &umax)
Create an ConstantIntRanges with the unsigned minimum and maximum equal to umin and umax and the sign...
static unsigned getStorageBitwidth(Type type)
Return the bitwidth that should be used for integer ranges describing type.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
ConstantIntRanges inferAnd(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferAdd(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferSub(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferShrS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges extSIRange(const ConstantIntRanges &range, unsigned destWidth)
Use the signed values in range to sign-extend it to destWidth.
std::optional< bool > evaluatePred(CmpPredicate pred, const ConstantIntRanges &lhs, const ConstantIntRanges &rhs)
Returns a boolean value if pred is statically true or false for anypossible inputs falling within lhs...
ConstantIntRanges inferMinS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferMaxU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferRemS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferMul(ArrayRef< ConstantIntRanges > argRanges)
CmpPredicate
Copy of the enum from arith and index to allow the common integer range infrastructure to not depend ...
ConstantIntRanges inferOr(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges truncRange(const ConstantIntRanges &range, unsigned destWidth)
Truncate range to destWidth bits, taking care to handle cases such as the truncation of [255,...
ConstantIntRanges inferDivU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferCeilDivS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferMinU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferXor(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferDivS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferShrU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferRemU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferFloorDivS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferCeilDivU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges extUIRange(const ConstantIntRanges &range, unsigned destWidth)
Use the unsigned values in range to zero-extend it to destWidth.
ConstantIntRanges inferShl(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferMaxS(ArrayRef< ConstantIntRanges > argRanges)
Include the generated interface declarations.