middle-end/105965 - add missing v_c_e <{ el }> simplification
authorRichard Biener <rguenther@suse.de>
Tue, 14 Jun 2022 08:59:49 +0000 (10:59 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 19 Jul 2022 09:24:50 +0000 (11:24 +0200)
When we got the simplification of bit-field-ref to view-convert
we lost the ability to detect FMAs since we cannot look through

  _1 = {_10};
  _11 = VIEW_CONVERT_EXPR<float>(_1);

the following amends the (view_convert CONSTRUCTOR) pattern
to handle this case.

2022-06-14  Richard Biener  <rguenther@suse.de>

PR middle-end/105965
* match.pd (view_convert CONSTRUCTOR): Handle single-element
CTOR case.

* gcc.target/i386/pr105965.c: New testcase.

(cherry picked from commit 90467f0ad649d0817f9e034596a0fb85605b55af)

gcc/match.pd
gcc/testsuite/gcc.target/i386/pr105965.c [new file with mode: 0644]

index 6d691d3..fa59624 100644 (file)
@@ -3672,12 +3672,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
               && TYPE_UNSIGNED (TREE_TYPE (@1)))))
    (view_convert @1)))
 
-/* Simplify a view-converted empty constructor.  */
+/* Simplify a view-converted empty or single-element constructor.  */
 (simplify
   (view_convert CONSTRUCTOR@0)
-  (if (TREE_CODE (@0) != SSA_NAME
-       && CONSTRUCTOR_NELTS (@0) == 0)
-   { build_zero_cst (type); }))
+  (with
+   { tree ctor = (TREE_CODE (@0) == SSA_NAME
+                 ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); }
+   (switch
+    (if (CONSTRUCTOR_NELTS (ctor) == 0)
+     { build_zero_cst (type); })
+    (if (CONSTRUCTOR_NELTS (ctor) == 1
+        && VECTOR_TYPE_P (TREE_TYPE (ctor))
+        && operand_equal_p (TYPE_SIZE (type),
+                            TYPE_SIZE (TREE_TYPE
+                              (CONSTRUCTOR_ELT (ctor, 0)->value))))
+     (view_convert { CONSTRUCTOR_ELT (ctor, 0)->value; })))))
 
 /* Re-association barriers around constants and other re-association
    barriers can be removed.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr105965.c b/gcc/testsuite/gcc.target/i386/pr105965.c
new file mode 100644 (file)
index 0000000..5bb5379
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mfma -mfpmath=sse" } */
+
+typedef float v1sf __attribute__((vector_size(4)));
+
+v1sf
+foo43 (v1sf a, v1sf b, v1sf c)
+{
+  return a * b + c;
+}
+
+/* { dg-final { scan-assembler "fmadd" } } */