[Mlir-commits] [mlir] [MLIR] Update APInt construction to correctly set isSigned/implicitTrunc (PR #110466)

Nikita Popov llvmlistbot at llvm.org
Tue Oct 8 04:14:30 PDT 2024


================
@@ -701,8 +701,10 @@ def Builtin_IntegerAttr : Builtin_Attr<"Integer", "integer",
         return $_get(type.getContext(), type, apValue);
       }
 
+      // TODO: Avoid implicit trunc?
       IntegerType intTy = ::llvm::cast<IntegerType>(type);
-      APInt apValue(intTy.getWidth(), value, intTy.isSignedInteger());
+      APInt apValue(intTy.getWidth(), value, intTy.isSignedInteger(),
+                    /*implicitTrunc=*/true);
----------------
nikic wrote:

The "proper" solution here is probably to either a) Only allow constructing signless integers from APInt or b) only allow constructing them from plain integers for bit widths <= 64 bit, as the sign distinction only becomes really problematic for larger bit widths.

But in any case, this is not something I want to touch in this PR...

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


More information about the Mlir-commits mailing list