[Mlir-commits] [mlir] [mlir][arith] Overflow flags propagation in arith canonicalizations. (PR #91646)

Tobias Gysi llvmlistbot at llvm.org
Sat May 11 10:33:46 PDT 2024


================
@@ -1051,6 +1193,17 @@ func.func @addiMuliToSubiLhsI32(%arg0: i32, %arg1: i32) -> i32 {
   return %add : i32
 }
 
+// CHECK-LABEL: @addiMuliToSubiLhsI32Ovf
+//  CHECK-SAME:   (%[[ARG0:.+]]: i32, %[[ARG1:.+]]: i32)
+//       CHECK:   %[[SUB:.+]] = arith.subi %[[ARG0]], %[[ARG1]] overflow<nsw, nuw> : i32
+//       CHECK:   return %[[SUB]]
+func.func @addiMuliToSubiLhsI32Ovf(%arg0: i32, %arg1: i32) -> i32 {
----------------
gysit wrote:

Nice!

Looks like the patterns that convert add <-> sub seem to be tricky, probably because addition uses an unsigned overflow to implement subtraction? So maybe dropping the nuw flag helps.


https://github.com/llvm/llvm-project/pull/91646


More information about the Mlir-commits mailing list