diff --git a/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td b/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td --- a/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td +++ b/mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td @@ -679,7 +679,7 @@ // MaxSIOp //===----------------------------------------------------------------------===// -def Arith_MaxSIOp : Arith_IntBinaryOp<"maxsi"> { +def Arith_MaxSIOp : Arith_IntBinaryOp<"maxsi", [Commutative]> { let summary = "signed integer maximum operation"; let hasFolder = 1; } @@ -688,7 +688,7 @@ // MaxUIOp //===----------------------------------------------------------------------===// -def Arith_MaxUIOp : Arith_IntBinaryOp<"maxui"> { +def Arith_MaxUIOp : Arith_IntBinaryOp<"maxui", [Commutative]> { let summary = "unsigned integer maximum operation"; let hasFolder = 1; } @@ -723,7 +723,7 @@ // MinSIOp //===----------------------------------------------------------------------===// -def Arith_MinSIOp : Arith_IntBinaryOp<"minsi"> { +def Arith_MinSIOp : Arith_IntBinaryOp<"minsi", [Commutative]> { let summary = "signed integer minimum operation"; let hasFolder = 1; } @@ -732,7 +732,7 @@ // MinUIOp //===----------------------------------------------------------------------===// -def Arith_MinUIOp : Arith_IntBinaryOp<"minui"> { +def Arith_MinUIOp : Arith_IntBinaryOp<"minui", [Commutative]> { let summary = "unsigned integer minimum operation"; let hasFolder = 1; } diff --git a/mlir/test/Dialect/Arithmetic/canonicalize.mlir b/mlir/test/Dialect/Arithmetic/canonicalize.mlir --- a/mlir/test/Dialect/Arithmetic/canonicalize.mlir +++ b/mlir/test/Dialect/Arithmetic/canonicalize.mlir @@ -682,6 +682,22 @@ return %0, %1, %2, %3: i8, i8, i8, i8 } +// CHECK-LABEL: test_maxsi2 +// CHECK: %[[C0:.+]] = arith.constant 42 +// CHECK: %[[MAX_INT_CST:.+]] = arith.constant 127 +// CHECK: %[[X:.+]] = arith.maxsi %arg0, %[[C0]] +// CHECK: return %arg0, %[[MAX_INT_CST]], %arg0, %[[X]] +func @test_maxsi2(%arg0 : i8) -> (i8, i8, i8, i8) { + %maxIntCst = arith.constant 127 : i8 + %minIntCst = arith.constant -128 : i8 + %c0 = arith.constant 42 : i8 + %0 = arith.maxsi %arg0, %arg0 : i8 + %1 = arith.maxsi %maxIntCst, %arg0: i8 + %2 = arith.maxsi %minIntCst, %arg0: i8 + %3 = arith.maxsi %c0, %arg0 : i8 + return %0, %1, %2, %3: i8, i8, i8, i8 +} + // ----- // CHECK-LABEL: test_maxui @@ -700,6 +716,22 @@ return %0, %1, %2, %3: i8, i8, i8, i8 } +// CHECK-LABEL: test_maxui +// CHECK: %[[C0:.+]] = arith.constant 42 +// CHECK: %[[MAX_INT_CST:.+]] = arith.constant -1 +// CHECK: %[[X:.+]] = arith.maxui %arg0, %[[C0]] +// CHECK: return %arg0, %[[MAX_INT_CST]], %arg0, %[[X]] +func @test_maxui2(%arg0 : i8) -> (i8, i8, i8, i8) { + %maxIntCst = arith.constant 255 : i8 + %minIntCst = arith.constant 0 : i8 + %c0 = arith.constant 42 : i8 + %0 = arith.maxui %arg0, %arg0 : i8 + %1 = arith.maxui %maxIntCst, %arg0 : i8 + %2 = arith.maxui %minIntCst, %arg0 : i8 + %3 = arith.maxui %c0, %arg0 : i8 + return %0, %1, %2, %3: i8, i8, i8, i8 +} + // ----- // CHECK-LABEL: test_minsi @@ -718,6 +750,22 @@ return %0, %1, %2, %3: i8, i8, i8, i8 } +// CHECK-LABEL: test_minsi +// CHECK: %[[C0:.+]] = arith.constant 42 +// CHECK: %[[MIN_INT_CST:.+]] = arith.constant -128 +// CHECK: %[[X:.+]] = arith.minsi %arg0, %[[C0]] +// CHECK: return %arg0, %arg0, %[[MIN_INT_CST]], %[[X]] +func @test_minsi2(%arg0 : i8) -> (i8, i8, i8, i8) { + %maxIntCst = arith.constant 127 : i8 + %minIntCst = arith.constant -128 : i8 + %c0 = arith.constant 42 : i8 + %0 = arith.minsi %arg0, %arg0 : i8 + %1 = arith.minsi %maxIntCst, %arg0 : i8 + %2 = arith.minsi %minIntCst, %arg0 : i8 + %3 = arith.minsi %c0, %arg0 : i8 + return %0, %1, %2, %3: i8, i8, i8, i8 +} + // ----- // CHECK-LABEL: test_minui @@ -736,6 +784,22 @@ return %0, %1, %2, %3: i8, i8, i8, i8 } +// CHECK-LABEL: test_minui +// CHECK: %[[C0:.+]] = arith.constant 42 +// CHECK: %[[MIN_INT_CST:.+]] = arith.constant 0 +// CHECK: %[[X:.+]] = arith.minui %arg0, %[[C0]] +// CHECK: return %arg0, %arg0, %[[MIN_INT_CST]], %[[X]] +func @test_minui2(%arg0 : i8) -> (i8, i8, i8, i8) { + %maxIntCst = arith.constant 255 : i8 + %minIntCst = arith.constant 0 : i8 + %c0 = arith.constant 42 : i8 + %0 = arith.minui %arg0, %arg0 : i8 + %1 = arith.minui %maxIntCst, %arg0 : i8 + %2 = arith.minui %minIntCst, %arg0 : i8 + %3 = arith.minui %c0, %arg0 : i8 + return %0, %1, %2, %3: i8, i8, i8, i8 +} + // ----- // CHECK-LABEL: @test_minf(