Fix detection of valid BFC immediates.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75576 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Goodwin
2009-07-14 00:57:56 +00:00
parent 1a8d2d2d4f
commit c2ffd286af
2 changed files with 16 additions and 10 deletions

View File

@@ -168,16 +168,16 @@ def bf_inv_mask_imm : Operand<i32>,
uint32_t v = (uint32_t)N->getZExtValue(); uint32_t v = (uint32_t)N->getZExtValue();
if (v == 0xffffffff) if (v == 0xffffffff)
return 0; return 0;
// naive checker. should do better, but simple is best for now since it's // there can be 1's on either or both "outsides", all the "inside"
// more likely to be correct. // bits must be 0's
while (v & 1) v >>= 1; // shift off the leading 1's unsigned int lsb = 0, msb = 31;
if (v) while (v & (1 << msb)) --msb;
{ while (v & (1 << lsb)) ++lsb;
while (!(v & 1)) v >>=1; // shift off the mask for (unsigned int i = lsb; i <= msb; ++i) {
while (v & 1) v >>= 1; // shift off the trailing 1's if (v & (1 << i))
} return 0;
// if this is a mask for clearing a bitfield, what's left should be zero. }
return (v == 0); return 1;
}] > { }] > {
let PrintMethod = "printBitfieldInvMaskImmOperand"; let PrintMethod = "printBitfieldInvMaskImmOperand";
} }

View File

@@ -17,3 +17,9 @@ define i32 @f3(i32 %a) {
%tmp = and i32 %a, 4095 %tmp = and i32 %a, 4095
ret i32 %tmp ret i32 %tmp
} }
; 2147483646 = 0x7ffffffe not implementable w/ BFC
define i32 @f4(i32 %a) {
%tmp = and i32 %a, 2147483646
ret i32 %tmp
}