This avoids forwprop from matching DFP <-> FP vector conversions
using VEC_[UN]PACK{_TRUNC,_LO,_HI}.  Maybe DFP vectors shouldn't be
a thing, but they appearantly are.  Re-using CONVERT/NOP_EXPR for
DFP <-> FP conversions was probably a mistake.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2022-02-14  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/104511
        * tree-ssa-forwprop.c (simplify_vector_constructor): Avoid
        touching DFP <-> FP conversions.

        * gcc.dg/pr104511.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr104511.c | 16 ++++++++++++++++
 gcc/tree-ssa-forwprop.cc        |  9 +++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr104511.c

diff --git a/gcc/testsuite/gcc.dg/pr104511.c b/gcc/testsuite/gcc.dg/pr104511.c
new file mode 100644
index 00000000000..ad5430c67c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr104511.c
@@ -0,0 +1,16 @@
+/* { dg-do compile { target dfp } } */
+/* { dg-options "-O -Wno-psabi" } */
+
+typedef _Float64 __attribute__((__vector_size__ (32))) F;
+typedef _Decimal32 __attribute__((__vector_size__ (16))) D;
+
+extern void bar (void);
+
+D g;
+void
+foo (F f)
+{
+  D d = __builtin_convertvector (f, D);
+  bar ();
+  g = d;
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 709bde6defa..484491fa1c5 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -2824,6 +2824,15 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
                         ? VEC_UNPACK_FLOAT_HI_EXPR
                         : VEC_UNPACK_HI_EXPR);
 
+         /* Conversions between DFP and FP have no special tree code
+            but we cannot handle those since all relevant vector conversion
+            optabs only have a single mode.  */
+         if (CONVERT_EXPR_CODE_P (conv_code)
+             && FLOAT_TYPE_P (TREE_TYPE (type))
+             && (DECIMAL_FLOAT_TYPE_P (TREE_TYPE (type))
+                 != DECIMAL_FLOAT_TYPE_P (TREE_TYPE (conv_src_type))))
+           return false;
+
          if (CONVERT_EXPR_CODE_P (conv_code)
              && (2 * TYPE_PRECISION (TREE_TYPE (TREE_TYPE (orig[0])))
                  == TYPE_PRECISION (TREE_TYPE (type)))
-- 
2.34.1

Reply via email to