[Mlir-commits] [mlir] 6a2190d - [mlir] Make division unsigned.

Hendrik Greving llvmlistbot at llvm.org
Tue Aug 30 09:55:45 PDT 2022


Author: Hendrik Greving
Date: 2022-08-30T09:55:04-07:00
New Revision: 6a2190dffca638de2ced77c6a773067af1529c51

URL: https://github.com/llvm/llvm-project/commit/6a2190dffca638de2ced77c6a773067af1529c51
DIFF: https://github.com/llvm/llvm-project/commit/6a2190dffca638de2ced77c6a773067af1529c51.diff

LOG: [mlir] Make division unsigned.

Uses arith.divui where it is safe to do so.
Adjusts the tests for above.

Differential Revision: https://reviews.llvm.org/D132701

Added: 
    

Modified: 
    mlir/lib/Dialect/SCF/Utils/Utils.cpp
    mlir/test/Dialect/Affine/loop-coalescing.mlir
    mlir/test/Dialect/SCF/loop-unroll.mlir
    mlir/test/Transforms/parametric-tiling.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SCF/Utils/Utils.cpp b/mlir/lib/Dialect/SCF/Utils/Utils.cpp
index 501d95b3c791d..1bcc48a32d7b8 100644
--- a/mlir/lib/Dialect/SCF/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/SCF/Utils/Utils.cpp
@@ -297,7 +297,7 @@ static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend,
       builder.create<arith::ConstantIndexOp>(loc, divisor - 1);
   Value divisorCst = builder.create<arith::ConstantIndexOp>(loc, divisor);
   Value sum = builder.create<arith::AddIOp>(loc, dividend, divisorMinusOneCst);
-  return builder.create<arith::DivSIOp>(loc, sum, divisorCst);
+  return builder.create<arith::DivUIOp>(loc, sum, divisorCst);
 }
 
 // Build the IR that performs ceil division of a positive value by another
@@ -311,7 +311,7 @@ static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend,
   Value cstOne = builder.create<arith::ConstantIndexOp>(loc, 1);
   Value divisorMinusOne = builder.create<arith::SubIOp>(loc, divisor, cstOne);
   Value sum = builder.create<arith::AddIOp>(loc, dividend, divisorMinusOne);
-  return builder.create<arith::DivSIOp>(loc, sum, divisor);
+  return builder.create<arith::DivUIOp>(loc, sum, divisor);
 }
 
 /// Helper to replace uses of loop carried values (iter_args) and loop

diff  --git a/mlir/test/Dialect/Affine/loop-coalescing.mlir b/mlir/test/Dialect/Affine/loop-coalescing.mlir
index 664dfa39cb5e0..5abc59734ddf8 100644
--- a/mlir/test/Dialect/Affine/loop-coalescing.mlir
+++ b/mlir/test/Dialect/Affine/loop-coalescing.mlir
@@ -91,7 +91,7 @@ func.func @unnormalized_loops() {
   // CHECK: %[[c1:.*]] = arith.constant 1
   // CHECK: %[[step_minus_c1:.*]] = arith.subi %[[orig_step_i]], %[[c1]]
   // CHECK: %[[dividend:.*]] = arith.addi %[[
diff _i]], %[[step_minus_c1]]
-  // CHECK: %[[numiter_i:.*]] = arith.divsi %[[dividend]], %[[orig_step_i]]
+  // CHECK: %[[numiter_i:.*]] = arith.divui %[[dividend]], %[[orig_step_i]]
 
   // Normalized lower bound and step for the outer scf.
   // CHECK: %[[lb_i:.*]] = arith.constant 0
