[llvm] [InstCombine] Fold copysign(floor(fabs(X)), X) to trunc(X) (PR #200836)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 07:59:25 PDT 2026
================
@@ -3116,6 +3116,16 @@ 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) --> trunc(X)
+ // Requires nnan: for NaN X the source returns a NaN with X's sign bit
+ // preserved (via copysign), but trunc(X) may return any NaN, making the
+ // target more undefined.
+ if (II->hasNoNaNs() &&
+ match(Mag, m_Intrinsic<Intrinsic::floor>(m_FAbs(m_Specific(Sign))))) {
----------------
arsenm wrote:
You can still do this without nnan by just reintroducing the fabs on the result
https://github.com/llvm/llvm-project/pull/200836
More information about the llvm-commits
mailing list