diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2019-12-22 10:05:28 -0500 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2019-12-22 10:07:01 -0500 |
| commit | 9cdcd81d3f2e9c1c9ae1e054e24668d46bc08bfb (patch) | |
| tree | 709e27318a85008275f57a2e89da34ea9687b22d /llvm/lib/Transforms | |
| parent | dc5b614fa9a1c83e8275fcb9c3f78444d0a30514 (diff) | |
| download | bcm5719-llvm-9cdcd81d3f2e9c1c9ae1e054e24668d46bc08bfb.tar.gz bcm5719-llvm-9cdcd81d3f2e9c1c9ae1e054e24668d46bc08bfb.zip | |
[InstCombine] enhance fold for copysign with known sign arg
This is another optimization suggested in PRPR44153:
https://bugs.llvm.org/show_bug.cgi?id=44153
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 51006272646..f556c5fd4ab 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2286,18 +2286,22 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { break; } case Intrinsic::copysign: { - const APFloat *C; - if (match(II->getArgOperand(1), m_APFloat(C))) { - // If we know the sign bit of the sign argument, reduce to FABS/FNABS: - // copysign X, PosC --> fabs X - // copysign X, NegC --> fneg (fabs X) + if (SignBitMustBeZero(II->getArgOperand(1), &TLI)) { + // If we know that the sign argument is positive, reduce to FABS: + // copysign X, Pos --> fabs X Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, II->getArgOperand(0), II); - if (C->isNegative()) - Fabs = Builder.CreateFNegFMF(Fabs, II); - return replaceInstUsesWith(*II, Fabs); } + // TODO: There should be a ValueTracking sibling like SignBitMustBeOne. + const APFloat *C; + if (match(II->getArgOperand(1), m_APFloat(C)) && C->isNegative()) { + // If we know that the sign argument is negative, reduce to FNABS: + // copysign X, Neg --> fneg (fabs X) + Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, + II->getArgOperand(0), II); + return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II)); + } break; } case Intrinsic::fabs: { |

