[LLVMdev] tblgen and sign-extended constants too large for type
Scott Michel
scottm at aero.org
Mon Feb 11 18:15:08 PST 2008
Allow me to rephrase my question: How much agony and gnashing of
teeth will I cause if I commit this patch to tblgen (fully tested and
changes to DAGISelEmitter.cpp also committed)?
-scooter
On Feb 8, 2008, at 6:43 PM, Scott Michel wrote:
> Question: How hard should tblgen try to fit constants into a
> particular
> type?
>
> My case is an xor with i8 immediate where I'm using 0xff in as the
> immediate value. 0xff should fit into i8 if treated as unsigned, but
> CodeGenDAGPatterns.cpp assumes that any and all integers less than
> 32-bits are signed.
>
> Should tblgen try to see if the sign-extended version of the constant
> could fit into the type, and failing that, try the unsigned version:
>
> Index: utils/TableGen/CodeGenDAGPatterns.cpp
> ===================================================================
> --- utils/TableGen/CodeGenDAGPatterns.cpp (revision 8028)
> +++ utils/TableGen/CodeGenDAGPatterns.cpp (working copy)
> @@ -685,10 +685,17 @@
> // Make sure that the value is representable for this type.
> if (Size < 32) {
> int Val = (II->getValue() << (32-Size)) >> (32-Size);
> - if (Val != II->getValue())
> - TP.error("Sign-extended integer value '" +
> itostr(II->getValue())+
> - "' is out of range for type '" +
> - getEnumName(getTypeNum(0)) + "'!");
> + if (Val != II->getValue()) {
> + // If sign-extended doesn't fit, does it fit as unsigned?
> + unsigned ValueMask = unsigned(MVT::getIntVTBitMask(VT));
> + unsigned UnsignedVal = unsigned(II->getValue());
> +
> + if ((ValueMask & UnsignedVal) != UnsignedVal) {
> + TP.error("Integer value '" + itostr(II->getValue())+
> + "' is out of range for type '" +
> + getEnumName(getTypeNum(0)) + "'!");
> + }
> + }
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list