[Mlir-commits] [mlir] [mlir][scf]: Expose emitNormalizedLoopBounds/denormalizeInductionVariable util functions (NFC) (PR #94429)
Aviad Cohen
llvmlistbot at llvm.org
Wed Jun 12 22:21:51 PDT 2024
================
@@ -495,45 +478,58 @@ static LoopParams emitNormalizedLoopBounds(RewriterBase &rewriter, Location loc,
if (auto stepCst = getConstantIntValue(step))
isStepOne = stepCst.value() == 1;
+ Type loopParamsType = getIntType(lb);
+ assert(loopParamsType == getIntType(ub) &&
+ loopParamsType == getIntType(step) && "expected matching types");
+
// Compute the number of iterations the loop executes: ceildiv(ub - lb, step)
// assuming the step is strictly positive. Update the bounds and the step
// of the loop to go from 0 to the number of iterations, if necessary.
if (isZeroBased && isStepOne)
return {lb, ub, step};
- Value diff = isZeroBased ? ub : rewriter.create<arith::SubIOp>(loc, ub, lb);
- Value newUpperBound =
- isStepOne ? diff : rewriter.create<arith::CeilDivSIOp>(loc, diff, step);
-
- Value newLowerBound = isZeroBased
- ? lb
- : rewriter.create<arith::ConstantOp>(
- loc, rewriter.getZeroAttr(lb.getType()));
- Value newStep = isStepOne
- ? step
- : rewriter.create<arith::ConstantOp>(
- loc, rewriter.getIntegerAttr(step.getType(), 1));
+ OpFoldResult diff = isZeroBased ? ub
+ : rewriter.createOrFold<arith::SubIOp>(
+ loc,
+ getValueOrCreateConstantIntOp(
+ rewriter, loc, loopParamsType, ub),
+ getValueOrCreateConstantIntOp(
+ rewriter, loc, loopParamsType, lb));
+ OpFoldResult newUpperBound =
+ isStepOne ? diff
+ : rewriter.createOrFold<arith::CeilDivSIOp>(
+ loc,
+ getValueOrCreateConstantIntOp(rewriter, loc,
+ loopParamsType, diff),
+ getValueOrCreateConstantIntOp(rewriter, loc,
+ loopParamsType, step));
----------------
AviadCo wrote:
Ack
https://github.com/llvm/llvm-project/pull/94429
More information about the Mlir-commits
mailing list