diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-08-24 09:10:57 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-08-24 09:10:57 +0000 |
| commit | 0ffccf7fb525a1534eb69fe32574c418dcab9746 (patch) | |
| tree | 91ad63dca6bda86a82b1dfe01a689412de4b254d /llvm/lib/CodeGen/LLVMTargetMachine.cpp | |
| parent | 3a1f4c77df96565ecdf47a07b63ca53e46848cf6 (diff) | |
| download | bcm5719-llvm-0ffccf7fb525a1534eb69fe32574c418dcab9746.tar.gz bcm5719-llvm-0ffccf7fb525a1534eb69fe32574c418dcab9746.zip | |
InstCombine: Properly optimize or'ing bittests together
CFE, with -03, would turn:
bool f(unsigned x) {
bool a = x & 1;
bool b = x & 2;
return a | b;
}
into:
%1 = lshr i32 %x, 1
%2 = or i32 %1, %x
%3 = and i32 %2, 1
%4 = icmp ne i32 %3, 0
This sort of thing exposes a nasty pathology in GCC, ICC and LLVM.
Instead, we would rather want:
%1 = and i32 %x, 3
%2 = icmp ne i32 %1, 0
Things get a bit more interesting in the following case:
%1 = lshr i32 %x, %y
%2 = or i32 %1, %x
%3 = and i32 %2, 1
%4 = icmp ne i32 %3, 0
Replacing it with the following sequence is better:
%1 = shl nuw i32 1, %y
%2 = or i32 %1, 1
%3 = and i32 %2, %x
%4 = icmp ne i32 %3, 0
This sequence is preferable because %1 doesn't involve %x and could
potentially be hoisted out of loops if it is invariant; only perform
this transform in the non-constant case if we know we won't increase
register pressure.
llvm-svn: 216343
Diffstat (limited to 'llvm/lib/CodeGen/LLVMTargetMachine.cpp')
0 files changed, 0 insertions, 0 deletions

