Bug 109604

Summary: [14 Regression] ICE during GIMPLE pass: phiopt since r14-169-g84325f1c6aa3c5
Product: gcc Reporter: David Binderman <dcb314>
Component: tree-optimizationAssignee: Andrew Pinski <pinskia>
Status: RESOLVED FIXED    
Severity: normal CC: marxin, pinskia
Priority: P3 Keywords: ice-on-valid-code
Version: 14.0   
Target Milestone: 14.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2023-04-24 00:00:00

Description David Binderman 2023-04-24 08:26:42 UTC
For this C code:

nilfs_bmap_find_target_seq_bmap;
unsigned long nilfs_bmap_find_target_seq_bmap_0;
unsigned long nilfs_bmap_find_target_seq() {
  if (nilfs_bmap_find_target_seq_bmap &&
      nilfs_bmap_find_target_seq_bmap_0 + nilfs_bmap_find_target_seq_bmap)
    return nilfs_bmap_find_target_seq_bmap_0 + nilfs_bmap_find_target_seq_bmap;
  else
    return 0;
}

compiled by recent gcc trunk, does this:

$ ../results/bin/gcc -c -w -O1 bug908.c 
bug908.c: In function ‘nilfs_bmap_find_target_seq’:
bug908.c:9:1: error: definition in block 3 does not dominate use in block 4
    9 | }
      | ^
for SSA_NAME: _5 in statement:
# VUSE <.MEM_10(D)>
return _5;
during GIMPLE pass: phiopt
bug908.c:9:1: internal compiler error: verify_ssa failed
0x107ae4f verify_ssa(bool, bool)
	../../trunk.year/gcc/tree-ssa.cc:1211

This seems to have broken between git hash g:7e26fd6bcd39f53b
and g:ff8f95449350372b, which is 6 revisions.
Comment 1 Martin Liška 2023-04-24 09:54:47 UTC
Started with r14-169-g84325f1c6aa3c5.
Comment 2 Andrew Pinski 2023-04-24 15:22:10 UTC
I had already posted a fix for this (and approved already):
https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616499.html

I will add the testcase.
Comment 3 David Binderman 2023-04-24 15:26:59 UTC
Another test case, this time in C++:

struct {
  int second;
} selectPlayer_playerRes;
int selectPlayer_playerRes_0;
int selectPlayer() {
  if (selectPlayer_playerRes_0 && selectPlayer_playerRes.second >= 0)
    return selectPlayer_playerRes.second;
  else
    return -1;
}
Comment 4 GCC Commits 2023-04-24 15:50:27 UTC
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:2f58dd71d1b8e23f28a43360742519e92ee0c8d5

commit r14-199-g2f58dd71d1b8e23f28a43360742519e92ee0c8d5
Author: Andrew Pinski <apinski@marvell.com>
Date:   Thu Apr 20 09:23:25 2023 -0700

    PHIOPT: Move check on diamond bb to tree_ssa_phiopt_worker from minmax_replacement
    
    This moves the check to make sure on the diamond shaped form bbs that
    the the two middle bbs are only for that diamond shaped form earlier
    in the shared code.
    Also remove the redundant check for single_succ_p since that was already
    done before hand.
    The next patch will simplify the code even further and remove redundant
    checks.
    
            PR tree-optimization/109604
    
    gcc/ChangeLog:
    
            * tree-ssa-phiopt.cc (tree_ssa_phiopt_worker): Move the
            diamond form check from ...
            (minmax_replacement): Here.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.c-torture/compile/pr109604-1.c: New test.
            * gcc.c-torture/compile/pr109604-2.c: New test.
Comment 5 Andrew Pinski 2023-04-24 15:51:21 UTC
Fixed.