]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/110496 - TYPE_PRECISION issue with store-merging
authorRichard Biener <rguenther@suse.de>
Fri, 30 Jun 2023 10:03:26 +0000 (12:03 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 30 Jun 2023 10:59:36 +0000 (12:59 +0200)
When store-merging looks for bswap opportunities we also handle
BIT_FIELD_REFs where we verify the refed object is of scalar
type but we don't check for the result type we eventually use.
That's done later but after we eventually query TYPE_PRECISION.
The following re-orders this.

PR tree-optimization/110496
* gimple-ssa-store-merging.cc (find_bswap_or_nop_1): Re-order
verifying and TYPE_PRECISION query for the BIT_FIELD_REF case.

* gcc.dg/pr110496.c: New testcase.

gcc/gimple-ssa-store-merging.cc
gcc/testsuite/gcc.dg/pr110496.c [new file with mode: 0644]

index 401496a923173dc69e941a45b340f39fa701664a..0d19b98ed73f3db68a54d1b807d6e1ad65b70a2d 100644 (file)
@@ -650,10 +650,13 @@ find_bswap_or_nop_1 (gimple *stmt, struct symbolic_number *n, int limit)
 
          /* Convert.  */
          n->type = TREE_TYPE (rhs1);
+         if (!verify_symbolic_number_p (n, stmt))
+           return NULL;
+
          if (!n->base_addr)
            n->range = TYPE_PRECISION (n->type) / BITS_PER_UNIT;
 
-         return verify_symbolic_number_p (n, stmt) ? stmt : NULL;
+         return stmt;
        }
 
       return NULL;
diff --git a/gcc/testsuite/gcc.dg/pr110496.c b/gcc/testsuite/gcc.dg/pr110496.c
new file mode 100644 (file)
index 0000000..3c3d12f
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+long contents, f_num;
+int decide();
+int f_MV0__x;
+void f() {
+  unsigned char *rptr;
+  unsigned char valbuf[6];
+  rptr = (unsigned char *)contents;
+  if (decide())
+    do {
+      __builtin_memcpy(valbuf, &f_MV0__x, sizeof(int));
+      (&valbuf[0])[4] = (&valbuf[0])[5] = 0;
+    } while (0);
+  else {
+    int MV0__x = f_num;
+    __builtin_memcpy(valbuf, &MV0__x, sizeof(int));
+    (&valbuf[0])[4] = (&valbuf[0])[5] = 0;
+  }
+  rptr[1] = valbuf[4];
+  rptr[2] = valbuf[5];
+  rptr[4] = valbuf[1];
+  rptr[5] = valbuf[2];
+  __builtin_memset(valbuf, 0, 8);
+}