[x86] try harder to match bitwise 'or' into an LEA
authorSanjay Patel <spatel@rotateright.com>
Mon, 9 Nov 2015 21:16:49 +0000 (21:16 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 9 Nov 2015 21:16:49 +0000 (21:16 +0000)
commit0e9a62e34fb4d4dca518ebfe88ff7695bc79516f
treee3cfe5c2c353b225adfc83c8472931408e07d39c
parent7fcebdc82ba1ad2265ad8869242ef988ec1b0c9b
[x86] try harder to match bitwise 'or' into an LEA

The motivation for this patch starts with the epic fail example in PR18007:
https://llvm.org/bugs/show_bug.cgi?id=18007

...unfortunately, this patch makes no difference for that case, but it solves some
simpler cases. We'll get there some day. :)

The current 'or' matching code was using computeKnownBits() via
isBaseWithConstantOffset() -> MaskedValueIsZero(), but that's an unnecessarily limited use.
We can do more by copying the logic in ValueTracking's haveNoCommonBitsSet(), so we can
treat the 'or' as if it was an 'add'.

There's a TODO comment here because we should lift the bit-checking logic into a helper
function, so it's not duplicated in DAGCombiner.

An example of the better LEA matching:

leal (%rdi,%rdi), %eax
andl $1, %esi
orl %esi, %eax

Becomes:

andl $1, %esi
leal (%rsi,%rdi,2), %eax

Differential Revision: http://reviews.llvm.org/D13956

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252515 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelDAGToDAG.cpp
test/CodeGen/X86/or-lea.ll
test/CodeGen/X86/x86-64-double-precision-shift-left.ll
test/CodeGen/X86/x86-64-double-precision-shift-right.ll