@@ -152,15 +152,15 @@ void IntegerRangeAnalysis::visitNonControlFlowArguments(
152
152
// / on a LoopLikeInterface return the lower/upper bound for that result if
153
153
// / possible.
154
154
auto getLoopBoundFromFold = [&](std::optional<OpFoldResult> loopBound,
155
- Type boundType, bool getUpper) {
155
+ Type boundType, Block *block, bool getUpper) {
156
156
unsigned int width = ConstantIntRanges::getStorageBitwidth (boundType);
157
157
if (loopBound.has_value ()) {
158
158
if (auto attr = dyn_cast<Attribute>(*loopBound)) {
159
159
if (auto bound = dyn_cast_or_null<IntegerAttr>(attr))
160
160
return bound.getValue ();
161
161
} else if (auto value = llvm::dyn_cast_if_present<Value>(*loopBound)) {
162
162
const IntegerValueRangeLattice *lattice =
163
- getLatticeElementFor (getProgramPointAfter (op ), value);
163
+ getLatticeElementFor (getProgramPointBefore (block ), value);
164
164
if (lattice != nullptr && !lattice->getValue ().isUninitialized ())
165
165
return getUpper ? lattice->getValue ().getValue ().smax ()
166
166
: lattice->getValue ().getValue ().smin ();
@@ -180,16 +180,17 @@ void IntegerRangeAnalysis::visitNonControlFlowArguments(
180
180
return SparseForwardDataFlowAnalysis ::visitNonControlFlowArguments (
181
181
op, successor, argLattices, firstIndex);
182
182
}
183
+ Block *block = iv->getParentBlock ();
183
184
std::optional<OpFoldResult> lowerBound = loop.getSingleLowerBound ();
184
185
std::optional<OpFoldResult> upperBound = loop.getSingleUpperBound ();
185
186
std::optional<OpFoldResult> step = loop.getSingleStep ();
186
- APInt min = getLoopBoundFromFold (lowerBound, iv->getType (),
187
+ APInt min = getLoopBoundFromFold (lowerBound, iv->getType (), block,
187
188
/* getUpper=*/ false );
188
- APInt max = getLoopBoundFromFold (upperBound, iv->getType (),
189
+ APInt max = getLoopBoundFromFold (upperBound, iv->getType (), block,
189
190
/* getUpper=*/ true );
190
191
// Assume positivity for uniscoverable steps by way of getUpper = true.
191
192
APInt stepVal =
192
- getLoopBoundFromFold (step, iv->getType (), /* getUpper=*/ true );
193
+ getLoopBoundFromFold (step, iv->getType (), block, /* getUpper=*/ true );
193
194
194
195
if (stepVal.isNegative ()) {
195
196
std::swap (min, max);
0 commit comments