[Mlir-commits] [mlir] [mlir] [linalg] Fold reduce(broadcast(x)) max/min (PR #213190)

Adam Siemieniuk llvmlistbot at llvm.org
Mon Aug 3 07:46:49 PDT 2026


================
@@ -1,5 +1,88 @@
 // RUN: mlir-opt %s -canonicalize="test-convergence" -split-input-file | FileCheck %s
 
+// CHECK-LABEL: func.func @reduce_broadcast_maxsi
+func.func @reduce_broadcast_maxsi(%input: tensor<3xi32>,
+    %broadcast_init: tensor<3x4xi32>)
+    -> tensor<3xi32> {
+  %reduce_init = arith.constant dense<-2147483648> : tensor<3xi32>
+  %broadcasted = linalg.broadcast
+      ins(%input : tensor<3xi32>)
+      outs(%broadcast_init : tensor<3x4xi32>) dimensions = [1]
+  %result = linalg.reduce
+      ins(%broadcasted : tensor<3x4xi32>)
+      outs(%reduce_init : tensor<3xi32>) dimensions = [1]
+      (%in: i32, %out: i32) {
+      %max = arith.maxsi %in, %out : i32
+      linalg.yield %max : i32
+  }
+  return %result : tensor<3xi32>
+}
+// CHECK-NEXT: return %{{.*}} : tensor<3xi32>
----------------
adam-smnk wrote:

I'd check and capture at least the value and its producer ops before returning. Currently, the state of IR after canonicalization is unclear (whether anything changed at all and if it's correct).

nit: I'd place it together with the previous `CHECK-LABEL` statement, I think it fits this file's existing style better

https://github.com/llvm/llvm-project/pull/213190


More information about the Mlir-commits mailing list