[Bug tree-optimization/108783] [13 Regression] ICE: verify_flow_info failed (error: returns_twice call is not first in basic block 3)

2023-02-16 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108783

Jakub Jelinek  changed:

   What|Removed |Added

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

--- Comment #7 from Jakub Jelinek  ---
Fixed.

[Bug tree-optimization/108783] [13 Regression] ICE: verify_flow_info failed (error: returns_twice call is not first in basic block 3)

2023-02-16 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108783

--- Comment #6 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:55db240d28d29aac90a2d2af3768283ba6288752

commit r13-6074-g55db240d28d29aac90a2d2af3768283ba6288752
Author: Jakub Jelinek 
Date:   Thu Feb 16 10:41:18 2023 +0100

reassoc: Fix up (ab) handling in eliminate_redundant_comparison [PR108783]

The following testcase ICEs because eliminate_redundant_comparison sees
redundant comparisons in &&/|| where the comparison has (ab) SSA_NAME,
maybe_fold_{and,or}_comparisons optimizes them into a single comparison
and build_and_add_sum emits a new comparison close to the definition
operands, which in this case is before a returns_twice call (which is
invalid).  Generally reassoc just punts on (ab) SSA_NAMEs, declares them
non-reassociable etc., so the second half of this patch does that.

Though we can do better in this case; the function has special code
when maybe_fold_{and,or}_comparisons returns INTEGER_CST (false/true)
or when what it returns is the same as curr->op (the first of the
comparisons we are considering) - in that case we just remove the
second one and keep the first one.  The reason it doesn't match is that
curr->op is a SSA_NAME whose SSA_NAME_DEF_STMT is checked to be a
comparison, in this case _42 = a_1(ab) != 0 and the other comparison
is also like that.  maybe_fold_{and,or}_comparisons looks through the
definitions though and so returns a_1(ab) != 0 as tree.
So the first part of the patch checks whether that returned comparison
isn't the same as the curr->op comparison and if yes, it just overrides
t back to curr->op so that its SSA_NAME is reused.  In that case we can
handle even (ab) in {,new}op{1,2} because we don't create a new comparison
of that, just keep using the existing one.  And t can't be (ab) because
otherwise it wouldn't be considered a reassociable operand.

The (ab) checks are needed say when we have a_1(ab) == 42 || a_1(ab) > 42
kind of comparisons where maybe_fold_{and,or}_comparisons returns a new
comparison not existing in the IL yet.

2023-02-16  Jakub Jelinek  

PR tree-optimization/108783
* tree-ssa-reassoc.cc (eliminate_redundant_comparison): If lcode
is equal to TREE_CODE (t), op1 to newop1 and op2 to newop2, set
t to curr->op.  Otherwise, punt if either newop1 or newop2 are
SSA_NAME_OCCURS_IN_ABNORMAL_PHI SSA_NAMEs.

* gcc.c-torture/compile/pr108783.c: New test.

[Bug tree-optimization/108783] [13 Regression] ICE: verify_flow_info failed (error: returns_twice call is not first in basic block 3)

2023-02-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108783

Jakub Jelinek  changed:

   What|Removed |Added

  Attachment #54465|0   |1
is obsolete||

--- Comment #5 from Jakub Jelinek  ---
Created attachment 54466
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54466&action=edit
gcc13-pr108783.patch

Better patch.  In the original testcase, a && a can be simplified to a despite
being (ab), and generally, there is no need to build_and_add_sum if t is the
same comparison as curr->op.

[Bug tree-optimization/108783] [13 Regression] ICE: verify_flow_info failed (error: returns_twice call is not first in basic block 3)

2023-02-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108783

Jakub Jelinek  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
 Status|NEW |ASSIGNED

--- Comment #4 from Jakub Jelinek  ---
Created attachment 54465
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54465&action=edit
gcc13-pr108783.patch

Untested fix.

[Bug tree-optimization/108783] [13 Regression] ICE: verify_flow_info failed (error: returns_twice call is not first in basic block 3)

2023-02-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108783

--- Comment #3 from Jakub Jelinek  ---
Though, the optimization that does this has been added in
r0-99848-g844381e5bc6eb515df838279 for PR28685.

[Bug tree-optimization/108783] [13 Regression] ICE: verify_flow_info failed (error: returns_twice call is not first in basic block 3)

2023-02-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108783

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org
   Keywords|needs-bisection |

--- Comment #2 from Jakub Jelinek  ---
ICEs since r13-1754-g7a158a5776f5ca95a318 when the check has been added.
Anyway, looking just at dumps, reassoc1 does this since
r5-4662-gd5e254e19c59fcc49265dda
That commit looks unrelated, but it actually changes quite a lot the generated
IL for some reason already starting with ssa dump.

[Bug tree-optimization/108783] [13 Regression] ICE: verify_flow_info failed (error: returns_twice call is not first in basic block 3)

2023-02-13 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108783

Richard Biener  changed:

   What|Removed |Added

   Keywords||needs-bisection
 Ever confirmed|0   |1
 CC||rguenth at gcc dot gnu.org
   Target Milestone|--- |13.0
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2023-02-14

--- Comment #1 from Richard Biener  ---
reassoc1 does

[local count: 966367643]:
   # a_4(ab) = PHI 
+  _14 = a_4(ab) != 0;
   foo (x_9(D), y_12(D));
   goto ; [99.96%]

@@ -36,8 +59,7 @@
[local count: 1073312329]:
   _1 = y_12(D) != 0;
   _2 = a_4(ab) != 0;
-  _3 = _1 & _2;
-  _10 = _2 & _3;
+  _10 = _14 & _1;
   _15 = (int) _10;
   return _15;

Confirmed.  It also inserts a new use of a_4(ab) which we try to generally
avoid
(but in this specific case it shouldn't be a problem).

Not sure why reassoc expands _2 and re-emits the _14 definition here.