]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: extend fma -> fms transformation to conditional optab [PR122103]
authorTamar Christina <tamar.christina@arm.com>
Mon, 5 Jan 2026 20:54:35 +0000 (20:54 +0000)
committerTamar Christina <tamar.christina@arm.com>
Mon, 5 Jan 2026 20:54:35 +0000 (20:54 +0000)
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.

gcc/match.pd

index ccdc1129e23e348c9fffda67e504c0c1032d2611..7753b258fc23f6e4cf7d3c95f3e597465cafc687 100644 (file)
@@ -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)