From 02da9643506dee4a82353e0f911513279634d846 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Thu, 7 Apr 2022 10:06:50 +0200 Subject: [mlir][CSE] Remove duplicated operations with MemRead side-effect This patch enhances the CSE pass to deal with simple cases of duplicated operations with MemoryEffects. It allows the CSE pass to remove safely duplicate operations with the MemoryEffects::Read that have no other side-effecting operations in between. Other MemoryEffects::Read operation are allowed. The use case is pretty simple so far so we can build on top of it to add more features. This patch is also meant to avoid a dedicated CSE pass in FIR and was brought together afetr discussion on https://reviews.llvm.org/D112711. It does not currently cover the full range of use cases described in https://reviews.llvm.org/D112711 but the idea is to gradually enhance the MLIR CSE pass to handle common use cases that can be used by other dialects. This patch takes advantage of the new CSE capabilities in Fir. Reviewed By: mehdi_amini, rriddle, schweitz Differential Revision: https://reviews.llvm.org/D122801 --- mlir/test/Examples/Toy/Ch5/affine-lowering.mlir | 3 +-- mlir/test/Examples/Toy/Ch6/affine-lowering.mlir | 3 +-- mlir/test/Examples/Toy/Ch7/affine-lowering.mlir | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) (limited to 'mlir/test/Examples') diff --git a/mlir/test/Examples/Toy/Ch5/affine-lowering.mlir b/mlir/test/Examples/Toy/Ch5/affine-lowering.mlir index ad99faa..034474d 100644 --- a/mlir/test/Examples/Toy/Ch5/affine-lowering.mlir +++ b/mlir/test/Examples/Toy/Ch5/affine-lowering.mlir @@ -32,8 +32,7 @@ toy.func @main() { // CHECK: affine.for [[VAL_12:%.*]] = 0 to 3 { // CHECK: affine.for [[VAL_13:%.*]] = 0 to 2 { // CHECK: [[VAL_14:%.*]] = affine.load [[VAL_7]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> -// CHECK: [[VAL_15:%.*]] = affine.load [[VAL_7]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> -// CHECK: [[VAL_16:%.*]] = arith.mulf [[VAL_14]], [[VAL_15]] : f64 +// CHECK: [[VAL_16:%.*]] = arith.mulf [[VAL_14]], [[VAL_14]] : f64 // CHECK: affine.store [[VAL_16]], [[VAL_6]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> // CHECK: toy.print [[VAL_6]] : memref<3x2xf64> // CHECK: memref.dealloc [[VAL_8]] : memref<2x3xf64> diff --git a/mlir/test/Examples/Toy/Ch6/affine-lowering.mlir b/mlir/test/Examples/Toy/Ch6/affine-lowering.mlir index ca056b4..51dedaf 100644 --- a/mlir/test/Examples/Toy/Ch6/affine-lowering.mlir +++ b/mlir/test/Examples/Toy/Ch6/affine-lowering.mlir @@ -32,8 +32,7 @@ toy.func @main() { // CHECK: affine.for [[VAL_12:%.*]] = 0 to 3 { // CHECK: affine.for [[VAL_13:%.*]] = 0 to 2 { // CHECK: [[VAL_14:%.*]] = affine.load [[VAL_7]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> -// CHECK: [[VAL_15:%.*]] = affine.load [[VAL_7]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> -// CHECK: [[VAL_16:%.*]] = arith.mulf [[VAL_14]], [[VAL_15]] : f64 +// CHECK: [[VAL_16:%.*]] = arith.mulf [[VAL_14]], [[VAL_14]] : f64 // CHECK: affine.store [[VAL_16]], [[VAL_6]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> // CHECK: toy.print [[VAL_6]] : memref<3x2xf64> // CHECK: memref.dealloc [[VAL_8]] : memref<2x3xf64> diff --git a/mlir/test/Examples/Toy/Ch7/affine-lowering.mlir b/mlir/test/Examples/Toy/Ch7/affine-lowering.mlir index 60d466e..3cefd0e 100644 --- a/mlir/test/Examples/Toy/Ch7/affine-lowering.mlir +++ b/mlir/test/Examples/Toy/Ch7/affine-lowering.mlir @@ -32,8 +32,7 @@ toy.func @main() { // CHECK: affine.for [[VAL_12:%.*]] = 0 to 3 { // CHECK: affine.for [[VAL_13:%.*]] = 0 to 2 { // CHECK: [[VAL_14:%.*]] = affine.load [[VAL_7]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> -// CHECK: [[VAL_15:%.*]] = affine.load [[VAL_7]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> -// CHECK: [[VAL_16:%.*]] = arith.mulf [[VAL_14]], [[VAL_15]] : f64 +// CHECK: [[VAL_16:%.*]] = arith.mulf [[VAL_14]], [[VAL_14]] : f64 // CHECK: affine.store [[VAL_16]], [[VAL_6]]{{\[}}[[VAL_12]], [[VAL_13]]] : memref<3x2xf64> // CHECK: toy.print [[VAL_6]] : memref<3x2xf64> // CHECK: memref.dealloc [[VAL_8]] : memref<2x3xf64> -- cgit v1.1