Bug 80054 - [7 Regression] ICE in verify_ssa with -O3 -march=broadwell/skylake-avx512
Summary: [7 Regression] ICE in verify_ssa with -O3 -march=broadwell/skylake-avx512
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 7.0.1
: P1 normal
Target Milestone: 7.0
Assignee: Bill Schmidt
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: yarpgen
  Show dependency treegraph
 
Reported: 2017-03-15 17:13 UTC by Vsevolod Livinskii
Modified: 2021-11-01 23:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 6.3.1
Known to fail:
Last reconfirmed: 2017-03-16 00:00:00


Attachments
Reproducer. (254 bytes, text/plain)
2017-03-15 17:13 UTC, Vsevolod Livinskii
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vsevolod Livinskii 2017-03-15 17:13:04 UTC
Created attachment 40978 [details]
Reproducer.

ICE with -O3 -march=broadwell (and skylake-avx512). Everything works fine with other optimization levels.

Error:
>$ g++ -O3 -march=broadwell -c repr.cpp
repr.cpp: In function ‘void foo()’:
repr.cpp:17:6: error: definition in block 7 does not dominate use in block 6
 void foo() {
      ^~~
for SSA_NAME: _133 in statement:
slsr_142 = PHI <_133(6), _133(16)>
PHI argument
_133
for PHI node
slsr_142 = PHI <_133(6), _133(16)>
repr.cpp:17:6: internal compiler error: verify_ssa failed
0xf84ad3 verify_ssa(bool, bool)
	/home/vsevolod/workspace/gcc-dev/trunk/gcc/tree-ssa.c:1184
0xc98ea7 execute_function_todo
	/home/vsevolod/workspace/gcc-dev/trunk/gcc/passes.c:1973
0xc99e0b execute_todo
	/home/vsevolod/workspace/gcc-dev/trunk/gcc/passes.c:2016

Reproducer:
extern short var_2;
extern short var_4;
extern const bool var_32;
extern short var_36;
extern const bool var_37;
extern bool var_46;
extern unsigned int var_47;
extern short var_49;
extern unsigned int var_56;
extern unsigned int var_62;
extern unsigned int var_65;
extern bool var_831;
extern unsigned int var_843;
extern short var_846;
extern short var_889;

void foo() {
    if (var_36 * var_37)
        var_831 = var_56 = 0;
    else
        var_65 = 0;
    
    if (var_46)
        var_843 = 0;
    
    var_846 = 0;
    
    if ((var_4 == 0) >> (var_32 | -(var_37 < var_46 || var_36)) + 8)
        var_49 = 2032651381 * bool(var_2 * var_37);
    else {
        var_62 = 0;
        var_47 = (var_46 || var_36) * (var_2 * var_37);
    }
    
    var_889 = bool(var_2 * var_37);
}

GCC version:
gcc version 7.0.1 (today's trunk)
Comment 1 Richard Biener 2017-03-16 14:57:19 UTC
Confirmed.  SLSR is at fault.
Comment 2 Bill Schmidt 2017-03-16 14:59:29 UTC
OK, I'll have a look.
Comment 3 Bill Schmidt 2017-03-16 15:58:31 UTC
Reproducible on ppc64le without any -march.
Comment 4 Bill Schmidt 2017-03-16 20:23:32 UTC
PRE creates a situation where a conditional SLSR candidate depends on a PHI that occurs prior to the basis for the candidate.  SLSR doesn't notice this and eventually creates a phi basis that is not dominated by the true basis, leading to a use of an undefined variable.

The fix will be to test whether the basis dominates all PHIs and their PHI argument definitions, and avoid the optimization in such cases.  Testing now.
Comment 5 Bill Schmidt 2017-03-20 20:04:58 UTC
Author: wschmidt
Date: Mon Mar 20 20:04:25 2017
New Revision: 246290

URL: https://gcc.gnu.org/viewcvs?rev=246290&root=gcc&view=rev
Log:
[gcc]

2017-03-20  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR tree-optimization/80054
	* gimple-ssa-strength-reduction.c (all_phi_incrs_profitable): Fail
	the optimization if a PHI or any of its arguments is not dominated
	by the candidate's basis.  Use gphi* rather than gimple* as
	appropriate.
	(replace_profitable_candidates): Clean up a gimple* variable that
	should be a gphi* variable.

[gcc/testsuite]

2017-03-20  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR tree-optimization/80054
	* g++.dg/torture/pr80054.C: New file.


Added:
    trunk/gcc/testsuite/g++.dg/torture/pr80054.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-ssa-strength-reduction.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Bill Schmidt 2017-03-20 20:05:53 UTC
Fixed.