Bug 71259 - [6/7 Regression] GCC trunk emits wrong code
Summary: [6/7 Regression] GCC trunk emits wrong code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: 6.2
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks: yarpgen
  Show dependency treegraph
 
Reported: 2016-05-24 14:29 UTC by Anton Mitrokhin
Modified: 2021-11-01 23:07 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-05-25 00:00:00


Attachments
Reproducer (398 bytes, text/x-csrc)
2016-05-24 14:29 UTC, Anton Mitrokhin
Details
gcc7-pr71259.patch (918 bytes, patch)
2016-06-03 15:35 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Mitrokhin 2016-05-24 14:29:47 UTC
Created attachment 38552 [details]
Reproducer

GCC trunk generates wrong code with -O3/Ofast on 'ivybridge' target (not sure about other targets though)

crash.cpp is attached.

Run:
> g++ -static-libgcc -static-libstdc++ -std=c++11 -O2 -march=ivybridge -o out0 crash.cpp
> g++ -static-libgcc -static-libstdc++ -std=c++11 -O3 -march=ivybridge -o out1 crash.cpp

Output:
> ./out0: -5105075050047261684
> ./out1: -5105075050047261682

> gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/export/users/amitrokh/gcc_trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /export/users/gnutester/stability/svn/trunk/configure --with-arch=corei7 --with-cpu=corei7 --enable-clocale=gnu --with-system-zlib --enable-shared --with-demangler-in-ld --enable-cloog-backend=isl --with-fpmath=sse --with-pkgversion=Revision=236614/svn-rev:236614/ --prefix=/export/users/gnutester/stability/work/trunk/64/install --enable-languages=c,c++,fortran,java,lto
Thread model: posix
gcc version 7.0.0 20160523 (experimental) (Revision=236614/svn-rev:236614/)
Comment 1 Richard Biener 2016-05-25 08:58:57 UTC
Confirmed also with GCC 6 with -msse4.2, -fno-tree-vectorize fixes it.  GCC 5 works fine.
Comment 2 Jakub Jelinek 2016-06-03 12:03:38 UTC
Simplified testcase:
long a, b[1][44][2];
long long c[44][17][2];

int
main ()
{
  int i, j, k;
  asm volatile ("" : : : "memory");
  for (i = 0; i < 44; i++)
    for (j = 0; j < 17; j++)
      for (k = 0; k < 2; k++)
	c[i][j][k] = (30995740 >= *(k + *(j + *b)) != (a != 8)) - 5105075050047261684;
  asm volatile ("" : : : "memory");
  for (i = 0; i < 44; i++) 
    for (j = 0; j < 17; j++)
      for (k = 0; k < 2; k++)
	if (c[i][j][k] != -5105075050047261684)
	  __builtin_abort ();
  return 0;
}
Comment 3 Jakub Jelinek 2016-06-03 14:04:23 UTC
Started to ICE with r230098, before that it worked properly. ICE got fixed with
r232153, but it is miscompiled already then, so it is unclear when this wrong-code has been introduced.
Comment 4 Jakub Jelinek 2016-06-03 15:35:49 UTC
Created attachment 38639 [details]
gcc7-pr71259.patch

Untested fix.
Comment 5 Jakub Jelinek 2016-06-06 18:35:35 UTC
Author: jakub
Date: Mon Jun  6 18:35:03 2016
New Revision: 237147

URL: https://gcc.gnu.org/viewcvs?rev=237147&root=gcc&view=rev
Log:
	PR tree-optimization/71259
	* tree-vect-slp.c (vect_get_constant_vectors): For
	VECTOR_BOOLEAN_TYPE_P, return all ones constant instead of
	one for constant op, and use COND_EXPR for non-constant.

	* gcc.dg/vect/pr71259.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr71259.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vect-slp.c
Comment 6 Jakub Jelinek 2016-06-06 18:48:09 UTC
Author: jakub
Date: Mon Jun  6 18:47:33 2016
New Revision: 237148

URL: https://gcc.gnu.org/viewcvs?rev=237148&root=gcc&view=rev
Log:
	PR tree-optimization/71259
	* tree-vect-slp.c (vect_get_constant_vectors): For
	VECTOR_BOOLEAN_TYPE_P, return all ones constant instead of
	one for constant op, and use COND_EXPR for non-constant.

	* gcc.dg/vect/pr71259.c: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/gcc.dg/vect/pr71259.c
Modified:
    branches/gcc-6-branch/gcc/ChangeLog
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
    branches/gcc-6-branch/gcc/tree-vect-slp.c
Comment 7 Jakub Jelinek 2016-06-06 19:18:48 UTC
Fixed.