public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server
@ 2021-10-05 19:37 vsevolod.livinskij at frtk dot ru
  2021-10-05 22:21 ` [Bug tree-optimization/102622] [12 Regression] " pinskia at gcc dot gnu.org
                   ` (29 more replies)
  0 siblings, 30 replies; 31+ messages in thread
From: vsevolod.livinskij at frtk dot ru @ 2021-10-05 19:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

            Bug ID: 102622
           Summary: Wrong code with -O3 for skylake-avx512 and
                    icelake-server
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vsevolod.livinskij at frtk dot ru
  Target Milestone: ---

Reproducer:
// func.cpp
#include <algorithm>

extern int var_20, var_22;
extern short arr_32[];
extern char arr_45[];

void test(int a, unsigned b, long long *c) {
  for (short d = 0; d < 13; d++) {
    for (int e = 0; e < a; e += 3)
      var_20 = 0;
    if (std::max(b, unsigned((short)b))) {
      arr_32[d] = 0;
      var_22 = *c;
    }
    for (unsigned f = 0; f < 69; f += 4)
      arr_45[f] = 0;
  }
}

driver.cpp
#include <stdio.h>

unsigned long long int a = 10693271954245845448ULL;
unsigned int b = 1144022456U;
long long int c = 42;
int var_20 = 0;
long long int var_22 = 0;
unsigned short arr_32 [13];
unsigned char arr_45 [69];

void test(int a, unsigned int b, long long int* c);

int main() {
    test(a, b, &c);
    printf("%llu\n", var_22);
}

Error:
>$ g++ -O3 -march=skylake-avx512 func.cpp driver.cpp && sde -skx -- ./a.out 
0
>$ g++ -O2 -march=skylake-avx512 func.cpp driver.cpp && sde -skx -- ./a.out 
42

GCC version:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/testing/gcc/bin/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /testing/gcc/gcc_src/configure --enable-multilib
--prefix=/testing/gcc/bin --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211004 (154fd0896ef22fcf5235e35e2b795394dddd7a33) (GCC)

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
@ 2021-10-05 22:21 ` pinskia at gcc dot gnu.org
  2021-10-05 22:36 ` pinskia at gcc dot gnu.org
                   ` (28 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-05 22:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
            Summary|Wrong code with -O3 for     |[12 Regression] Wrong code
                   |skylake-avx512 and          |with -O3 for skylake-avx512
                   |icelake-server              |and icelake-server
   Last reconfirmed|                            |2021-10-05
   Target Milestone|---                         |12.0
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
reduced to one file:
static inline const unsigned &max1(const unsigned &t, const unsigned &t1)
{
    return t > t1 ? t : t1;
}
long long int c = 42;
int var_20 = 0;
int var_22 = 0;
short arr_32 [13];
char arr_45 [69];

void test(int a, unsigned b, long long *c) __attribute__((noipa));
void test(int a, unsigned b, long long *c) {
  for (short d = 0; d < 13; d++) {
    for (int e = 0; e < a; e += 3)
      var_20 = 0;
    if (max1(b, unsigned((short)b))) {
      arr_32[d] = 0;
      var_22 = *c;
    }
    for (unsigned f = 0; f < 69; f += 4)
      arr_45[f] = 0;
  }
}
int main() {
    test(-545750584, 1144022456U, &c);
    if (var_22 != 42)
      __builtin_abort();
    return 0;
}

Confirmed.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
  2021-10-05 22:21 ` [Bug tree-optimization/102622] [12 Regression] " pinskia at gcc dot gnu.org
