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

Tobias Gysi llvmlistbot at llvm.org
Fri Nov 8 10:28:23 PST 2024


================
@@ -508,6 +508,23 @@ class LLVM_CastOp<string mnemonic, string instName, Type type,
       $_location, $_resultType, $arg);
   }];
 }
+class LLVM_CastOpWithOverflowFlag<string mnemonic, string instName, Type type,
+                  Type resultType, list<Trait> traits = []> :
+    LLVM_Op<mnemonic, !listconcat([Pure], [DeclareOpInterfaceMethods<IntegerOverflowFlagsInterface>], traits)>,
+    LLVM_Builder<"$res = builder.Create" # instName # "($arg, $_resultType, /*Name=*/\"\", op.hasNoUnsignedWrap(), op.hasNoSignedWrap());"> {
+  let arguments = (ins type:$arg, EnumProperty<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags);
+  let results = (outs resultType:$res);
+  let builders = [LLVM_OneResultOpBuilder];
+  let assemblyFormat = "$arg attr-dict `` custom<OverflowFlags>($overflowFlags) `:` type($arg) `to` type($res)";
----------------
gysit wrote:

```suggestion
  let assemblyFormat = "$arg custom<OverflowFlags>($overflowFlags) `` attr-dict `:` type($arg) `to` type($res)";
```
nit: Can you move the attribute dictionary after the overflow flags. I think this is how it is done for the other operations that take overflow flags. 

I am somewhat surprised you don't need to elide overflow flags from the attribute dictionary when printing using `custom<LLVMOpAttrs>(attr-dict)`. Maybe tablegen does elide the flag since it is passed to a custom print function.


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


More information about the Mlir-commits mailing list