llvm-6502/lib/Transforms/InstCombine
David Majnemer 5cbd5a13a4 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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216343 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-24 09:10:57 +00:00
..
CMakeLists.txt
InstCombine.h InstCombine: Fold ((A | B) & C1) ^ (B & C2) -> (A & C1) ^ B if C1^C2=-1 2014-08-21 05:14:48 +00:00
InstCombineAddSub.cpp InstCombine: sub nsw %x, C -> add nsw %x, -C if C isn't INT_MIN 2014-08-22 16:41:23 +00:00
InstCombineAndOrXor.cpp InstCombine: Fold ((A | B) & C1) ^ (B & C2) -> (A & C1) ^ B if C1^C2=-1 2014-08-21 05:14:48 +00:00
InstCombineCalls.cpp Canonicalization for @llvm.assume 2014-07-25 21:45:17 +00:00
InstCombineCasts.cpp Fix comment in InstCombiner::visitAddrSpaceCast. 2014-07-16 01:34:21 +00:00
InstCombineCompares.cpp InstCombine: Properly optimize or'ing bittests together 2014-08-24 09:10:57 +00:00
InstCombineLoadStoreAlloca.cpp AA metadata refactoring (introduce AAMDNodes) 2014-07-24 12:16:19 +00:00
InstCombineMulDivRem.cpp Remove an InstCombine that transformed patterns like (x * uitofp i1 y) to (select y, x, 0.0) when the multiply has fast math flags set. 2014-08-17 03:51:29 +00:00
InstCombinePHI.cpp Repace SmallPtrSet with SmallPtrSetImpl in function arguments to avoid needing to mention the size. 2014-08-21 05:55:13 +00:00
InstCombineSelect.cpp This removes TODO added in http://reviews.llvm.org/D3658 2014-06-12 14:06:00 +00:00
InstCombineShifts.cpp fixed typo in comment 2014-07-22 04:57:06 +00:00
InstCombineSimplifyDemanded.cpp InstCombine: Don't unconditionally preserve 'nuw' when shrinking constants 2014-08-22 17:11:04 +00:00
InstCombineVectorOps.cpp fixed some typos 2014-07-07 22:13:58 +00:00
InstCombineWorklist.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
InstructionCombining.cpp Repace SmallPtrSet with SmallPtrSetImpl in function arguments to avoid needing to mention the size. 2014-08-21 05:55:13 +00:00
LLVMBuild.txt
Makefile