[llvm] [InstCombine] Fold copysign(floor(fabs(X)), X) to trunc(X) (PR #200836)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 04:27:57 PDT 2026
================
@@ -3116,6 +3116,15 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
if (match(Mag, m_FAbs(m_Value(X))) || match(Mag, m_FNeg(m_Value(X))))
return replaceOperand(*II, 0, X);
+ // copysign(floor(fabs(X)), X) --> copysign(trunc(X), X)
+ // copysign ignores the sign bit of its magnitude argument (implicit fabs),
+ // so replacing floor(fabs(X)) with trunc(X) is correct for all inputs
+ // including NaN without requiring nnan.
+ if (match(Mag, m_Intrinsic<Intrinsic::floor>(m_FAbs(m_Specific(Sign))))) {
----------------
arsenm wrote:
Should this be stripSignOnlyFPOps instead of specifically matching fabs? would also cover fneg(fabs())
https://github.com/llvm/llvm-project/pull/200836
More information about the llvm-commits
mailing list