OSDN Git Service

[Thumb] Teach ISel how to lower compares of AND bitmasks efficiently
authorJames Molloy <james.molloy@arm.com>
Mon, 12 Sep 2016 14:30:48 +0000 (14:30 +0000)
committerJames Molloy <james.molloy@arm.com>
Mon, 12 Sep 2016 14:30:48 +0000 (14:30 +0000)
commit91db09d0e862832164c6c80c4d14f471d902429f
tree49402c35ac264883da1f8d30b0e1ab67f4124ec2
parentc04a5a1fc46d588a90a50d48be0aaa94c526bd9a
[Thumb] Teach ISel how to lower compares of AND bitmasks efficiently

For the common pattern (CMPZ (AND x, #bitmask), #0), we can do some more efficient instruction selection if the bitmask is one consecutive sequence of set bits (32 - clz(bm) - ctz(bm) == popcount(bm)).

1) If the bitmask touches the LSB, then we can remove all the upper bits and set the flags by doing one LSLS.
2) If the bitmask touches the MSB, then we can remove all the lower bits and set the flags with one LSRS.
3) If the bitmask has popcount == 1 (only one set bit), we can shift that bit into the sign bit with one LSLS and change the condition query from NE/EQ to MI/PL (we could also implement this by shifting into the carry bit and branching on BCC/BCS).
4) Otherwise, we can emit a sequence of LSLS+LSRS to remove the upper and lower zero bits of the mask.

1-3 require only one 16-bit instruction and can elide the CMP. 4 requires two 16-bit instructions but can elide the CMP and doesn't require materializing a complex immediate, so is also a win.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281215 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/ARM/ARMBaseInstrInfo.cpp
lib/Target/ARM/ARMISelDAGToDAG.cpp
test/CodeGen/ARM/and-cmpz.ll [new file with mode: 0644]
test/CodeGen/ARM/arm-and-tst-peephole.ll
test/CodeGen/ARM/arm-shrink-wrapping.ll
test/CodeGen/ARM/call-tc.ll
test/CodeGen/ARM/debug-info-branch-folding.ll
test/CodeGen/Thumb/thumb-shrink-wrapping.ll
test/CodeGen/Thumb2/float-ops.ll