Fix detection of valid BFC immediates.
authorDavid Goodwin <david_goodwin@apple.com>
Tue, 14 Jul 2009 00:57:56 +0000 (00:57 +0000)
committerDavid Goodwin <david_goodwin@apple.com>
Tue, 14 Jul 2009 00:57:56 +0000 (00:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75576 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMInstrInfo.td
test/CodeGen/Thumb2/thumb2-bfc.ll

index b3a52d65f1756d89d7227a76cd3ea40baac6ed56..17e7365962b8d29beb7ec63fb6ffd441d2abed9b 100644 (file)
@@ -168,16 +168,16 @@ def bf_inv_mask_imm : Operand<i32>,
   uint32_t v = (uint32_t)N->getZExtValue();
   if (v == 0xffffffff)
     return 0;
-  // naive checker. should do better, but simple is best for now since it's
-  // more likely to be correct.
-  while (v & 1) v >>= 1;    // shift off the leading 1's
-  if (v)
-    {
-      while (!(v & 1)) v >>=1;  // shift off the mask
-      while (v & 1) v >>= 1;    // shift off the trailing 1's
-    }
-  // if this is a mask for clearing a bitfield, what's left should be zero.
-  return (v == 0);
+  // there can be 1's on either or both "outsides", all the "inside"
+  // bits must be 0's
+  unsigned int lsb = 0, msb = 31;
+  while (v & (1 << msb)) --msb;
+  while (v & (1 << lsb)) ++lsb;
+  for (unsigned int i = lsb; i <= msb; ++i) {
+    if (v & (1 << i))
+      return 0;
+  }
+  return 1;
 }] > {
   let PrintMethod = "printBitfieldInvMaskImmOperand";
 }
index 1e5016c91294bb8a392409b11001b21daa7569ef..a612b9bb888d9d4167fd00197a5e037879bd4b9e 100644 (file)
@@ -17,3 +17,9 @@ define i32 @f3(i32 %a) {
     %tmp = and i32 %a, 4095
     ret i32 %tmp
 }
+
+; 2147483646 = 0x7ffffffe   not implementable w/ BFC
+define i32 @f4(i32 %a) {
+    %tmp = and i32 %a, 2147483646
+    ret i32 %tmp
+}