[Mlir-commits] [mlir] 652a796 - [mlir] fix off-by-one error in collapseParallelLoops

Tobias Gysi llvmlistbot at llvm.org
Fri Jun 26 06:39:52 PDT 2020


Author: Tobias Gysi
Date: 2020-06-26T15:39:46+02:00
New Revision: 652a79659a89b3634f34c6cf94a0b18b25ea4419

URL: https://github.com/llvm/llvm-project/commit/652a79659a89b3634f34c6cf94a0b18b25ea4419
DIFF: https://github.com/llvm/llvm-project/commit/652a79659a89b3634f34c6cf94a0b18b25ea4419.diff

LOG: [mlir] fix off-by-one error in collapseParallelLoops

Summary: The patch fixes an off by one error in the method collapseParallelLoops. It ensures the same normalized bound is used for the computation of the division and the remainder.

Reviewers: herhut

Reviewed By: herhut

Subscribers: mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, Kayjukh, jurahul, msifontes

Tags: #mlir

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

Added: 
    

Modified: 
    mlir/lib/Transforms/Utils/LoopUtils.cpp
    mlir/test/Transforms/parallel-loop-collapsing.mlir
    mlir/test/Transforms/single-parallel-loop-collapsing.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp
index 58e2d9b42043..58807cf72128 100644
--- a/mlir/lib/Transforms/Utils/LoopUtils.cpp
+++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp
@@ -1491,7 +1491,7 @@ void mlir::collapseParallelLoops(
             // Remove the effect of the current induction value to prepare for
             // the next value.
             previous = insideBuilder.create<SignedDivIOp>(
-                loc, previous, normalizedUpperBounds[idx + 1]);
+                loc, previous, normalizedUpperBounds[idx]);
           }
 
           // The final induction value is just the remaining value.

diff  --git a/mlir/test/Transforms/parallel-loop-collapsing.mlir b/mlir/test/Transforms/parallel-loop-collapsing.mlir
index 36b6a2cab948..5d581cffaffe 100644
--- a/mlir/test/Transforms/parallel-loop-collapsing.mlir
+++ b/mlir/test/Transforms/parallel-loop-collapsing.mlir
@@ -30,15 +30,16 @@ func @parallel_many_dims() {
 // CHECK:         [[C6:%.*]] = constant 6 : index
 // CHECK:         [[C9:%.*]] = constant 9 : index
 // CHECK:         [[C10:%.*]] = constant 10 : index
-// CHECK:         [[C12:%.*]] = constant 12 : index
 // CHECK:         [[C0:%.*]] = constant 0 : index
 // CHECK:         [[C1:%.*]] = constant 1 : index
 // CHECK:         [[C2:%.*]] = constant 2 : index
 // CHECK:         [[C3:%.*]] = constant 3 : index
+// CHECK:         [[C12:%.*]] = constant 12 : index
 // CHECK:         scf.parallel ([[NEW_I0:%.*]]) = ([[C0]]) to ([[C2]]) step ([[C1]]) {
 // CHECK:           [[I0:%.*]] = remi_signed [[NEW_I0]], [[C2]] : index
-// CHECK:           [[V18:%.*]] = muli [[NEW_I0]], [[C10]] : index
-// CHECK:           [[I3:%.*]] = addi [[V18]], [[C9]] : index
+// CHECK:           [[V0:%.*]] = divi_signed [[NEW_I0]], [[C2]] : index
+// CHECK:           [[V2:%.*]] = muli [[V0]], [[C10]] : index
+// CHECK:           [[I3:%.*]] = addi [[V2]], [[C9]] : index
 // CHECK:           "magic.op"([[I0]], [[C3]], [[C6]], [[I3]], [[C12]]) : (index, index, index, index, index) -> index
 // CHECK:           scf.yield
 // CHECK-NEXT:    }

diff  --git a/mlir/test/Transforms/single-parallel-loop-collapsing.mlir b/mlir/test/Transforms/single-parallel-loop-collapsing.mlir
index 4cc354bca0b2..bdf4338e4889 100644
--- a/mlir/test/Transforms/single-parallel-loop-collapsing.mlir
+++ b/mlir/test/Transforms/single-parallel-loop-collapsing.mlir
@@ -18,16 +18,15 @@ func @collapse_to_single() {
 // CHECK:         [[C4:%.*]] = constant 4 : index
 // CHECK:         [[C18:%.*]] = constant 18 : index
 // CHECK:         [[C3:%.*]] = constant 3 : index
-// CHECK:         [[C6:%.*]] = constant 6 : index
 // CHECK:         [[C0:%.*]] = constant 0 : index
 // CHECK:         [[C1:%.*]] = constant 1 : index
 // CHECK:         scf.parallel ([[NEW_I:%.*]]) = ([[C0]]) to ([[C18]]) step ([[C1]]) {
 // CHECK:           [[I0_COUNT:%.*]] = remi_signed [[NEW_I]], [[C3]] : index
-// CHECK:           [[I1_COUNT:%.*]] = divi_signed [[NEW_I]], [[C6]] : index
-// CHECK:           [[VAL_10:%.*]] = muli [[I1_COUNT]], [[C4]] : index
-// CHECK:           [[I1:%.*]] = addi [[VAL_10]], [[C7]] : index
-// CHECK:           [[VAL_12:%.*]] = muli [[I0_COUNT]], [[C3]] : index
-// CHECK:           [[I0:%.*]] = addi [[VAL_12]], [[C3]] : index
+// CHECK:           [[I1_COUNT:%.*]] = divi_signed [[NEW_I]], [[C3]] : index
+// CHECK:           [[V0:%.*]] = muli [[I1_COUNT]], [[C4]] : index
+// CHECK:           [[I1:%.*]] = addi [[V0]], [[C7]] : index
+// CHECK:           [[V1:%.*]] = muli [[I0_COUNT]], [[C3]] : index
+// CHECK:           [[I0:%.*]] = addi [[V1]], [[C3]] : index
 // CHECK:           "magic.op"([[I0]], [[I1]]) : (index, index) -> index
 // CHECK:           scf.yield
 // CHECK-NEXT:    }


        


More information about the Mlir-commits mailing list