diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2017-04-05 17:57:05 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2017-04-05 17:57:05 +0000 |
| commit | 50c82c439518eb40a1fe875fe23dd581d4764c0d (patch) | |
| tree | 3343b86bca4e711c90c60d897851b6015c31b604 /llvm/lib/Transforms | |
| parent | 4ecee77c9aeb4928efbf5d5cf107ab9996e7407e (diff) | |
| download | bcm5719-llvm-50c82c439518eb40a1fe875fe23dd581d4764c0d.tar.gz bcm5719-llvm-50c82c439518eb40a1fe875fe23dd581d4764c0d.zip | |
[InstCombine] add fold for icmp with or mask of low bits (PR32542)
We already have these 'and' folds:
// X & -C == -C -> X > u ~C
// X & -C != -C -> X <= u ~C
// iff C is a power of 2
...but we were missing the 'or' siblings.
http://rise4fun.com/Alive/n6
This should improve:
https://bugs.llvm.org/show_bug.cgi?id=32524
...but there are 2 or more other pieces to fix still.
Differential Revision: https://reviews.llvm.org/D31712
llvm-svn: 299570
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 69bc38e8c76..2419d4f3288 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1794,6 +1794,15 @@ Instruction *InstCombiner::foldICmpOrConstant(ICmpInst &Cmp, BinaryOperator *Or, ConstantInt::get(V->getType(), 1)); } + // X | C == C --> X <=u C + // X | C != C --> X >u C + // iff C+1 is a power of 2 (C is a bitmask of the low bits) + if (Cmp.isEquality() && Cmp.getOperand(1) == Or->getOperand(1) && + (*C + 1).isPowerOf2()) { + Pred = (Pred == CmpInst::ICMP_EQ) ? CmpInst::ICMP_ULE : CmpInst::ICMP_UGT; + return new ICmpInst(Pred, Or->getOperand(0), Or->getOperand(1)); + } + if (!Cmp.isEquality() || *C != 0 || !Or->hasOneUse()) return nullptr; |

