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.

Bootstrapped Regtested on aarch64-none-linux-gnu,
arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
-m32, -m64 and no issues.

Ok for master?

Thanks,
Tamar

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 
45d968446736335ef448da276f79ef7c06693b2e..e6929b1ca429a7981a1cc89daeb5a468dab02538
 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -10249,6 +10249,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)


-- 
diff --git a/gcc/match.pd b/gcc/match.pd
index 45d968446736335ef448da276f79ef7c06693b2e..e6929b1ca429a7981a1cc89daeb5a468dab02538 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -10249,6 +10249,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)

Reply via email to