https://gcc.gnu.org/g:ada5b8f08739b26bf76558c9d5157cbbdd16c205

commit r17-5778-gada5b8f08739b26bf76558c9d5157cbbdd16c205
Author: Richard Biener <[email protected]>
Date:   Sat Oct 31 15:34:53 2026 +0100

    tree-optimization/128322 - amend PR127377 fix
    
    The PR127377 fix fails to consider head padding when setting the
    new size after pruning the tail.  Fix that.
    
            PR tree-optimization/128322
            * tree-ssa-sccvn.cc (vn_walk_cb_data::push_partial_def):
            Properly consider head padding when pruning the tail for
            a non-constant def.
    
            * gcc.dg/torture/pr128322.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr128322.c | 24 ++++++++++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   |  5 +++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr128322.c 
b/gcc/testsuite/gcc.dg/torture/pr128322.c
new file mode 100644
index 000000000000..244fa3bed7d8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr128322.c
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+/* { dg-require-effective-target int32plus } */
+
+struct A { unsigned long long lo : 32, y : 19, rest : 13; };
+struct BF { unsigned long long x0:4, x1:8, x2:31, x3:3, x4:4, x5:14; };
+union U { unsigned char b[8]; struct A a; struct BF bf; };
+
+__attribute__((noipa)) unsigned
+f(union U *p, unsigned v)
+{
+  p->b[6] = 209;
+  p->a.y = v;
+  p->b[5] = 39;
+  return p->bf.x4;
+}
+
+int main()
+{
+  static union U x;
+  unsigned r = f(&x, 0x30000);
+  if (r != 12)
+    __builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 7d97bce77fa7..49557bb637a2 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -2081,8 +2081,9 @@ vn_walk_cb_data::push_partial_def (pd_data pd,
          pd.offset += o;
        }
       if (pd.size + pd.offset > offseti + maxsizei)
-       pd.size = maxsizei + ((pd.size + pd.offset - (offseti + maxsizei))
-                             % BITS_PER_UNIT);
+       pd.size = ((offseti - pd.offset + maxsizei)
+                  + ((pd.size + pd.offset - (offseti + maxsizei))
+                     % BITS_PER_UNIT));
     }
 
   pd.offset -= offseti;

Reply via email to