https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110491

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot 
gnu.org
             Status|RESOLVED                    |ASSIGNED
         Resolution|DUPLICATE                   |---
   Last reconfirmed|                            |2023-07-04

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
So the issue here is phiopt4 doing

   <bb 6> [local count: 1073741824]:
-  if (c_lsm_flag.14_16 != 0)
-    goto <bb 8>; [66.67%]
-  else
-    goto <bb 7>; [33.33%]
-
-  <bb 7> [local count: 357913944]:
-
-  <bb 8> [local count: 1073741824]:
+  _26 = ~c_lsm_flag.14_16;
+  _14 = (int) _26;
   # RANGE [irange] int [0, 1] NONZERO 0x1
-  # prephitmp_27 = PHI <1(7), c_lsm.13_3(6)>
-  c = prephitmp_27;
+  _4 = c_lsm.13_3 | _14;
+  c = _4;
   return;

via

phiopt match-simplify trying:
       c_lsm_flag.14_16 != 0 ? c_lsm.13_3 : 1
Matching expression match.pd:1991, gimple-match-5.cc:23
Matching expression match.pd:1991, gimple-match-5.cc:23
Matching expression match.pd:1991, gimple-match-5.cc:23
Matching expression match.pd:1948, gimple-match-7.cc:20
Matching expression match.pd:2480, gimple-match-4.cc:35
Matching expression match.pd:2483, gimple-match-3.cc:66
Matching expression match.pd:2490, gimple-match-2.cc:58
Applying pattern match.pd:6459, gimple-match-10.cc:12767
Applying pattern match.pd:1378, gimple-match-5.cc:7352
Applying pattern match.pd:1886, gimple-match-1.cc:1232
Applying pattern match.pd:4748, gimple-match-4.cc:15651
Folded into the sequence:
_13 = (int) c_lsm_flag.14_16;
_26 = ~c_lsm_flag.14_16;
_14 = (int) _26;
_4 = c_lsm.13_3 | _14;
Removing basic block 7

but

  <bb 3> [local count: 9761289309]:
  # RANGE [irange] int [0, 1] NONZERO 0x1
  # c_lsm.13_3 = PHI <_17(D)(2), _11(5)>

so we have an uninitialized use here.  The following fixes this.

diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 31a7c39e405..467c9fd108a 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -785,6 +785,13 @@ match_simplify_replacement (basic_block cond_bb,
basic_block middle_bb,
       arg_false = arg0;
     }

+  /* Do not make conditional undefs unconditional.  */
+  if ((TREE_CODE (arg_true) == SSA_NAME
+       && ssa_name_maybe_undef_p (arg_true))
+      || (TREE_CODE (arg_false) == SSA_NAME
+         && ssa_name_maybe_undef_p (arg_false)))
+    return false;
+
   tree type = TREE_TYPE (gimple_phi_result (phi));
   result = gimple_simplify_phiopt (early_p, type, stmt,
                                   arg_true, arg_false,

Reply via email to