public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
@ 2021-06-09 17:58 fossum at us dot ibm.com
  2021-06-09 18:35 ` [Bug middle-end/100998] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: fossum at us dot ibm.com @ 2021-06-09 17:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100998
           Summary: bug in experimental GCC12 with optimization '-O1',
                    disappears with optimization '-O0'
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fossum at us dot ibm.com
  Target Milestone: ---

(note: m, i and k are "long int", GEMM_UNROLL_M is 256, COMPSIZE is 1, and 
a, c, aa, cc are of type (float *))

Here's a snippet of our code:

===============================================
for (i = 1; i < GEMM_UNROLL_M; i *= 2){
   if (m & i) {
     if (((m & ~(i - 1)) - i) < 0) { 
       fprintf(stderr, "EEK! m = %ld, i = %ld, ((m & ~(i - 1)) - i) = %ld\n", 
                             m, i, ((m & ~(i - 1)) - i)); 
       fflush(stderr); 
     }
     aa = a + ((m & ~(i - 1)) - i) * k * COMPSIZE;
     cc = c + ((m & ~(i - 1)) - i)     * COMPSIZE;
     ...
     [call a function using aa and cc]
  }
}
===============================================

When we run with -O0, the printout does not occur, and all is well.

When we run with -O1, we see this printout:

EEK! m = 3, i = 1, ((m & ~(i - 1)) - i) = -2

The fact that we get a negative number ends up leading to a 
segfault in the called function, when we try to access the 
first element of the array "aa".

I would be DELIGHTED if you could help me understand that the tested 
construction ((m & ~(i - 1)) - i) is somehow illegal, but I feel like
it should NEVER return a negative value, as long as i is a power of 2,
and (m & i) is not 0.

I'm building this code with GCC12 (a version provided by my colleague
Peter Bergner, and I'm hoping he will add a comment clarifying exactly 
which version of your experimental GCC12 he is using.

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

* [Bug middle-end/100998] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
@ 2021-06-09 18:35 ` pinskia at gcc dot gnu.org
  2021-06-09 18:38 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-09 18:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Keywords|                            |wrong-code
   Last reconfirmed|                            |2021-06-09
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So the tree level looks fine for me:

  _1 = (unsigned int) i_5(D);
  _2 = -_1;
  _9 = (unsigned int) m_6(D);
  _3 = _2 & _9;
  _4 = _3 - _1;
  _7 = (int) _4;

---- CUT ----
This is for:
int f (long int m, long int i)
{
  return ((m & ~(i - 1)) - i);
}

---- CUT ----
The assembly produced for both x86_64 and aarch64 looks correct.
What target is this on?

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

* [Bug middle-end/100998] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
  2021-06-09 18:35 ` [Bug middle-end/100998] " pinskia at gcc dot gnu.org
@ 2021-06-09 18:38 ` pinskia at gcc dot gnu.org
  2021-06-09 18:42 ` [Bug target/100998] [12 Regression] " pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-09 18:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|1                           |0
             Status|WAITING                     |UNCONFIRMED
             Target|                            |powerpc

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
If this is powerpc and on power10, then it is most likely caused by r12-1020.

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

* [Bug target/100998] [12 Regression] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
  2021-06-09 18:35 ` [Bug middle-end/100998] " pinskia at gcc dot gnu.org
  2021-06-09 18:38 ` pinskia at gcc dot gnu.org
@ 2021-06-09 18:42 ` pinskia at gcc dot gnu.org
  2021-06-09 18:51 ` bergner at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-09 18:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

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

* [Bug target/100998] [12 Regression] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
                   ` (2 preceding siblings ...)
  2021-06-09 18:42 ` [Bug target/100998] [12 Regression] " pinskia at gcc dot gnu.org
@ 2021-06-09 18:51 ` bergner at gcc dot gnu.org
  2021-06-09 19:05 ` bergner at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bergner at gcc dot gnu.org @ 2021-06-09 18:51 UTC (permalink / raw)
  To: gcc-bugs

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

Peter Bergner <bergner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |acsawdey at gcc dot gnu.org,
                   |                            |bergner at gcc dot gnu.org,
                   |                            |segher at gcc dot gnu.org

--- Comment #3 from Peter Bergner <bergner at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> If this is powerpc and on power10, then it is most likely caused by r12-1020.

Not arguing with you, but how did you pinpoint this commit?

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

* [Bug target/100998] [12 Regression] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
                   ` (3 preceding siblings ...)
  2021-06-09 18:51 ` bergner at gcc dot gnu.org
@ 2021-06-09 19:05 ` bergner at gcc dot gnu.org
  2021-06-09 19:10 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bergner at gcc dot gnu.org @ 2021-06-09 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Peter Bergner <bergner at gcc dot gnu.org> ---
FYI, I'll give Gordon a build without that patch to test with and see if his
issue goes away with that.

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

* [Bug target/100998] [12 Regression] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
                   ` (4 preceding siblings ...)
  2021-06-09 19:05 ` bergner at gcc dot gnu.org
@ 2021-06-09 19:10 ` pinskia at gcc dot gnu.org
  2021-06-09 19:32 ` bergner at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-09 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Peter Bergner from comment #3)
