From: Sanjay Patel Date: Thu, 13 Apr 2017 17:36:24 +0000 (+0000) Subject: [InstCombine] use similar ops for related folds; NFCI X-Git-Tag: llvmorg-5.0.0-rc1~7783 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9745d24a6658f01cbe296192cefb5a0b729cbf0d;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 2123f2a..efe1c06 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 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