https://gcc.gnu.org/g:25eb892a8c1587ab720e92548874f0d600aa842e

commit r15-6914-g25eb892a8c1587ab720e92548874f0d600aa842e
Author: Tamar Christina <tamar.christ...@arm.com>
Date:   Wed Jan 15 13:58:00 2025 +0000

    middle-end: Fix incorrect type replacement in operands_equals [PR118472]
    
    In g:3c32575e5b6370270d38a80a7fa8eaa144e083d0 I made a mistake and 
incorrectly
    replaced the type of the arguments of an expression with the type of the
    expression.  This is of course wrong.
    
    This reverts that change and I have also double checked the other 
replacements
    and they are fine.
    
    gcc/ChangeLog:
    
            PR middle-end/118472
            * fold-const.cc (operand_compare::operand_equal_p): Fix incorrect
            replacement.
    
    gcc/testsuite/ChangeLog:
    
            PR middle-end/118472
            * gcc.dg/pr118472.c: New test.

Diff:
---
 gcc/fold-const.cc               |  3 ++-
 gcc/testsuite/gcc.dg/pr118472.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 501c6d8a54db..f9f7f4d2f917 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -3746,7 +3746,8 @@ operand_compare::operand_equal_p (tree type0, const_tree 
arg0,
             of op1.  Need to check to make sure they are the same.  */
          if (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
              && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
-             && TYPE_PRECISION (type0) != TYPE_PRECISION (type1))
+             && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 1)))
+                   != TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg1, 1))))
            return false;
          /* FALLTHRU */
 
diff --git a/gcc/testsuite/gcc.dg/pr118472.c b/gcc/testsuite/gcc.dg/pr118472.c
new file mode 100644
index 000000000000..dd842a6ae0fe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr118472.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fopenmp-simd" } */
+
+typedef int a;
+typedef struct {
+  a b __attribute__((__vector_size__(8)));
+} c;
+
+typedef a d __attribute__((__vector_size__(8)));
+c e, f, g;
+d h, j;
+void k() {
+  c l;
+  l.b[1] = 0;
+  c m = l;
+  __builtin_memcpy(&h, &m, sizeof(h));
+  j = h;
+  {
+    c l;
+    l.b[1] = 0;
+    m = l;
+    __builtin_memcpy(&h, &m, sizeof(h));
+    d m = j;
+    __builtin_memcpy(&g, &m, sizeof(g));
+    e = g;
+    m = h;
+    __builtin_memcpy(&g, &m, sizeof(g));
+#pragma omp simd
+    for (long i = 0; i < f.b[0]; i++)
+      f.b[i] = e.b[i] > g.b[i];
+  }
+}

Reply via email to