@@ -99,7 +99,7 @@ func.func @unnormalized_loops() {
 
   // Number of iterations in the inner loop, the pattern is the same as above,
   // only capture the final result.
-  // CHECK: %[[numiter_j:.*]] = arith.divsi {{.*}}, %[[orig_step_j]]
+  // CHECK: %[[numiter_j:.*]] = arith.divui {{.*}}, %[[orig_step_j]]
 
   // New bounds of the outer scf.
   // CHECK: %[[range:.*]] = arith.muli %[[numiter_i]], %[[numiter_j]]
@@ -137,11 +137,11 @@ func.func @parametric(%lb1 : index, %ub1 : index, %step1 : index,
   // CHECK: %[[range1:.*]] = arith.subi %[[orig_ub1]], %[[orig_lb1]]
   // CHECK: %[[orig_step1_minus_1:.*]] = arith.subi %[[orig_step1]], %c1
   // CHECK: %[[dividend1:.*]] = arith.addi %[[range1]], %[[orig_step1_minus_1]]
-  // CHECK: %[[numiter1:.*]] = arith.divsi %[[dividend1]], %[[orig_step1]]
+  // CHECK: %[[numiter1:.*]] = arith.divui %[[dividend1]], %[[orig_step1]]
   // CHECK: %[[range2:.*]] = arith.subi %[[orig_ub2]], %[[orig_lb2]]
   // CHECK: %[[orig_step2_minus_1:.*]] = arith.subi %arg5, %c1
   // CHECK: %[[dividend2:.*]] = arith.addi %[[range2]], %[[orig_step2_minus_1]]
-  // CHECK: %[[numiter2:.*]] = arith.divsi %[[dividend2]], %[[orig_step2]]
+  // CHECK: %[[numiter2:.*]] = arith.divui %[[dividend2]], %[[orig_step2]]
   // CHECK: %[[range:.*]] = arith.muli %[[numiter1]], %[[numiter2]] : index
 
   // Check that the outer loop is updated.

diff  --git a/mlir/test/Dialect/SCF/loop-unroll.mlir b/mlir/test/Dialect/SCF/loop-unroll.mlir
index 652e751d9104f..b2928f5a91e9c 100644
--- a/mlir/test/Dialect/SCF/loop-unroll.mlir
+++ b/mlir/test/Dialect/SCF/loop-unroll.mlir
@@ -25,7 +25,7 @@ func.func @dynamic_loop_unroll(%arg0 : index, %arg1 : index, %arg2 : index,
 //   UNROLL-BY-2-DAG:  %[[V1:.*]] = arith.subi %[[STEP]], %[[C1]] : index
 //   UNROLL-BY-2-DAG:  %[[V2:.*]] = arith.addi %[[V0]], %[[V1]] : index
 //       Compute trip count in V3.
-//   UNROLL-BY-2-DAG:  %[[V3:.*]] = arith.divsi %[[V2]], %[[STEP]] : index
+//   UNROLL-BY-2-DAG:  %[[V3:.*]] = arith.divui %[[V2]], %[[STEP]] : index
 //       Store unroll factor in C2.
 //   UNROLL-BY-2-DAG:  %[[C2:.*]] = arith.constant 2 : index
 //   UNROLL-BY-2-DAG:  %[[V4:.*]] = arith.remsi %[[V3]], %[[C2]] : index
@@ -58,7 +58,7 @@ func.func @dynamic_loop_unroll(%arg0 : index, %arg1 : index, %arg2 : index,
 //   UNROLL-BY-3-DAG:  %[[V1:.*]] = arith.subi %[[STEP]], %[[C1]] : index
 //   UNROLL-BY-3-DAG:  %[[V2:.*]] = arith.addi %[[V0]], %[[V1]] : index
 //       Compute trip count in V3.
-//   UNROLL-BY-3-DAG:  %[[V3:.*]] = arith.divsi %[[V2]], %[[STEP]] : index
+//   UNROLL-BY-3-DAG:  %[[V3:.*]] = arith.divui %[[V2]], %[[STEP]] : index
 //       Store unroll factor in C3.
 //   UNROLL-BY-3-DAG:  %[[C3:.*]] = arith.constant 3 : index
 //   UNROLL-BY-3-DAG:  %[[V4:.*]] = arith.remsi %[[V3]], %[[C3]] : index

diff  --git a/mlir/test/Transforms/parametric-tiling.mlir b/mlir/test/Transforms/parametric-tiling.mlir
index d47b171c96ddb..e3be41e702ec4 100644
--- a/mlir/test/Transforms/parametric-tiling.mlir
+++ b/mlir/test/Transforms/parametric-tiling.mlir
@@ -12,11 +12,11 @@ func.func @rectangular(%arg0: memref<?x?xf32>) {
   // COMMON:      %[[
diff :.*]] = arith.subi %c44, %c2
   // COMMON:      %[[adjustment:.*]] = arith.subi %c1, %c1_{{.*}}
   // COMMON-NEXT: %[[
diff _adj:.*]] = arith.addi %[[
diff ]], %[[adjustment]]
-  // COMMON-NEXT: %[[range:.*]] = arith.divsi %[[
diff _adj]], %c1
+  // COMMON-NEXT: %[[range:.*]] = arith.divui %[[
diff _adj]], %c1
 
   // Ceildiv to get the parametric tile size.
   // COMMON:       %[[sum:.*]] = arith.addi %[[range]], %c6
