diff options
author | Craig Topper <craig.topper@intel.com> | 2018-05-23 17:29:03 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2018-05-23 17:29:03 +0000 |
commit | 3b768e8602cd1d739aaa7d0709aead5a38b47a23 (patch) | |
tree | 9b70644690793eab1b90dc9944fee1d190e7541c /llvm/lib/Transforms | |
parent | 03bce2b4a597a7fe1a35324d769b03aa209fab49 (diff) | |
download | bcm5719-llvm-3b768e8602cd1d739aaa7d0709aead5a38b47a23.tar.gz bcm5719-llvm-3b768e8602cd1d739aaa7d0709aead5a38b47a23.zip |
[InstCombine] Negate ABS/NABS patterns by swapping the select operands to remove the negation
Differential Revision: https://reviews.llvm.org/D47236
llvm-svn: 333101
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 0df56bd0c07..1e4c38c4c84 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1628,6 +1628,22 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { Value *ShAmtOp = cast<Instruction>(Op1)->getOperand(1); return BinaryOperator::CreateLShr(X, ShAmtOp); } + + if (Op1->hasOneUse()) { + Value *LHS, *RHS; + SelectPatternFlavor SPF = matchSelectPattern(Op1, LHS, RHS).Flavor; + if (SPF == SPF_ABS || SPF == SPF_NABS) { + // This is a negate of an ABS/NABS pattern. Just swap the operands + // of the select. + SelectInst *SI = cast<SelectInst>(Op1); + Value *TrueVal = SI->getTrueValue(); + Value *FalseVal = SI->getFalseValue(); + SI->setTrueValue(FalseVal); + SI->setFalseValue(TrueVal); + // Don't swap prof metadata, we didn't change the branch behavior. + return replaceInstUsesWith(I, SI); + } + } } // Turn this into a xor if LHS is 2^n-1 and the remaining bits are known |