[Mlir-commits] [mlir] [mlir] Restore fullyComposeAffineMapAndOperands in simplifyConstrainedMinMaxOp (PR #233743)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 20 02:15:31 PDT 2026


https://github.com/xshang-synaptics updated https://github.com/llvm/llvm-project/pull/233743

>From 54b9de6fa1b6bce4ae10b4d679bb1496c74f50fb Mon Sep 17 00:00:00 2001
From: "Xiaomei.Shang" <Xiaomei.Shang at synaptics.com>
Date: Tue, 20 Oct 2026 01:19:53 -0700
Subject: [PATCH] [mlir][Affine] Compose affine.apply operands in
 simplifyConstrainedMinMaxOp

simplifyConstrainedMinMaxOp passes the raw op operands to the
constraint solver. When an operand is produced by an affine.apply
(possibly through a chain of them), the solver cannot relate it to
the constrained values and treats it as an opaque dimension, so a
min/max that is provably constant under the given constraints fails
to simplify.

The only in-tree caller (transform.affine.simplify_bounded_affine_ops)
is not affected because it runs affine canonicalization patterns to a
fixpoint alongside the simplification, and canonicalization composes
affine.apply operands into the min/max map first. Direct callers of
the utility, such as IREE's FoldAffineMinInDistributedLoops, do not
run canonicalization beforehand and hit the silent failure (observed
downstream as fused tile loops staying dynamic-typed and getting
fully unrolled, +28% kernel time on an NPU target).

Compose the operands with affine::fullyComposeAffineMapAndOperands
inside the utility itself, so all callers get the composed form
regardless of whether canonicalization ran. The null-operand
filtering added in d725513e7d92 (#189246, fixing #127436) is
unaffected: it guards the appended internal constraint dims, which
are null-valued in either formulation.
---
 mlir/lib/Dialect/Affine/Analysis/Utils.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
index 0e036dfedbf52e..6bfa5929705b64 100644
--- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
@@ -2318,7 +2318,10 @@ FailureOr<AffineValueMap> mlir::affine::simplifyConstrainedMinMaxOp(
   Builder builder(ctx);
   AffineMap map =
       isMin ? cast<AffineMinOp>(op).getMap() : cast<AffineMaxOp>(op).getMap();
-  ValueRange operands = op->getOperands();
+  SmallVector<Value> operands =
+      isMin ? cast<AffineMinOp>(op).getOperands()
+            : cast<AffineMaxOp>(op).getOperands();
+  affine::fullyComposeAffineMapAndOperands(&map, &operands);
   unsigned numResults = map.getNumResults();
 
   // Add a few extra dimensions.



More information about the Mlir-commits mailing list