-  // COMMON-NEXT:  %[[size:.*]] = arith.divsi %[[sum]], %c7
+  // COMMON-NEXT:  %[[size:.*]] = arith.divui %[[sum]], %c7
   // New outer step (original is %c1).
   // COMMON-NEXT:      %[[step:.*]] = arith.muli %c1, %[[size]]
 
@@ -26,11 +26,11 @@ func.func @rectangular(%arg0: memref<?x?xf32>) {
   // TILE_74:      %[[
diff 2:.*]] = arith.subi %c44, %c1
   // TILE_74:      %[[adjustment2:.*]] = arith.subi %c2, %c1_{{.*}}
   // TILE_74-NEXT: %[[
diff 2_adj:.*]] = arith.addi %[[
diff 2]], %[[adjustment2]]
-  // TILE_74-NEXT: %[[range2:.*]] = arith.divsi %[[
diff 2_adj]], %c2
+  // TILE_74-NEXT: %[[range2:.*]] = arith.divui %[[
diff 2_adj]], %c2
 
   // Ceildiv to get the parametric tile size for the second original scf.
   // TILE_74:      %[[sum2:.*]] = arith.addi %[[range2]], %c3
-  // TILE_74-NEXT: %[[size2:.*]] = arith.divsi %[[sum2]], %c4
+  // TILE_74-NEXT: %[[size2:.*]] = arith.divui %[[sum2]], %c4
   // New inner step (original is %c2).
   // TILE_74-NEXT:     %[[step2:.*]] = arith.muli %c2, %[[size2]]
 
@@ -76,11 +76,11 @@ func.func @triangular(%arg0: memref<?x?xf32>) {
   // COMMON:      %[[
diff :.*]] = arith.subi %c44, %c2
   // COMMON:      %[[adjustment:.*]] = arith.subi %c1, %c1_{{.*}}
   // COMMON-NEXT: %[[
diff _adj:.*]] = arith.addi %[[
diff ]], %[[adjustment]]
-  // COMMON-NEXT: %[[range:.*]] = arith.divsi %[[
diff _adj]], %c1
+  // COMMON-NEXT: %[[range:.*]] = arith.divui %[[
diff _adj]], %c1
 
   // Ceildiv to get the parametric tile size.
   // COMMON:       %[[sum:.*]] = arith.addi %[[range]], %c6
-  // COMMON-NEXT:  %[[size:.*]] = arith.divsi %[[sum]], %c7
+  // COMMON-NEXT:  %[[size:.*]] = arith.divui %[[sum]], %c7
   // New outer step (original is %c1).
   // COMMON-NEXT:  %[[step:.*]] = arith.muli %c1, %[[size]]
 
@@ -95,11 +95,11 @@ func.func @triangular(%arg0: memref<?x?xf32>) {
   // where step is known to be %c2.
   // TILE_74:      %[[
diff 2:.*]] = arith.subi %[[i]], %c1
   // TILE_74-NEXT: %[[
diff 2_adj:.*]] = arith.addi %[[
diff 2]], %[[adjustment2]]
-  // TILE_74-NEXT: %[[range2:.*]] = arith.divsi %[[
diff 2_adj]], %c2
+  // TILE_74-NEXT: %[[range2:.*]] = arith.divui %[[
diff 2_adj]], %c2
 
   // Ceildiv to get the parametric tile size for the second original scf.
   // TILE_74:      %[[sum2:.*]] = arith.addi %[[range2]], %c3
-  // TILE_74-NEXT: %[[size2:.*]] = arith.divsi %[[sum2]], %c4
+  // TILE_74-NEXT: %[[size2:.*]] = arith.divui %[[sum2]], %c4
   // New inner step (original is %c2).
   // TILE_74-NEXT:     %[[step2:.*]] = arith.muli %c2, %[[size2]]
 


        


More information about the Mlir-commits mailing list