From: Tamar Christina Date: Mon, 5 Jan 2026 20:54:35 +0000 (+0000) Subject: middle-end: extend fma -> fms transformation to conditional optab [PR122103] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=772b847d99d5e3d6caf40cead5ecf15575125059;p=thirdparty%2Fgcc.git middle-end: extend fma -> fms transformation to conditional optab [PR122103] Currently in the simplications between if-conversion and vect we rely on match.pd to rewrite FMA into FMS if the accumulator is on a negated value. However if if-conversion instead produces a COND_FMA then this doesn't work and so the vectorizer can't generate a vector FMS or it's other variant. This extends the rules to include the COND_FMA variants. Because this happens before the vectorization the vectorizer will take care of generating the LEN variants and as such we don't need match.pd to know about those. The added rules are the same as the ones directly above them just changing FMA to COND_FMA. gcc/ChangeLog: PR tree-optimization/122103 * match.pd: Add COND_FMA to COND_FMS rewrite rules. --- diff --git a/gcc/match.pd b/gcc/match.pd index ccdc1129e23..7753b258fc2 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -10266,6 +10266,64 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) (IFN_FMA @0 @1 @2)))) +(if (canonicalize_math_after_vectorization_p ()) + (for fmas (IFN_COND_FMA) + (simplify + (fmas:c @3 (negate @0) @1 @2 @4) + (IFN_COND_FNMA @3 @0 @1 @2 @4)) + (simplify + (fmas @3 @0 @1 (negate @2) @4) + (IFN_COND_FMS @0 @1 @2 @4)) + (simplify + (fmas:c @3 (negate @0) @1 (negate @2) @4) + (IFN_COND_FNMS @3 @0 @1 @2 @4)) + (simplify + (negate (fmas@3 @4 @0 @1 @2 @5)) + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) + (IFN_COND_FNMS @4 @0 @1 @2 @5)))) + + (simplify + (IFN_COND_FMS:c @3 (negate @0) @1 @2 @4) + (IFN_COND_FNMS @3 @0 @1 @2 @4)) + (simplify + (IFN_COND_FMS @3 @0 @1 (negate @2) @4) + (IFN_COND_FMA @3 @0 @1 @2 @4)) + (simplify + (IFN_COND_FMS:c @3 (negate @0) @1 (negate @2) @4) + (IFN_COND_FNMA @3 @0 @1 @2 @4)) + (simplify + (negate (IFN_FMS@3 @4 @0 @1 @2 @5)) + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) + (IFN_COND_FNMA @4 @0 @1 @2 @5))) + + (simplify + (IFN_COND_FNMA:c @3 (negate @0) @1 @2 @4) + (IFN_COND_FMA @3 @0 @1 @2 @4)) + (simplify + (IFN_COND_FNMA @3 @0 @1 (negate @2) @4) + (IFN_COND_FNMS @3 @0 @1 @2 @4)) + (simplify + (IFN_COND_FNMA:c @3 (negate @0) @1 (negate @2) @4) + (IFN_COND_FMS @3 @0 @1 @2 @4)) + (simplify + (negate (IFN_COND_FNMA@3 @4 @0 @1 @2 @5)) + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) + (IFN_COND_FMS @4 @0 @1 @2 @5))) + + (simplify + (IFN_COND_FNMS:c @3 (negate @0) @1 @2 @4) + (IFN_COND_FMS @3 @0 @1 @2 @4)) + (simplify + (IFN_COND_FNMS @3 @0 @1 (negate @2) @4) + (IFN_COND_FNMA @3 @0 @1 @2 @4)) + (simplify + (IFN_COND_FNMS:c @3 (negate @0) @1 (negate @2) @4) + (IFN_COND_FMA @3 @0 @1 @2 @4)) + (simplify + (negate (IFN_COND_FNMS@3 @4 @0 @1 @2 @5)) + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3)) + (IFN_COND_FMA @4 @0 @1 @2 @5)))) + /* CLZ simplifications. */ (for clz (CLZ) (for op (eq ne)