[Bug c/110491] Wrong code at -O2 on x86_64-linux-gnu (a recent regression)

2023-07-04 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110491

Richard Biener  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Richard Biener  ---
Fixed.

[Bug c/110491] Wrong code at -O2 on x86_64-linux-gnu (a recent regression)

2023-07-04 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110491

--- Comment #3 from CVS Commits  ---
The master branch has been updated by Richard Biener :

https://gcc.gnu.org/g:819285ef10a87d663f8c181c06aa88d1d9f75aed

commit r14-2296-g819285ef10a87d663f8c181c06aa88d1d9f75aed
Author: Richard Biener 
Date:   Tue Jul 4 12:52:27 2023 +0200

tree-optimization/110491 - PHI-OPT and undefs

The following makes sure to not make conditional undefs in PHI arguments
unconditional by folding cond ? arg1 : arg2.

PR tree-optimization/110491
* tree-ssa-phiopt.cc (match_simplify_replacement): Check
whether the PHI args are possibly undefined before folding
the COND_EXPR.

* gcc.dg/torture/pr110491.c: New testcase.

[Bug c/110491] Wrong code at -O2 on x86_64-linux-gnu (a recent regression)

2023-07-04 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110491

Richard Biener  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  ---
So the issue here is phiopt4 doing

[local count: 1073741824]:
-  if (c_lsm_flag.14_16 != 0)
-goto ; [66.67%]
-  else
-goto ; [33.33%]
-
-   [local count: 357913944]:
-
-   [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

   [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,

[Bug c/110491] Wrong code at -O2 on x86_64-linux-gnu (a recent regression)

2023-06-29 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110491

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #1 from Andrew Pinski  ---
Dup of bug 110228.



  # RANGE [irange] int [0, 1] NONZERO 0x1
  # c_lsm.10_3 = PHI <_17(D)(2), _11(5)>
...
  if (c_lsm_flag.11_16 != 0)
goto ; [66.67%]
  else
goto ; [33.33%]
;;succ:   7 [33.3% (adjusted)]  count:357913944 (estimated locally)
(FALSE_VALUE,EXECUTABLE)
;;8 [66.7% (adjusted)]  count:715827880 (estimated locally)
(TRUE_VALUE,EXECUTABLE)

;;   basic block 7, loop depth 0, count 357913944 (estimated locally), maybe
hot
;;prev block 6, next block 8, flags: (NEW)
;;pred:   6 [33.3% (adjusted)]  count:357913944 (estimated locally)
(FALSE_VALUE,EXECUTABLE)
;;succ:   8 [always]  count:357913944 (estimated locally) (FALLTHRU)

;;   basic block 8, loop depth 0, count 1073741824 (estimated locally), maybe
hot
;;prev block 7, next block 1, flags: (NEW, REACHABLE, VISITED)
;;pred:   7 [always]  count:357913944 (estimated locally) (FALLTHRU)
;;6 [66.7% (adjusted)]  count:715827880 (estimated locally)
(TRUE_VALUE,EXECUTABLE)
  # RANGE [irange] int [0, 1] NONZERO 0x1
  # prephitmp_27 = PHI <1(7), c_lsm.10_3(6)>

*** This bug has been marked as a duplicate of bug 110228 ***