https://gcc.gnu.org/g:3a782326a3927032b5fafcebbb7fcd2f9842ee33

commit r17-5993-g3a782326a3927032b5fafcebbb7fcd2f9842ee33
Author: Richard Biener <[email protected]>
Date:   Fri Nov 6 09:11:55 2026 +0100

    tree-optimization/128464 - fix complex lowering for abnormals
    
    We're ignoring abnormal defs during analysis but we fail to set their
    lattice value.
    
            PR tree-optimization/128464
            * tree-complex.cc (complex_propagate::visit_stmt): Set
            abnormal def lattice value to VARYING.
            (complex_propagate::visit_phi): Likewise.
    
            * gcc.dg/torture/pr128464.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr128464.c | 31 +++++++++++++++++++++++++++++++
 gcc/tree-complex.cc                     | 16 ++++++++++++----
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr128464.c 
b/gcc/testsuite/gcc.dg/torture/pr128464.c
new file mode 100644
index 000000000000..43ab3ef7becd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr128464.c
@@ -0,0 +1,31 @@
+/* { dg-do run } */
+/* { dg-require-effective-target int32plus } */
+
+unsigned __attribute__((noipa))
+f(unsigned x, unsigned y)
+{
+  {
+    __label__ l1;
+    void g1(void) { goto l1; }
+  l1:;
+  }
+  _Complex unsigned z = 0, w;
+  __imag__ z = x;
+  __real__ w = 1;
+  __imag__ w = y;
+  z = ~(z * w);
+  {
+    __label__ l2;
+    void g2(void) { goto l2; }
+    g2();
+  l2:;
+  }
+  return __real__ z;
+}
+
+int main ()
+{
+  if (f(1, 1) != 4294967295)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-complex.cc b/gcc/tree-complex.cc
index e99abbab7f0d..b4752b7deb40 100644
--- a/gcc/tree-complex.cc
+++ b/gcc/tree-complex.cc
@@ -344,7 +344,7 @@ complex_propagate::visit_stmt (gimple *stmt, edge 
*taken_edge_p ATTRIBUTE_UNUSED
 
   lhs = gimple_get_lhs (stmt);
   /* Skip anything but GIMPLE_ASSIGN and GIMPLE_CALL with a lhs.  */
-  if (!lhs || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
+  if (!lhs)
     return SSA_PROP_VARYING;
 
   /* These conditions should be satisfied due to the initial filter
@@ -354,8 +354,13 @@ complex_propagate::visit_stmt (gimple *stmt, edge 
*taken_edge_p ATTRIBUTE_UNUSED
 
   *result_p = lhs;
   ver = SSA_NAME_VERSION (lhs);
-  old_l = complex_lattice_values[ver];
+  if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
+    {
+      complex_lattice_values[ver] = VARYING;
+      return SSA_PROP_VARYING;
+    }
 
+  old_l = complex_lattice_values[ver];
   switch (gimple_expr_code (stmt))
     {
     case SSA_NAME:
@@ -444,15 +449,18 @@ complex_propagate::visit_phi (gphi *phi)
      set up in init_dont_simulate_again.  */
   gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE);
 
+  ver = SSA_NAME_VERSION (lhs);
   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
-    return SSA_PROP_VARYING;
+    {
+      complex_lattice_values[ver] = VARYING;
+      return SSA_PROP_VARYING;
+    }
 
   /* We've set up the lattice values such that IOR neatly models PHI meet.  */
   new_l = UNINITIALIZED;
   for (i = gimple_phi_num_args (phi) - 1; i >= 0; --i)
     new_l |= find_lattice_value (gimple_phi_arg_def (phi, i));
 
-  ver = SSA_NAME_VERSION (lhs);
   old_l = complex_lattice_values[ver];
 
   if (new_l == old_l)

Reply via email to