[Mlir-commits] [mlir] d345ce6 - Mark arith.minf, arith.maxf as commutative.

Christian Sigg llvmlistbot at llvm.org
Tue Jan 11 08:47:58 PST 2022


Author: Christian Sigg
Date: 2022-01-11T17:47:53+01:00
New Revision: d345ce65ff0cf5e7cf4299d0659477ca7dbe6631

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

LOG: Mark arith.minf, arith.maxf as commutative.

Reviewed By: herhut

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td
    mlir/test/Dialect/Arithmetic/canonicalize.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td b/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td
index b57c05ab87e62..5f52e440c4da6 100644
--- a/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td
+++ b/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td
@@ -634,7 +634,7 @@ def Arith_SubFOp : Arith_FloatBinaryOp<"subf"> {
 // MaxFOp
 //===----------------------------------------------------------------------===//
 
-def Arith_MaxFOp : Arith_FloatBinaryOp<"maxf"> {
+def Arith_MaxFOp : Arith_FloatBinaryOp<"maxf", [Commutative]> {
   let summary = "floating-point maximum operation";
   let description = [{
     Syntax:
@@ -677,7 +677,7 @@ def Arith_MaxUIOp : Arith_IntBinaryOp<"maxui"> {
 // MinFOp
 //===----------------------------------------------------------------------===//
 
-def Arith_MinFOp : Arith_FloatBinaryOp<"minf"> {
+def Arith_MinFOp : Arith_FloatBinaryOp<"minf", [Commutative]> {
   let summary = "floating-point minimum operation";
   let description = [{
     Syntax:

diff  --git a/mlir/test/Dialect/Arithmetic/canonicalize.mlir b/mlir/test/Dialect/Arithmetic/canonicalize.mlir
index 8a17fa9d7f661..54259741b7a64 100644
--- a/mlir/test/Dialect/Arithmetic/canonicalize.mlir
+++ b/mlir/test/Dialect/Arithmetic/canonicalize.mlir
@@ -678,3 +678,16 @@ func @constant_UItoFP() -> f32 {
   %res = arith.sitofp %c0 : i32 to f32
   return %res : f32
 }
+
+// -----
+// CHECK-LABEL: @constant_MinMax(
+func @constant_MinMax(%arg0 : f32) -> f32 {
+  // CHECK:  %[[const:.+]] = arith.constant
+  // CHECK:  %[[min:.+]] = arith.minf %arg0, %[[const]] : f32
+  // CHECK:  %[[res:.+]] = arith.maxf %[[min]], %[[const]] : f32
+  // CHECK:   return %[[res]]
+  %const = arith.constant 0.0 : f32
+  %min = arith.minf %const, %arg0 : f32
+  %res = arith.maxf %const, %min : f32
+  return %res : f32
+}


        


More information about the Mlir-commits mailing list