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'.
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