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

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).