@@ -152,15 +152,15 @@ void IntegerRangeAnalysis::visitNonControlFlowArguments(
152152 // / on a LoopLikeInterface return the lower/upper bound for that result if
153153 // / possible.
154154 auto getLoopBoundFromFold = [&](std::optional<OpFoldResult> loopBound,
155- Type boundType, bool getUpper) {
155+ Type boundType, Block *block, bool getUpper) {
156156 unsigned int width = ConstantIntRanges::getStorageBitwidth (boundType);
157157 if (loopBound.has_value ()) {
158158 if (auto attr = dyn_cast<Attribute>(*loopBound)) {
159159 if (auto bound = dyn_cast_or_null<IntegerAttr>(attr))
160160 return bound.getValue ();
161161 } else if (auto value = llvm::dyn_cast_if_present<Value>(*loopBound)) {
162162 const IntegerValueRangeLattice *lattice =
163- getLatticeElementFor (getProgramPointAfter (op ), value);
163+ getLatticeElementFor (getProgramPointBefore (block ), value);
164164 if (lattice != nullptr && !lattice->getValue ().isUninitialized ())
165165 return getUpper ? lattice->getValue ().getValue ().smax ()
166166 : lattice->getValue ().getValue ().smin ();
@@ -180,16 +180,17 @@ void IntegerRangeAnalysis::visitNonControlFlowArguments(
180180 return SparseForwardDataFlowAnalysis ::visitNonControlFlowArguments (
181181 op, successor, argLattices, firstIndex);
182182 }
183+ Block *block = iv->getParentBlock ();
183184 std::optional<OpFoldResult> lowerBound = loop.getSingleLowerBound ();
184185 std::optional<OpFoldResult> upperBound = loop.getSingleUpperBound ();
185186 std::optional<OpFoldResult> step = loop.getSingleStep ();
186- APInt min = getLoopBoundFromFold (lowerBound, iv->getType (),
187+ APInt min = getLoopBoundFromFold (lowerBound, iv->getType (), block,
187188 /* getUpper=*/ false );
188- APInt max = getLoopBoundFromFold (upperBound, iv->getType (),
189+ APInt max = getLoopBoundFromFold (upperBound, iv->getType (), block,
189190 /* getUpper=*/ true );
190191 // Assume positivity for uniscoverable steps by way of getUpper = true.
191192 APInt stepVal =
192- getLoopBoundFromFold (step, iv->getType (), /* getUpper=*/ true );
193+ getLoopBoundFromFold (step, iv->getType (), block, /* getUpper=*/ true );
193194
194195 if (stepVal.isNegative ()) {
195196 std::swap (min, max);
0 commit comments