[Mlir-commits] [mlir] [mlir][emitc] Support conversion of arith.divsi and arith.remsi to EmitC (PR #93450)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue May 28 02:15:17 PDT 2024


https://github.com/josel-amd updated https://github.com/llvm/llvm-project/pull/93450

>From d71003cc03b32a0394cc831ee1cf3563bd3f3c8f Mon Sep 17 00:00:00 2001
From: Jose Lopes <jose.lopes at amd.com>
Date: Mon, 27 May 2024 08:00:19 +0100
Subject: [PATCH 1/2] Support conversion of arith.divsi and arith.remsi to
 EmitC

---
 .../lib/Conversion/ArithToEmitC/ArithToEmitC.cpp |  2 ++
 .../Conversion/ArithToEmitC/arith-to-emitc.mlir  | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
index 0be3d76f556de..75c69cfe7e246 100644
--- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
+++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
@@ -394,6 +394,8 @@ void mlir::populateArithToEmitCPatterns(TypeConverter &typeConverter,
     ArithConstantOpConversionPattern,
     ArithOpConversion<arith::AddFOp, emitc::AddOp>,
     ArithOpConversion<arith::DivFOp, emitc::DivOp>,
+    ArithOpConversion<arith::DivSIOp, emitc::DivOp>,
+    ArithOpConversion<arith::RemSIOp, emitc::RemOp>,
     ArithOpConversion<arith::MulFOp, emitc::MulOp>,
     ArithOpConversion<arith::SubFOp, emitc::SubOp>,
     IntegerOpConversion<arith::AddIOp, emitc::AddOp>,
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
index b453b69a214e8..0cbee321b7e7f 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
+++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
@@ -88,6 +88,22 @@ func.func @arith_index(%arg0: index, %arg1: index) {
 
 // -----
 
+func.func @arith_signed_integer_div(%arg0: i32, %arg1: i32) {
+  // CHECK: emitc.div %arg0, %arg1 : (i32, i32) -> i32
+  %0 = arith.divsi %arg0, %arg1 : i32
+  return
+}
+
+// -----
+
+func.func @arith_signed_integer_rem(%arg0: i32, %arg1: i32) {
+  // CHECK: emitc.rem %arg0, %arg1 : (i32, i32) -> i32
+  %0 = arith.remsi %arg0, %arg1 : i32
+  return
+}
+
+// -----
+
 func.func @arith_select(%arg0: i1, %arg1: tensor<8xi32>, %arg2: tensor<8xi32>) -> () {
   // CHECK: [[V0:[^ ]*]] = emitc.conditional %arg0, %arg1, %arg2 : tensor<8xi32>
   %0 = arith.select %arg0, %arg1, %arg2 : i1, tensor<8xi32>

>From b3ac2846cb648ec04db42256b449ad087fa246a3 Mon Sep 17 00:00:00 2001
From: Jose Lopes <jose.lopes at amd.com>
Date: Tue, 28 May 2024 09:21:57 +0100
Subject: [PATCH 2/2] Respect lexicographic order and merge the tests for divsi
 and remsi

---
 mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp     | 2 +-
 mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
index 75c69cfe7e246..388794ec122d2 100644
--- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
+++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
@@ -395,8 +395,8 @@ void mlir::populateArithToEmitCPatterns(TypeConverter &typeConverter,
     ArithOpConversion<arith::AddFOp, emitc::AddOp>,
     ArithOpConversion<arith::DivFOp, emitc::DivOp>,
     ArithOpConversion<arith::DivSIOp, emitc::DivOp>,
-    ArithOpConversion<arith::RemSIOp, emitc::RemOp>,
     ArithOpConversion<arith::MulFOp, emitc::MulOp>,
+    ArithOpConversion<arith::RemSIOp, emitc::RemOp>,
     ArithOpConversion<arith::SubFOp, emitc::SubOp>,
     IntegerOpConversion<arith::AddIOp, emitc::AddOp>,
     IntegerOpConversion<arith::MulIOp, emitc::MulOp>,
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
index 0cbee321b7e7f..1c7848213de94 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
+++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
@@ -88,17 +88,18 @@ func.func @arith_index(%arg0: index, %arg1: index) {
 
 // -----
 
-func.func @arith_signed_integer_div(%arg0: i32, %arg1: i32) {
+// CHECK-LABEL: arith_signed_integer_div_rem
+func.func @arith_signed_integer_div_rem(%arg0: i32, %arg1: i32) {
   // CHECK: emitc.div %arg0, %arg1 : (i32, i32) -> i32
   %0 = arith.divsi %arg0, %arg1 : i32
+  // CHECK: emitc.rem %arg0, %arg1 : (i32, i32) -> i32
+  %1 = arith.remsi %arg0, %arg1 : i32
   return
 }
 
 // -----
 
 func.func @arith_signed_integer_rem(%arg0: i32, %arg1: i32) {
-  // CHECK: emitc.rem %arg0, %arg1 : (i32, i32) -> i32
-  %0 = arith.remsi %arg0, %arg1 : i32
   return
 }
 



More information about the Mlir-commits mailing list