[llvm] [InstCombine] Add fold for fabs(-x) -> fabs(x) (PR #95627)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 17 02:34:29 PDT 2024
================
@@ -2514,9 +2514,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
Value* Arg = II->getArgOperand(0);
Value* X;
// fabs (-X) --> fabs (X)
- if (match(Arg, m_FNeg(m_Value(X))))
- return replaceInstUsesWith(
- CI, Builder.CreateUnaryIntrinsic(Intrinsic::fabs, X));
+ if (match(Arg, m_FNeg(m_Value(X)))) {
+ CallInst *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, X);
+ Fabs->copyFastMathFlags(II);
----------------
arsenm wrote:
You can also pass the II as the 3rd argument to CreateUnaryIntrinsic as the FMFSource (though this will need adjustment depending on how this is extended to handle copysign)
https://github.com/llvm/llvm-project/pull/95627
More information about the llvm-commits
mailing list