[Mlir-commits] [mlir] [mlir][LLVM] Add nsw and nuw flags (PR #74508)

Tobias Gysi llvmlistbot at llvm.org
Tue Dec 5 12:57:51 PST 2023


================
@@ -55,6 +55,21 @@ class LLVM_IntArithmeticOp<string mnemonic, string instName,
     $res = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
   }];
 }
+class LLVM_IntArithmeticOpWithFlag<string mnemonic, string instName,
+                                   list<Trait> traits = []> :
+    LLVM_ArithmeticOpBase<AnyInteger, mnemonic, instName,
+    !listconcat([DeclareOpInterfaceMethods<IntegerArithFlagsInterface>], traits)> {
+  dag iafArg = (
+    ins DefaultValuedAttr<LLVM_IntegerArithFlagsAttr, "{}">:$arithFlags);
+  let arguments = !con(commonArgs, iafArg);
+  string mlirBuilder = [{
+    auto op = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
+    moduleImport.setIntegerFlagsAttr(inst, op);
+    $res = op;
+  }];
+  let assemblyFormat = "$lhs `,` $rhs (`flags` ` ` $arithFlags^)? custom<LLVMOpAttrs>(attr-dict) `:` type($res)";
+  string llvmBuilder = "$res = builder.Create" # instName # "($lhs, $rhs, /*Name=*/\"\", op.hasNuw(), op.hasNsw());";
----------------
gysit wrote:

```suggestion
  string llvmBuilder = [{
    $res = builder.Create" # instName # "($lhs, $rhs, /*Name=*/"", op.hasNuw(), op.hasNsw());
  }];
```
nit: I would similarly try to fit this into the limits.

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


More information about the Mlir-commits mailing list