> (In reply to Andrew Pinski from comment #2)
> > If this is powerpc and on power10, then it is most likely caused by r12-1020.
> 
> Not arguing with you, but how did you pinpoint this commit?

It is just a guess based on understanding what the RTL would look like and what
changes were going on in the powerpc backend and the reporter is from IBM and
you work on the powerpc backend.  Also the code looks correct on both aarch64
and x86_64 so I figured it is most likely a target issue.

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

* [Bug target/100998] [12 Regression] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
                   ` (5 preceding siblings ...)
  2021-06-09 19:10 ` pinskia at gcc dot gnu.org
@ 2021-06-09 19:32 ` bergner at gcc dot gnu.org
  2021-06-09 20:09 ` bergner at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bergner at gcc dot gnu.org @ 2021-06-09 19:32 UTC (permalink / raw)
  To: gcc-bugs

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

Peter Bergner <bergner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |acsawdey at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1

--- Comment #6 from Peter Bergner <bergner at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> It is just a guess based on understanding what the RTL would look like and
> what changes were going on in the powerpc backend and the reporter is from
> IBM and you work on the powerpc backend.  Also the code looks correct on
> both aarch64 and x86_64 so I figured it is most likely a target issue.

And you guessed well!  I built a mainline compiler for Gordon with Aaron's
commit reverted and the issue goes away.  Assigning this to Aaron to debug.

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

* [Bug target/100998] [12 Regression] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
                   ` (6 preceding siblings ...)
  2021-06-09 19:32 ` bergner at gcc dot gnu.org
@ 2021-06-09 20:09 ` bergner at gcc dot gnu.org
  2021-06-09 20:15 ` pinskia at gcc dot gnu.org
  2021-06-09 20:25 ` bergner at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: bergner at gcc dot gnu.org @ 2021-06-09 20:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Peter Bergner <bergner at gcc dot gnu.org> ---
(In reply to Peter Bergner from comment #6)
> And you guessed well!  I built a mainline compiler for Gordon with Aaron's
> commit reverted and the issue goes away.  Assigning this to Aaron to debug.

Talking with Aaron offline, he pointed me at his
52e130652a76ff3d14c0f572fcd79fa53637ce2c fix which is already upstream. 
Checking my sources, I don't have that, so I will retry with an updated
compiler.

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

* [Bug target/100998] [12 Regression] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
                   ` (7 preceding siblings ...)
  2021-06-09 20:09 ` bergner at gcc dot gnu.org
@ 2021-06-09 20:15 ` pinskia at gcc dot gnu.org
  2021-06-09 20:25 ` bergner at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-09 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Peter Bergner from comment #7)
> (In reply to Peter Bergner from comment #6)
> > And you guessed well!  I built a mainline compiler for Gordon with Aaron's
> > commit reverted and the issue goes away.  Assigning this to Aaron to debug.
> 
> Talking with Aaron offline, he pointed me at his
> 52e130652a76ff3d14c0f572fcd79fa53637ce2c fix which is already upstream. 
> Checking my sources, I don't have that, so I will retry with an updated
> compiler.

Yes that looks like it could be in this case, since we are getting 0 - 2 rather
2 - 0

That is for:
  _3 = _2 & _9;
  _4 = _3 - _1;
before that patch, it would be doing basically _1 - _3 instead of the above.

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

* [Bug target/100998] [12 Regression] bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0'
  2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
                   ` (8 preceding siblings ...)
  2021-06-09 20:15 ` pinskia at gcc dot gnu.org
@ 2021-06-09 20:25 ` bergner at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: bergner at gcc dot gnu.org @ 2021-06-09 20:25 UTC (permalink / raw)
  To: gcc-bugs

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

Peter Bergner <bergner at gcc dot gnu.org> changed:

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

--- Comment #9 from Peter Bergner <bergner at gcc dot gnu.org> ---
(In reply to Peter Bergner from comment #7)
> Talking with Aaron offline, he pointed me at his
> 52e130652a76ff3d14c0f572fcd79fa53637ce2c fix which is already upstream. 
> Checking my sources, I don't have that, so I will retry with an updated
> compiler.

Ok, it's confirmed with a new build using Aaron's fallow-on fix the issue goes
away, so I'll close this as ALREADY_FIXED.  Thanks for your help Andrew!

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

end of thread, other threads:[~2021-06-09 20:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 17:58 [Bug c/100998] New: bug in experimental GCC12 with optimization '-O1', disappears with optimization '-O0' fossum at us dot ibm.com
2021-06-09 18:35 ` [Bug middle-end/100998] " pinskia at gcc dot gnu.org
2021-06-09 18:38 ` pinskia at gcc dot gnu.org
2021-06-09 18:42 ` [Bug target/100998] [12 Regression] " pinskia at gcc dot gnu.org
2021-06-09 18:51 ` bergner at gcc dot gnu.org
2021-06-09 19:05 ` bergner at gcc dot gnu.org
2021-06-09 19:10 ` pinskia at gcc dot gnu.org
2021-06-09 19:32 ` bergner at gcc dot gnu.org
2021-06-09 20:09 ` bergner at gcc dot gnu.org
2021-06-09 20:15 ` pinskia at gcc dot gnu.org
2021-06-09 20:25 ` bergner 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).