@ 2021-10-05 22:36 ` pinskia at gcc dot gnu.org
  2021-10-05 23:31 ` pinskia at gcc dot gnu.org
                   ` (27 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-05 22:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a slightly more reduced testcase (without the reasonable values):
static inline const unsigned &max1(const unsigned &t, const unsigned &t1)
{
    return t > t1 ? t : t1;
}
extern int  var_20, var_22;
extern short arr_32[];
extern char arr_45[];

void test(int a, unsigned b, const long long &c) __attribute__((noipa));
void test(int a, unsigned b, const long long &c) {
  for (short d = 0; d < 13; d++) {
    for (int e = 0; e < a; e += 3)
      var_20 = 0;
    if (max1(b, unsigned((short)b))) {
      arr_32[d] = 0;
      var_22 = c;
    }
    for (unsigned f = 0; f < 69; f += 4)
      arr_45[f] = 0;
  }
}


int var_20 = 0;
int var_22 = 0;
short arr_32 [13];
char arr_45 [69];

int main() {
    test(-1, 1, 42);
    if (var_22 != 42)
      __builtin_abort();
    return 0;
}

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
  2021-10-05 22:21 ` [Bug tree-optimization/102622] [12 Regression] " pinskia at gcc dot gnu.org
  2021-10-05 22:36 ` pinskia at gcc dot gnu.org
@ 2021-10-05 23:31 ` pinskia at gcc dot gnu.org
  2021-10-06  7:23 ` [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903 aldyh at gcc dot gnu.org
                   ` (26 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-05 23:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |11.2.0

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> Here is a slightly more reduced testcase (without the reasonable values):

Looks like the store to var_22 was fully removed, I think this is not a
vectorizer bug really, but rather some issue with jump threading ....

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (2 preceding siblings ...)
  2021-10-05 23:31 ` pinskia at gcc dot gnu.org
@ 2021-10-06  7:23 ` aldyh at gcc dot gnu.org
  2021-10-06  8:42 ` rguenth at gcc dot gnu.org
                   ` (25 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-10-06  7:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aldyh at gcc dot gnu.org

--- Comment #4 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> (In reply to Andrew Pinski from comment #2)
> > Here is a slightly more reduced testcase (without the reasonable values):
> 
> Looks like the store to var_22 was fully removed, I think this is not a
> vectorizer bug really, but rather some issue with jump threading ....

I'm getting an illegal instruction, so perhaps I don't have a machine with the
appropriate hardware.  I even get the illegal instruction with
-fno-thread-jumps:

(base) abulafia:~/bld/t/gcc$ ./xg++ -B./ a.c -O3
-L/usr/lib/gcc/x86_64-redhat-linux/11/ -march=skylake-avx512                   
                                                                               
                   (base) abulafia:~/bld/t/gcc$ ./a.out
Illegal instruction (core dumped)

Can you try with -fno-thread-jumps to make sure its really the threader at
play?

If so, you could try to narrow it down to the problematic threading path with:

-fdbg-cnt=registered_jump_thread:N:N

where N is the number that causes the problem.

Once it's narrowed, I could look at the path and see if it's valid.

Thanks.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (3 preceding siblings ...)
  2021-10-06  7:23 ` [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903 aldyh at gcc dot gnu.org
@ 2021-10-06  8:42 ` rguenth at gcc dot gnu.org
  2021-10-06 12:55 ` hjl.tools at gmail dot com
                   ` (24 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-06  8:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (4 preceding siblings ...)
  2021-10-06  8:42 ` rguenth at gcc dot gnu.org
@ 2021-10-06 12:55 ` hjl.tools at gmail dot com
  2021-10-06 13:04 ` hjl.tools at gmail dot com
                   ` (23 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: hjl.tools at gmail dot com @ 2021-10-06 12:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #5 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Aldy Hernandez from comment #4)
> (In reply to Andrew Pinski from comment #3)
> > (In reply to Andrew Pinski from comment #2)
> > > Here is a slightly more reduced testcase (without the reasonable values):
> > 
> > Looks like the store to var_22 was fully removed, I think this is not a
> > vectorizer bug really, but rather some issue with jump threading ....
> 
> I'm getting an illegal instruction, so perhaps I don't have a machine with
> the appropriate hardware.  I even get the illegal instruction with
> -fno-thread-jumps:
> 
> (base) abulafia:~/bld/t/gcc$ ./xg++ -B./ a.c -O3
> -L/usr/lib/gcc/x86_64-redhat-linux/11/ -march=skylake-avx512                
> (base) abulafia:~/bld/t/gcc$ ./a.out
> Illegal instruction (core dumped)

You can download Intel SDE to run it:

https://software.intel.com/content/www/us/en/develop/articles/intel-software-development-emulator.html

> Can you try with -fno-thread-jumps to make sure its really the threader at
> play?

I will give it a try.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (5 preceding siblings ...)
  2021-10-06 12:55 ` hjl.tools at gmail dot com
@ 2021-10-06 13:04 ` hjl.tools at gmail dot com
  2021-10-06 13:10 ` aldyh at gcc dot gnu.org
                   ` (22 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: hjl.tools at gmail dot com @ 2021-10-06 13:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Aldy Hernandez from comment #4)
> Can you try with -fno-thread-jumps to make sure its really the threader at
> play?

-fno-thread-jumps fixes the bug.

> If so, you could try to narrow it down to the problematic threading path
> with:
> 
> -fdbg-cnt=registered_jump_thread:N:N
> 
> where N is the number that causes the problem.

What N should I try? I got

[hjl@gnu-skx-1 gcc]$ ./xgcc -B./ -S -O3 -march=native
/export/project/git/gcc-bisect/pr102622.cc
-fdbg-cnt=registered_jump_thread:10:10
cc1plus: error: Interval overlap of ??-fdbg-cnt=registered_jump_thread??: [1,
10] and [1, 10]

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (6 preceding siblings ...)
  2021-10-06 13:04 ` hjl.tools at gmail dot com
@ 2021-10-06 13:10 ` aldyh at gcc dot gnu.org
  2021-10-06 13:12 ` aldyh at gcc dot gnu.org
                   ` (21 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-10-06 13:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #7 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #6)
> (In reply to Aldy Hernandez from comment #4)
> > Can you try with -fno-thread-jumps to make sure its really the threader at
> > play?
> 
> -fno-thread-jumps fixes the bug.
> 
> > If so, you could try to narrow it down to the problematic threading path
> > with:
> > 
> > -fdbg-cnt=registered_jump_thread:N:N
> > 
> > where N is the number that causes the problem.
> 
> What N should I try? I got
> 
> [hjl@gnu-skx-1 gcc]$ ./xgcc -B./ -S -O3 -march=native
> /export/project/git/gcc-bisect/pr102622.cc
> -fdbg-cnt=registered_jump_thread:10:10
> cc1plus: error: Interval overlap of ??-fdbg-cnt=registered_jump_thread??:
> [1, 10] and [1, 10]

What I usually do is start with say...10

-fdbg-cnt=registered_jump_thread:10

and keep reducing it until you find the problematic one.

Say it dies with 10, but does not with 9.  That usually means that the
combination of the first 10 jump threading paths caused the problem.  More
often than not, it means it's the 10th one.  But it could be a combination of
1-10.

You could then further reduce it to an individual jump threading path (if
you're lucky enough that's only one threading path that's causing the problem--
it's usually the case).

For instance:

-fdbg-cnt=registered_jump_thread:5-5

That will ONLY jump thread the 5th attempt.  If that fails, then you're
absolutely sure it's the 5th attempt that's causing the problem.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (7 preceding siblings ...)
  2021-10-06 13:10 ` aldyh at gcc dot gnu.org
@ 2021-10-06 13:12 ` aldyh at gcc dot gnu.org
  2021-10-06 13:26 ` hjl.tools at gmail dot com
                   ` (20 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-10-06 13:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #8 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #6)
> (In reply to Aldy Hernandez from comment #4)
> > Can you try with -fno-thread-jumps to make sure its really the threader at
> > play?
> 
> -fno-thread-jumps fixes the bug.
> 
> > If so, you could try to narrow it down to the problematic threading path
> > with:
> > 
> > -fdbg-cnt=registered_jump_thread:N:N
> > 
> > where N is the number that causes the problem.
> 
> What N should I try? I got
> 
> [hjl@gnu-skx-1 gcc]$ ./xgcc -B./ -S -O3 -march=native
> /export/project/git/gcc-bisect/pr102622.cc
> -fdbg-cnt=registered_jump_thread:10:10
> cc1plus: error: Interval overlap of ??-fdbg-cnt=registered_jump_thread??:
> [1, 10] and [1, 10]

Sorry, that should've been N-N for the Nth attempt.

Or M-N for attempts M through N.

-fdbg-cnt is annoying in that it doesn't give much feedback.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (8 preceding siblings ...)
  2021-10-06 13:12 ` aldyh at gcc dot gnu.org
@ 2021-10-06 13:26 ` hjl.tools at gmail dot com
  2021-10-06 14:19 ` aldyh at redhat dot com
                   ` (19 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: hjl.tools at gmail dot com @ 2021-10-06 13:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #9 from H.J. Lu <hjl.tools at gmail dot com> ---
1. -fdbg-cnt=registered_jump_thread:19 passes.
2. -fdbg-cnt=registered_jump_thread:20 fails.
3. -fdbg-cnt=registered_jump_thread:1-20 fails.
4. -fdbg-cnt=registered_jump_thread:2-20 passes.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (9 preceding siblings ...)
  2021-10-06 13:26 ` hjl.tools at gmail dot com
@ 2021-10-06 14:19 ` aldyh at redhat dot com
  2021-10-06 14:21 ` hjl.tools at gmail dot com
                   ` (18 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: aldyh at redhat dot com @ 2021-10-06 14:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #10 from Aldy Hernandez <aldyh at redhat dot com> ---
Does :1-1 fail? In which case it's definitely the first thread.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (10 preceding siblings ...)
  2021-10-06 14:19 ` aldyh at redhat dot com
@ 2021-10-06 14:21 ` hjl.tools at gmail dot com
  2021-10-07 16:07 ` aldyh at gcc dot gnu.org
                   ` (17 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: hjl.tools at gmail dot com @ 2021-10-06 14:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #11 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Aldy Hernandez from comment #10)
> Does :1-1 fail? In which case it's definitely the first thread.

:1-1 passes.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (11 preceding siblings ...)
  2021-10-06 14:21 ` hjl.tools at gmail dot com
@ 2021-10-07 16:07 ` aldyh at gcc dot gnu.org
  2021-10-07 21:29 ` pinskia at gcc dot gnu.org
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-10-07 16:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com,
                   |                            |jakub at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org

--- Comment #12 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
I had to download the Intel SDE to reproduce it, but was finally able to narrow
it down to 4 jump threading paths:

./xg++ -B./ a.c -O3 -L/usr/lib/gcc/x86_64-redhat-linux/11/
-march=skylake-avx512 -fdump-tree-all-details -fdisable-tree-ethread
-fdisable-tree-thread1 -fdisable-tree-thread2 -fdisable-tree-thread3
-fdisable-tree-thread4  -fdbg-cnt=registered_jump_thread:2-4:19-20

$ grep 'thread' a.c.* |grep Registering
a.c.113t.vrp-thread1:  [2] Registering jump thread: (9, 11) incoming edge; 
(11, 10) normal; 
a.c.113t.vrp-thread1:  [4] Registering jump thread: (5, 7) incoming edge;  (7,
8) normal; 
a.c.197t.vrp-thread2:  [19] Registering jump thread: (15, 16) incoming edge; 
(16, 18) normal; 
a.c.197t.vrp-thread2:  [20] Registering jump thread: (21, 16) incoming edge; 
(16, 18) normal; 

Things start getting challenging after the vectorizer and cunroll run.  Such
that by vrp-thread2, ranger figures out that the 2->3 edge is unreachable, _21
must be 0, and shit rolls downhill from there:

  unsigned long ivtmp.31;
  short int * vectp_arr_32.21;
  vector(8) short int * vectp_arr_32.20;
  unsigned short tmp.19;
  short int tmp.18;
  int D.4484;
  bool var_22_lsm_flag.15;
  int var_22_lsm.14;
  int D.4481;
  bool var_20_lsm_flag.13;
  int var_20_lsm.12;
  unsigned int f;
  int e;
  short int d;
  short int _2;
  unsigned int _3;
  bool _4;
  long long int _6;
  int _7;
  bool _21;
  unsigned short ivtmp_24;
  int _30(D);
  bool _33;
  unsigned short ivtmp_41;
  int _43(D);
  short int * _55;
  <signed-boolean:1> _64;
  int _66;
  unsigned long _74;
  <signed-boolean:1> _75;
  vector(8) <signed-boolean:1> vect_cst__76;
  void * _81;

  <bb 2> [local count: 8685306]:
  _2 = (short int) b_15(D);
  _3 = (unsigned int) _2;
  _4 = _3 != 0;
  _33 = _3 < b_15(D);
  _21 = _4 | _33;
  _64 = (<signed-boolean:1>) _21;
  _75 = -_64;
  vect_cst__76 = {_75, _75, _75, _75, _75, _75, _75, _75};
  if (_75 == 0)
    goto <bb 4>; [100.00%]
  else
    goto <bb 3>; [20.00%]

  <bb 3> [local count: 1737061]:
  MEM <vector(8) short int> [(short int *)&arr_32] = { 0, 0, 0, 0, 0, 0, 0, 0
};

  <bb 4> [local count: 8685306]:
  if (_21 != 0)
    goto <bb 5>; [50.00%]
  else
    goto <bb 6>; [50.00%]

  <bb 5> [local count: 2171327]:
  arr_32[8] = 0;

  <bb 6> [local count: 4342653]:
  if (_21 != 0)
    goto <bb 7>; [50.00%]
  else
    goto <bb 8>; [50.00%]
[snip]
[snip]

The reason ranger concludes that 2->3 is unreachable is from analyzing block 2:

  <bb 2> [local count: 8685306]:
  _2 = (short int) b_15(D);
  _3 = (unsigned int) _2;
  _4 = _3 != 0;
  _33 = _3 < b_15(D);
  _21 = _4 | _33;
  _64 = (<signed-boolean:1>) _21;
  _75 = -_64;
  vect_cst__76 = {_75, _75, _75, _75, _75, _75, _75, _75};
  if (_75 == 0)
    goto <bb 4>; [100.00%]
  else
    goto <bb 3>; [20.00%]

On the 2->3 edge, _75 == -1 because this is a 1-bit signed integer.  Solving
back we have:

_75 = - _64; ==> [-1,-1] = -_64;

-1 for a 1-bit signed integer is TYPE_MIN_VALUE, and NEG(TYPE_MIN_VALUE) is
unrepresentable.  So, _75 cannot be -1, thus the edge is unexecutable.

Questions:

a) Is -(-1) representable in 1-bit signed?

b) Could we somehow avoid creating the 1-bit signed in the vectorizer, since
they are a source of endless exception?

Thanks.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (12 preceding siblings ...)
  2021-10-07 16:07 ` aldyh at gcc dot gnu.org
@ 2021-10-07 21:29 ` pinskia at gcc dot gnu.org
  2021-10-07 21:31 ` pinskia at gcc dot gnu.org
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-07 21:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
VRP is rewriting:
  _75 = _33 ? -1 : 0;
to:
  _38 = (<signed-boolean:1>) _33;
  _75 = -_38;


Folding statement: _75 = _33 ? -1 : 0;
Applying pattern match.pd:3954, gimple-match.c:142059
gimple_simplified to _38 = (<signed-boolean:1>) _33;
_75 = -_38;
Folded into: _75 = -_38;


Mine.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (13 preceding siblings ...)
  2021-10-07 21:29 ` pinskia at gcc dot gnu.org
@ 2021-10-07 21:31 ` pinskia at gcc dot gnu.org
  2021-10-08  6:04 ` pinskia at gcc dot gnu.org
                   ` (14 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-07 21:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #14 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #13)
> VRP is rewriting:
>   _75 = _33 ? -1 : 0;
> to:
>   _38 = (<signed-boolean:1>) _33;
>   _75 = -_38;
> 
> 
> Folding statement: _75 = _33 ? -1 : 0;
> Applying pattern match.pd:3954, gimple-match.c:142059
> gimple_simplified to _38 = (<signed-boolean:1>) _33;
> _75 = -_38;
> Folded into: _75 = -_38;
> 
> 
> Mine.

That is this pattern:
    /* a ? -1 : 0 -> -a. */
    (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
     (negate (convert (convert:boolean_type_node @0))))

I guess I need a check for TYPE_PRECISION being non-1 here.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (14 preceding siblings ...)
  2021-10-07 21:31 ` pinskia at gcc dot gnu.org
@ 2021-10-08  6:04 ` pinskia at gcc dot gnu.org
  2021-10-09 22:25 ` pinskia at gcc dot gnu.org
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-08  6:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
here is the C testcase:
static inline const unsigned *max1(const unsigned *t, const unsigned *t1)
{
    return *t > *t1 ? t : t1;
}
int var_20 = 0;
int var_22 = 0;
short arr_32 [13];
char arr_45 [69];
void test(int a, unsigned b, const long long *c) __attribute__((noipa));
void test(int a, unsigned b, const long long *c) {
  for (short d = 0; d < 13; d++) {
    for (int e = 0; e < a; e += 3)
      var_20 = 0;
    unsigned t = (short)b;
    if (*max1(&b, &t)) {
      arr_32[d] = 0;
      var_22 = *c;
    }
    for (unsigned f = 0; f < 69; f += 4)
      arr_45[f] = 0;
  }
}

int main() {
    long long t = 42;
    test(-1, 1, &t);
    if (var_22 != 42)
      __builtin_abort();
    return 0;
}

---- CUT -----

Here is the patch which I tested and is working:
diff --git a/gcc/match.pd b/gcc/match.pd
index a9791ceb74a..4fd2a8c3ea9 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3950,10 +3950,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
     (if (integer_onep (@1))
      (convert (convert:boolean_type_node @0)))
     /* a ? -1 : 0 -> -a. */
-    (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
+    (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1)
+         && TYPE_PRECISION (type) != 1)
      (negate (convert (convert:boolean_type_node @0))))
     /* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */
-    (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1))
+    (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1)
+         && TYPE_PRECISION (type) != 1)
      (with {
        tree shift = build_int_cst (integer_type_node, tree_log2 (@1));
       }
@@ -3967,10 +3969,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      (if (integer_onep (@2))
       (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
      /* a ? -1 : 0 -> -(!a). */
-     (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
+     (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)
+         && TYPE_PRECISION (type) != 1)
       (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; }
))))
      /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
-     (if (INTEGRAL_TYPE_P (type) &&  integer_pow2p (@2))
+     (if (INTEGRAL_TYPE_P (type) &&  integer_pow2p (@2)
+         && TYPE_PRECISION (type) != 1)
       (with {
        tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
        }

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (15 preceding siblings ...)
  2021-10-08  6:04 ` pinskia at gcc dot gnu.org
@ 2021-10-09 22:25 ` pinskia at gcc dot gnu.org
  2021-10-10  1:05 ` [Bug tree-optimization/102622] [9/10/12 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types pinskia at gcc dot gnu.org
                   ` (12 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-09 22:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #16 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a testcase without avx-512f usage:
struct f{signed t:1;};
int g(struct f *a, int t) __attribute__((noipa));
int g(struct f *a, int t)
{
    if (t)
      a->t = -1;
    else
      a->t = 0;
    int t1 = a->t;
    if (t1) return 1;
    return t1;
}

int main(void)
{
    struct f a;
    if (!g(&a, 1))  __builtin_abort();
    return 0;
}

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9/10/12 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (16 preceding siblings ...)
  2021-10-09 22:25 ` pinskia at gcc dot gnu.org
@ 2021-10-10  1:05 ` pinskia at gcc dot gnu.org
  2021-10-10  1:54 ` pinskia at gcc dot gnu.org
                   ` (11 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-10  1:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.0                        |9.5
      Known to work|9.3.0                       |11.1.0, 4.9.2, 7.1.0, 8.5.0
      Known to fail|                            |10.3.0, 9.1.0, 9.4.0
            Summary|[12 Regression] Wrong code  |[9/10/12 Regression] Wrong
                   |with -O3 for skylake-avx512 |code with -O1 and above due
                   |and icelake-server by       |to phiopt and signed one
                   |r12-3903                    |bit integer types

--- Comment #17 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So the reason why we didn't hit it in GCC 11 (and before) was the order of the
following was swapped in phiopt compared to what it is in match.pd now:
a ? -1 : 0 -> -a
a ? powerof2cst : 0 -> a << (log2(powerof2cst))

That is did the powerof2cst case before it did the -1 case.  I am going to test
that to see if it works here which I think it does.

In fact my new testcase fails in GCC 9.1.0-10.3.0 :).

I am going to fix this for the trunk and come up with a fix for the other
branches later on.

And yes the regression markers are a bit off right now but that is because the
bug is not latent on the 12 branch.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9/10/12 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (17 preceding siblings ...)
  2021-10-10  1:05 ` [Bug tree-optimization/102622] [9/10/12 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types pinskia at gcc dot gnu.org
@ 2021-10-10  1:54 ` pinskia at gcc dot gnu.org
  2021-10-10  5:49 ` pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-10  1:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #18 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 51579
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51579&action=edit
Patch which I am testing

Patch which I am testing, it works for the testcase but I have not done a full
bootstrap/test yet.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9/10/12 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (18 preceding siblings ...)
  2021-10-10  1:54 ` pinskia at gcc dot gnu.org
@ 2021-10-10  5:49 ` pinskia at gcc dot gnu.org
  2021-10-10  9:04 ` cvs-commit at gcc dot gnu.org
                   ` (9 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-10  5:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2021-October
                   |                            |/581251.html

--- Comment #19 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Trunk patch submitted
https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581251.html

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9/10/12 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (19 preceding siblings ...)
  2021-10-10  5:49 ` pinskia at gcc dot gnu.org
@ 2021-10-10  9:04 ` cvs-commit at gcc dot gnu.org
  2021-10-10  9:06 ` [Bug tree-optimization/102622] [9/10 " pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-10  9:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #20 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:882d806c1a8f9d2d2ade1133de88d63e5d4fe40c

commit r12-4276-g882d806c1a8f9d2d2ade1133de88d63e5d4fe40c
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sun Oct 10 01:28:59 2021 +0000

    tree-optimization: [PR102622]: wrong code due to signed one bit integer and
"a?-1:0"

    So it turns out this is kinda of a latent bug but not really latent.
    In GCC 9 and 10, phi-opt would transform a?-1:0 (even for signed 1-bit
integer)
    to -(type)a but the type is an one bit integer which means the negation is
    undefined. GCC 11 fixed the problem by checking for a?pow2cst:0
transformation
    before a?-1:0 transformation.

    When I added the transformations to match.pd, I had swapped the order not
paying
    attention and I didn't expect anything of it. Because there was no testcase
failing
    due to this.
    Anyways this fixes the problem on the trunk by swapping the order in
match.pd and
    adding a comment of why the order is this way.

    I will try to come up with a patch for GCC 9 and 10 series later on which
fixes
    the problem there too.

    Note I didn't include the original testcase which requires the vectorizer
and AVX-512f
    as I can't figure out the right dg options to restrict it to avx-512f but I
did come up
    with a testcase which shows the problem and even more shows the problem
with the 9/10
    series as mentioned.

    OK? Bootstrapped and tested on x86_64-linux-gnu.

            PR tree-optimization/102622

    gcc/ChangeLog:

            * match.pd: Swap the order of a?pow2cst:0 and a?-1:0
transformations.
            Swap the order of a?0:pow2cst and a?0:-1 transformations.

    gcc/testsuite/ChangeLog:

            * gcc.c-torture/execute/bitfld-10.c: New test.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9/10 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (20 preceding siblings ...)
  2021-10-10  9:04 ` cvs-commit at gcc dot gnu.org
@ 2021-10-10  9:06 ` pinskia at gcc dot gnu.org
  2021-10-10  9:18 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-10  9:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|https://gcc.gnu.org/piperma |
                   |il/gcc-patches/2021-October |
                   |/581251.html                |
            Summary|[9/10/12 Regression] Wrong  |[9/10 Regression] Wrong
                   |code with -O1 and above due |code with -O1 and above due
                   |to phiopt and signed one    |to phiopt and signed one
                   |bit integer types           |bit integer types
           Keywords|patch                       |
      Known to work|                            |12.0

--- Comment #21 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed on the trunk.  I will come up with a patch for GCC 9 and 10 branches in
the next few days since it won't be even close to a backport of this patch.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9/10 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (21 preceding siblings ...)
  2021-10-10  9:06 ` [Bug tree-optimization/102622] [9/10 " pinskia at gcc dot gnu.org
@ 2021-10-10  9:18 ` pinskia at gcc dot gnu.org
  2021-10-10 23:21 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-10  9:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #22 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is the simple patch which I will test for both GCC 10 and GCC 9.

The question becomes does it make sense to make the same change to GCC 11 even
if it cannot be hit.

diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index 9ed26a3d45f..a6c197defea 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -770,9 +770,12 @@ conditional_replacement (basic_block cond_bb, basic_block
middle_bb,
   if ((integer_zerop (arg0) && integer_onep (arg1))
       || (integer_zerop (arg1) && integer_onep (arg0)))
     neg = false;
+  /* For signed one bit types, the negation is not needed and
+     should be avoided and is the same as 1 case for non-signed
+     one bit types.  */
   else if ((integer_zerop (arg0) && integer_all_onesp (arg1))
           || (integer_zerop (arg1) && integer_all_onesp (arg0)))
-    neg = true;
+    neg = TYPE_PRECISION (TREE_TYPE (arg0)) != 1;
   else
     return false;

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9/10 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (22 preceding siblings ...)
  2021-10-10  9:18 ` pinskia at gcc dot gnu.org
@ 2021-10-10 23:21 ` pinskia at gcc dot gnu.org
  2021-10-11  9:22 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-10 23:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2021-October
                   |                            |/581259.html
           Keywords|                            |patch

--- Comment #23 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC 10 branch patch submitted:
https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581259.html

Once I approved I will backport to GCC 9.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9/10 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (23 preceding siblings ...)
  2021-10-10 23:21 ` pinskia at gcc dot gnu.org
@ 2021-10-11  9:22 ` cvs-commit at gcc dot gnu.org
  2021-10-11  9:24 ` [Bug tree-optimization/102622] [9 " pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-11  9:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #24 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Andrew Pinski
<pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:4111b36079fed95b787fafeed1deaab2dedaf3db

commit r10-10177-g4111b36079fed95b787fafeed1deaab2dedaf3db
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sun Oct 10 23:12:11 2021 +0000

    [GCC 10 branch] tree-optimization: [PR102622]: wrong code due to signed one
bit integer and "a?-1:0"

    So here is the GCC 10 branch version which fixes the wrong code.
    The problem is we create a negation of an one bit signed integer type
    which is undefined if the value was -1.
    This is not needed for GCC 11 branch since the case is handled differently
    there and has been fixed there (and the trunk has now been fixed too).
    So for one bit types, there is no reason to create the negation so just
    setting neg to false for them, just works.

    OK? Bootstrapped and tested on x86_64-linux-gnu.

            PR tree-optimization/102622

    gcc/ChangeLog:

            * tree-ssa-phiopt.c (conditional_replacement): Set neg
            to false for one bit signed types.

    gcc/testsuite/ChangeLog:

            * gcc.c-torture/execute/bitfld-10.c: New test.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (24 preceding siblings ...)
  2021-10-11  9:22 ` cvs-commit at gcc dot gnu.org
@ 2021-10-11  9:24 ` pinskia at gcc dot gnu.org
  2021-10-11 21:07 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-11  9:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |10.3.1
            Summary|[9/10 Regression] Wrong     |[9 Regression] Wrong code
                   |code with -O1 and above due |with -O1 and above due to
                   |to phiopt and signed one    |phiopt and signed one bit
                   |bit integer types           |integer types

--- Comment #25 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 10.4.0 now.  Will backport the GCC 10 patch tomorrow/later today.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (25 preceding siblings ...)
  2021-10-11  9:24 ` [Bug tree-optimization/102622] [9 " pinskia at gcc dot gnu.org
@ 2021-10-11 21:07 ` cvs-commit at gcc dot gnu.org
  2021-10-11 21:08 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-11 21:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #26 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Andrew Pinski
<pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:77867cd8185b206124dd24ce8229cc0bf144c078

commit r9-9765-g77867cd8185b206124dd24ce8229cc0bf144c078
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sun Oct 10 23:12:11 2021 +0000

    [GCC 10 branch] tree-optimization: [PR102622]: wrong code due to signed one
bit integer and "a?-1:0"

    So here is the GCC 10 branch version which fixes the wrong code.
    The problem is we create a negation of an one bit signed integer type
    which is undefined if the value was -1.
    This is not needed for GCC 11 branch since the case is handled differently
    there and has been fixed there (and the trunk has now been fixed too).
    So for one bit types, there is no reason to create the negation so just
    setting neg to false for them, just works.

    OK? Bootstrapped and tested on x86_64-linux-gnu.

            PR tree-optimization/102622

    gcc/ChangeLog:

            * tree-ssa-phiopt.c (conditional_replacement): Set neg
            to false for one bit signed types.

    gcc/testsuite/ChangeLog:

            * gcc.c-torture/execute/bitfld-10.c: New test.

    (cherry picked from commit 4111b36079fed95b787fafeed1deaab2dedaf3db)

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (26 preceding siblings ...)
  2021-10-11 21:07 ` cvs-commit at gcc dot gnu.org
@ 2021-10-11 21:08 ` pinskia at gcc dot gnu.org
  2021-10-11 21:19 ` cvs-commit at gcc dot gnu.org
  2021-11-09 19:03 ` cvs-commit at gcc dot gnu.org
  29 siblings, 0 replies; 31+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-11 21:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #27 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed on all branches now.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (27 preceding siblings ...)
  2021-10-11 21:08 ` pinskia at gcc dot gnu.org
@ 2021-10-11 21:19 ` cvs-commit at gcc dot gnu.org
  2021-11-09 19:03 ` cvs-commit at gcc dot gnu.org
  29 siblings, 0 replies; 31+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-11 21:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #28 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Andrew Pinski
<pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:e3c06b990b2458b87f72a0c63e0de72cf69f7fc4

commit r11-9096-ge3c06b990b2458b87f72a0c63e0de72cf69f7fc4
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sun Oct 10 01:28:59 2021 +0000

    tree-optimization: [PR102622]: wrong code due to signed one bit integer and
"a?-1:0"

    Since the problem was already fixed on this branch, we just want to add the
    testcase so it does not regress there.

            PR tree-optimization/102622

    gcc/testsuite/ChangeLog:

            * gcc.c-torture/execute/bitfld-10.c: New test.

    (cherry picked from commit 882d806c1a8f9d2d2ade1133de88d63e5d4fe40c)

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [Bug tree-optimization/102622] [9 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types
  2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
                   ` (28 preceding siblings ...)
  2021-10-11 21:19 ` cvs-commit at gcc dot gnu.org
@ 2021-11-09 19:03 ` cvs-commit at gcc dot gnu.org
  29 siblings, 0 replies; 31+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-09 19:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622

--- Comment #29 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:f7844b6a777cb47fec7208d7bd594f6ce66f1daa

commit r12-5071-gf7844b6a777cb47fec7208d7bd594f6ce66f1daa
Author: Andrew Pinski <apinski@marvell.com>
Date:   Tue Nov 9 09:56:10 2021 +0000

    [Committed] Fix tree-optimization/103152: Still one more -signed1bit issue

    When I fixed PR 102622, I accidently left behind a TYPE_PRECISION
    check which I had there for checking before hand.  This check
    is not needed as the code will handle it correctly anyways.

    Committed as obvious after a bootstrap/test on x86_64-linux-gnu.

            PR tree-optimization/10352

    gcc/ChangeLog:

            * match.pd: Remove check of TYPE_PRECISION for
            the a?0:pow2 case.

    gcc/testsuite/ChangeLog:

            * gcc.c-torture/execute/pr10352-1.c: New test.

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2021-11-09 19:03 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 19:37 [Bug tree-optimization/102622] New: Wrong code with -O3 for skylake-avx512 and icelake-server vsevolod.livinskij at frtk dot ru
2021-10-05 22:21 ` [Bug tree-optimization/102622] [12 Regression] " pinskia at gcc dot gnu.org
2021-10-05 22:36 ` pinskia at gcc dot gnu.org
2021-10-05 23:31 ` pinskia at gcc dot gnu.org
2021-10-06  7:23 ` [Bug tree-optimization/102622] [12 Regression] Wrong code with -O3 for skylake-avx512 and icelake-server by r12-3903 aldyh at gcc dot gnu.org
2021-10-06  8:42 ` rguenth at gcc dot gnu.org
2021-10-06 12:55 ` hjl.tools at gmail dot com
2021-10-06 13:04 ` hjl.tools at gmail dot com
2021-10-06 13:10 ` aldyh at gcc dot gnu.org
2021-10-06 13:12 ` aldyh at gcc dot gnu.org
2021-10-06 13:26 ` hjl.tools at gmail dot com
2021-10-06 14:19 ` aldyh at redhat dot com
2021-10-06 14:21 ` hjl.tools at gmail dot com
2021-10-07 16:07 ` aldyh at gcc dot gnu.org
2021-10-07 21:29 ` pinskia at gcc dot gnu.org
2021-10-07 21:31 ` pinskia at gcc dot gnu.org
2021-10-08  6:04 ` pinskia at gcc dot gnu.org
2021-10-09 22:25 ` pinskia at gcc dot gnu.org
2021-10-10  1:05 ` [Bug tree-optimization/102622] [9/10/12 Regression] Wrong code with -O1 and above due to phiopt and signed one bit integer types pinskia at gcc dot gnu.org
2021-10-10  1:54 ` pinskia at gcc dot gnu.org
2021-10-10  5:49 ` pinskia at gcc dot gnu.org
2021-10-10  9:04 ` cvs-commit at gcc dot gnu.org
2021-10-10  9:06 ` [Bug tree-optimization/102622] [9/10 " pinskia at gcc dot gnu.org
2021-10-10  9:18 ` pinskia at gcc dot gnu.org
2021-10-10 23:21 ` pinskia at gcc dot gnu.org
2021-10-11  9:22 ` cvs-commit at gcc dot gnu.org
2021-10-11  9:24 ` [Bug tree-optimization/102622] [9 " pinskia at gcc dot gnu.org
2021-10-11 21:07 ` cvs-commit at gcc dot gnu.org
2021-10-11 21:08 ` pinskia at gcc dot gnu.org
2021-10-11 21:19 ` cvs-commit at gcc dot gnu.org
2021-11-09 19:03 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).