[Mlir-commits] [mlir] [mlir][Vector] Fold vector.step compared to constant (PR #161615)

James Newling llvmlistbot at llvm.org
Tue Oct 14 13:21:09 PDT 2025


================
@@ -0,0 +1,393 @@
+// RUN: mlir-opt %s -canonicalize="test-convergence" -split-input-file | FileCheck %s
+
+///===----------------------------------------------===//
+///  Tests of `StepCompareFolder`
+///===----------------------------------------------===//
+
+
+///===------------------------------------===//
+///  Tests of `ugt` (unsigned greater than)
+///===------------------------------------===//
+
+// CHECK-LABEL: @ugt_constant_3_lhs
+//       CHECK: %[[CST:.*]] = arith.constant dense<true> : vector<3xi1>
+//       CHECK: return %[[CST]] : vector<3xi1>
+func.func @ugt_constant_3_lhs() -> vector<3xi1> {
+  %cst = arith.constant dense<3> : vector<3xindex>
+  %0 = vector.step : vector<3xindex>
+  // 3 > [0, 1, 2] => true
+  %1 = arith.cmpi ugt, %cst, %0 : vector<3xindex>
+  return %1 : vector<3xi1>
+}
+
+// -----
+
+// CHECK-LABEL: @negative_ugt_constant_2_lhs
+//       CHECK: %[[CMP:.*]] = arith.cmpi
+//       CHECK: return %[[CMP]]
+func.func @negative_ugt_constant_2_lhs() -> vector<3xi1> {
+  %cst = arith.constant dense<2> : vector<3xindex>
+  %0 = vector.step : vector<3xindex>
+  // 2 > [0, 1, 2] => not constant
----------------
newling wrote:

I've updated the comment but essentially I mean that it's not the same at all indices. 

`2 > [0, 1, 2]` is `[true, true, false]`. Because it's not _always_ true or _always_ false, it doesn't get folded. So by "constant" I meant "the same at all indices". Which admittedly is a confusing use of the word "constant" when working on a compiler :-D

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


More information about the Mlir-commits mailing list