diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-04-12 15:11:33 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-04-12 15:11:33 +0000 |
commit | 33439f982bd6650c8b42574ade840983962e28a9 (patch) | |
tree | 992857407bc702cdf7a31b2de0880a13862d6d4d /llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | |
parent | 7184c44d66fdbe5876cf5c70f73cd1a76ef9628a (diff) | |
download | bcm5719-llvm-33439f982bd6650c8b42574ade840983962e28a9.tar.gz bcm5719-llvm-33439f982bd6650c8b42574ade840983962e28a9.zip |
[InstCombine] morph an existing instruction instead of creating a new one
One potential way to make InstCombine (very slightly?) faster is to recycle instructions
when possible instead of creating new ones. It's not explicitly stated AFAIK, but we don't
consider this an "InstSimplify". We could, however, make a new layer to house transforms
like this if that makes InstCombine more manageable (just throwing out an idea; not sure
how much opportunity is actually here).
Differential Revision: https://reviews.llvm.org/D31863
llvm-svn: 300067
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index ea8c0a6d38b..99a983ab474 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2408,13 +2408,12 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { } } - if (Constant *RHS = dyn_cast<Constant>(Op1)) { - if (RHS->isAllOnesValue() && Op0->hasOneUse()) - // xor (cmp A, B), true = not (cmp A, B) = !cmp A, B - if (CmpInst *CI = dyn_cast<CmpInst>(Op0)) - return CmpInst::Create(CI->getOpcode(), - CI->getInversePredicate(), - CI->getOperand(0), CI->getOperand(1)); + // xor (cmp A, B), true = not (cmp A, B) = !cmp A, B + ICmpInst::Predicate Pred; + if (match(Op0, m_OneUse(m_Cmp(Pred, m_Value(), m_Value()))) && + match(Op1, m_AllOnes())) { + cast<CmpInst>(Op0)->setPredicate(CmpInst::getInversePredicate(Pred)); + return replaceInstUsesWith(I, Op0); } if (ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1)) { |