diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-04-13 17:36:24 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-04-13 17:36:24 +0000 |
commit | 9745d24a6658f01cbe296192cefb5a0b729cbf0d (patch) | |
tree | d2320198e5aca4d8d4eec605c6f56102751f6d4a /llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | |
parent | bdb8b58d160da0320d7ab0a751711842d3313a38 (diff) | |
download | bcm5719-llvm-9745d24a6658f01cbe296192cefb5a0b729cbf0d.tar.gz bcm5719-llvm-9745d24a6658f01cbe296192cefb5a0b729cbf0d.zip |
[InstCombine] use similar ops for related folds; NFCI
It's less efficient to produce 'ule' than 'ult' since we know we're going to
canonicalize to 'ult', but we shouldn't have duplicated code for these folds.
As a trade-off, this was a pretty terrible way to make a '2'. :)
if (LHSC == SubOne(RHSC))
AddC = ConstantExpr::getSub(AddOne(RHSC), LHSC);
The next steps are to share the code to fix PR32524 and add the missing 'and'
fold that was left out when PR14708 was fixed:
https://bugs.llvm.org/show_bug.cgi?id=14708
llvm-svn: 300222
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 2123f2a0b01..efe1c068300 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -881,11 +881,11 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) { // zero. if (LHSC->getValue() == 0 && RHSC->getValue().isAllOnesValue()) std::swap(LHSC, RHSC); - if (LHSC == SubOne(RHSC)) { // (X != 13 & X != 14) -> X-13 >u 1 - Constant *AddC = ConstantExpr::getNeg(LHSC); - Value *Add = Builder->CreateAdd(LHS0, AddC, LHS0->getName() + ".off"); - return Builder->CreateICmpUGT(Add, ConstantInt::get(Add->getType(), 1), - LHS0->getName() + ".cmp"); + if (LHSC == SubOne(RHSC)) { + // (X != 13 & X != 14) -> X-13 >u 1 + // An 'add' is the canonical IR form, so favor that over a 'sub'. + Value *Add = Builder->CreateAdd(LHS0, ConstantExpr::getNeg(LHSC)); + return Builder->CreateICmpUGT(Add, ConstantInt::get(Add->getType(), 1)); } break; // (X != 13 & X != 15) -> no change } @@ -1786,11 +1786,10 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, } if (LHSC == SubOne(RHSC)) { - // (X == 13 | X == 14) -> X-13 <u 2 - Constant *AddC = ConstantExpr::getNeg(LHSC); - Value *Add = Builder->CreateAdd(LHS0, AddC, LHS0->getName() + ".off"); - AddC = ConstantExpr::getSub(AddOne(RHSC), LHSC); - return Builder->CreateICmpULT(Add, AddC); + // (X == 13 | X == 14) -> X-13 <=u 1 + // An 'add' is the canonical IR form, so favor that over a 'sub'. + Value *Add = Builder->CreateAdd(LHS0, ConstantExpr::getNeg(LHSC)); + return Builder->CreateICmpULE(Add, ConstantInt::get(Add->getType(), 1)); } break; // (X == 13 | X == 15) -> no change |