public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/22266] New: bad code generation at -O1 (conditional expression and constants)
@ 2005-07-01 10:29 A dot Salwa at osmosys dot tv
  2005-07-01 10:31 ` [Bug tree-optimization/22266] " A dot Salwa at osmosys dot tv
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: A dot Salwa at osmosys dot tv @ 2005-07-01 10:29 UTC (permalink / raw)
  To: gcc-bugs

The attached code is compiled OK at -O0 level, but at -O1 it produces bad results.
The bug occurs somewhere in expression:

((a)==INT_MIN && (b)==-1)?(INT_MIN):((a)/(b))

where a and b are ints.
a is not INT_MIN and b is not -1, so division shall be performed. But at -O1
INT_MIN is returned instead.

gcc version 4.0.0 20050519 (Red Hat 4.0.0-8)

Attached is full preprocessed source (*.i file) and a shell script that tries to
detect which compilation flag causes the failure. It shows that the test passes
when compiled with '-O1 -fno-tree-ccp'.

tree-ccp_bug.c file (just for quick reading; I'll attach full *.i file in a few
seconds anyway):

#include <stdio.h>
#include <limits.h>

#define i_div(a, b)  (((a)==INT_MIN && (b)==-1)?(INT_MIN):((a)/(b)))

// 2 macros just to make an assignment look a bit more complicated for compiler:
#define i_low_set(a, b)    \
    ((a)&=(int)0xffff0000UL, (a)|=(int)(unsigned short)(b))

#define i_high_set(a, b)   \
    ((a)&=(int)0x0000ffffL, (a)|=((int)(short)(b))<<16)

int main(int argv, char*argc) {

    int d1;
    int d2;
    int s1, s2;
    int b;

    i_high_set(d1, 0x344);
    i_low_set(d1, 0x4567);
    //d1 = 0x3444567; // this makes test pass

    i_high_set(d2, 0);
    i_low_set(d2, 0x3b9a);

    printf(" dividend >>: %ld\n", d1);
    printf(" divisor  >>: %ld\n", d2);

    // just to check that the subexpression alone is computed correctly:
    b = (d1)==INT_MIN && (d2)==-1;

    s1 = d1/d2;
    s2 = i_div(d1, d2);

    printf(" results >>: %d, %ld, %ld\n", b, s1, s2);

    if(s1!=s2)
        printf(" FAILED\n");
}

-- 
           Summary: bad code generation at -O1 (conditional expression and
                    constants)
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: A dot Salwa at osmosys dot tv
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22266


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

* [Bug tree-optimization/22266] bad code generation at -O1 (conditional expression and constants)
  2005-07-01 10:29 [Bug tree-optimization/22266] New: bad code generation at -O1 (conditional expression and constants) A dot Salwa at osmosys dot tv
@ 2005-07-01 10:31 ` A dot Salwa at osmosys dot tv
  2005-07-01 10:32 ` A dot Salwa at osmosys dot tv
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: A dot Salwa at osmosys dot tv @ 2005-07-01 10:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From A dot Salwa at osmosys dot tv  2005-07-01 10:31 -------
Created an attachment (id=9186)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9186&action=view)
full preprocessed source


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22266


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

* [Bug tree-optimization/22266] bad code generation at -O1 (conditional expression and constants)
  2005-07-01 10:29 [Bug tree-optimization/22266] New: bad code generation at -O1 (conditional expression and constants) A dot Salwa at osmosys dot tv
  2005-07-01 10:31 ` [Bug tree-optimization/22266] " A dot Salwa at osmosys dot tv
@ 2005-07-01 10:32 ` A dot Salwa at osmosys dot tv
  2005-07-01 10:44 ` A dot Salwa at osmosys dot tv
  2005-07-01 15:53 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: A dot Salwa at osmosys dot tv @ 2005-07-01 10:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From A dot Salwa at osmosys dot tv  2005-07-01 10:32 -------
Created an attachment (id=9187)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9187&action=view)
a simple shell script that runs test with various compilation flags


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22266


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

* [Bug tree-optimization/22266] bad code generation at -O1 (conditional expression and constants)
  2005-07-01 10:29 [Bug tree-optimization/22266] New: bad code generation at -O1 (conditional expression and constants) A dot Salwa at osmosys dot tv
  2005-07-01 10:31 ` [Bug tree-optimization/22266] " A dot Salwa at osmosys dot tv
  2005-07-01 10:32 ` A dot Salwa at osmosys dot tv
@ 2005-07-01 10:44 ` A dot Salwa at osmosys dot tv
  2005-07-01 15:53 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: A dot Salwa at osmosys dot tv @ 2005-07-01 10:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From A dot Salwa at osmosys dot tv  2005-07-01 10:44 -------
It looks like a 3.4/4.0 regression - it works fine on gcc 3.4.3.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22266


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

* [Bug tree-optimization/22266] bad code generation at -O1 (conditional expression and constants)
  2005-07-01 10:29 [Bug tree-optimization/22266] New: bad code generation at -O1 (conditional expression and constants) A dot Salwa at osmosys dot tv
                   ` (2 preceding siblings ...)
  2005-07-01 10:44 ` A dot Salwa at osmosys dot tv
@ 2005-07-01 15:53 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-01 15:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-01 15:52 -------
You are using an unitialized variable and putting it together piece wise,  This is undefined hence the 
warning with -Wall.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22266


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

end of thread, other threads:[~2005-07-01 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-01 10:29 [Bug tree-optimization/22266] New: bad code generation at -O1 (conditional expression and constants) A dot Salwa at osmosys dot tv
2005-07-01 10:31 ` [Bug tree-optimization/22266] " A dot Salwa at osmosys dot tv
2005-07-01 10:32 ` A dot Salwa at osmosys dot tv
2005-07-01 10:44 ` A dot Salwa at osmosys dot tv
2005-07-01 15:53 ` pinskia at gcc dot gnu dot 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).