[Mlir-commits] [mlir] [mlir][scf]: Avoid using wrong calculation loop pipelining kernel upperbound (PR #116748)
Aviad Cohen
llvmlistbot at llvm.org
Mon Nov 25 02:12:35 PST 2024
================
@@ -444,7 +444,15 @@ scf::ForOp LoopPipelinerInternal::createKernelLoop(
loc, rewriter.getIntegerAttr(t, maxStage));
Value maxStageByStep =
rewriter.create<arith::MulIOp>(loc, step, maxStageValue);
- newUb = rewriter.create<arith::SubIOp>(loc, ub, maxStageByStep);
+ Value hasAtLeastOneIteration = rewriter.create<arith::CmpIOp>(
+ loc, arith::CmpIPredicate::slt, maxStageByStep, ub);
+ Value possibleNewUB =
+ rewriter.create<arith::SubIOp>(loc, ub, maxStageByStep);
+ // In case of `index` or `unsigned` type, we need to make sure that the
+ // subtraction does not result in a negative value, instead we use lb
+ // to avoid entering the kernel loop.
+ newUb = rewriter.create<arith::SelectOp>(
+ loc, hasAtLeastOneIteration, possibleNewUB, forOp.getLowerBound());
----------------
AviadCo wrote:
@ThomasRaoux @joker-eph
After some discussion iwth my team it seems more reasonable to make the lower/upper bounds as `signed integer` when lowered to HW.
Here is a followed up PR: https://github.com/llvm/llvm-project/pull/117534
https://github.com/llvm/llvm-project/pull/116748
More information about the Mlir-commits
mailing list