[LLVMdev] tblgen and sign-extended constants too large for type

Scott Michel scottm at rushg.aero.org
Fri Feb 8 18:43:52 PST 2008


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)) + "'!");
+	      }
+	    }




More information about the llvm-dev mailing list