[Mlir-commits] [mlir] 59569eb - [mlir] Fix support for loop normalization with integer indices (#76566)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jan 5 06:49:26 PST 2024


Author: Arseniy Obolenskiy
Date: 2024-01-05T17:49:21+03:00
New Revision: 59569eb756265b2a5d9d96f6c6c5ee1a3c371c4f

URL: https://github.com/llvm/llvm-project/commit/59569eb756265b2a5d9d96f6c6c5ee1a3c371c4f
DIFF: https://github.com/llvm/llvm-project/commit/59569eb756265b2a5d9d96f6c6c5ee1a3c371c4f.diff

LOG: [mlir] Fix support for loop normalization with integer indices (#76566)

Choose correct type for updated loop boundaries after scf loop
normalization, do not force chosen type to IndexType

Added: 
    

Modified: 
    mlir/lib/Dialect/SCF/Utils/Utils.cpp
    mlir/test/Dialect/SCF/transform-ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SCF/Utils/Utils.cpp b/mlir/lib/Dialect/SCF/Utils/Utils.cpp
index e85825595e3c1e..a2043c647d49a3 100644
--- a/mlir/lib/Dialect/SCF/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/SCF/Utils/Utils.cpp
@@ -502,9 +502,12 @@ static LoopParams normalizeLoop(OpBuilder &boundsBuilder,
 
   Value newLowerBound =
       isZeroBased ? lowerBound
-                  : boundsBuilder.create<arith::ConstantIndexOp>(loc, 0);
+                  : boundsBuilder.create<arith::ConstantOp>(
+                        loc, boundsBuilder.getZeroAttr(lowerBound.getType()));
   Value newStep =
-      isStepOne ? step : boundsBuilder.create<arith::ConstantIndexOp>(loc, 1);
+      isStepOne ? step
+                : boundsBuilder.create<arith::ConstantOp>(
+                      loc, boundsBuilder.getIntegerAttr(step.getType(), 1));
 
   // Insert code computing the value of the original loop induction variable
   // from the "normalized" one.

diff  --git a/mlir/test/Dialect/SCF/transform-ops.mlir b/mlir/test/Dialect/SCF/transform-ops.mlir
index 93ebf67f8b7133..a945758143c644 100644
--- a/mlir/test/Dialect/SCF/transform-ops.mlir
+++ b/mlir/test/Dialect/SCF/transform-ops.mlir
@@ -270,3 +270,33 @@ module attributes {transform.with_named_sequence} {
     transform.yield
   }
 }
+
+// -----
+
+// CHECK-LABEL: func @coalesce_i32_loops(
+
+// This test checks for loop coalescing success for non-index loop boundaries and step type
+func.func @coalesce_i32_loops() {
+  %0 = arith.constant 0 : i32
+  %1 = arith.constant 128 : i32
+  %2 = arith.constant 2 : i32
+  %3 = arith.constant 64 : i32
+  // CHECK-DAG: %[[C0_I32:.*]] = arith.constant 0 : i32
+  // CHECK-DAG: %[[C1_I32:.*]] = arith.constant 1 : i32
+  // CHECK: scf.for %[[ARG0:.*]] = %[[C0_I32]] to {{.*}} step %[[C1_I32]]  : i32
+  scf.for %i = %0 to %1 step %2 : i32 {
+    scf.for %j = %0 to %3 step %2 : i32 {
+      arith.addi %i, %j : i32
+    }
+  } {coalesce}
+  return
+}
+
+module attributes {transform.with_named_sequence} {
+  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
+    %0 = transform.structured.match ops{["scf.for"]} attributes {coalesce} in %arg1 : (!transform.any_op) -> !transform.any_op
+    %1 = transform.cast %0 : !transform.any_op to !transform.op<"scf.for">
+    %2 = transform.loop.coalesce %1: (!transform.op<"scf.for">) -> (!transform.op<"scf.for">)
+    transform.yield
+  }
+}


        


More information about the Mlir-commits mailing list