Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 33315
Product:  
Component:  
Status: NEW
Resolution:
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Pranav Bhandarkar <pranav.bhandarkar@gmail.com>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
if.c Sample Testcase text/x-csrc 2007-09-05 19:03 129 bytes Edit
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 33315 depends on: 23286 30905 Show dependency tree
Show dependency graph
Bug 33315 blocks:

Additional Comments:





Mark bug as waiting for feedback
Mark bug as suspended




View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2007-09-05 20:34 Opened: 2007-09-05 18:53
if ( x == 8 ) statement1
if ( x != 8 ) statement1
if ( x == 9 ) statement2
if ( x != 9 ) statement2
should be replaced by

statement1
statement2

However this doesnt happen and compare and jumps do get generated.

------- Comment #1 From Pranav Bhandarkar 2007-09-05 19:03 -------
Created an attachment (id=14158) [edit]
Sample Testcase

------- Comment #2 From Richard Guenther 2007-09-05 20:34 -------
This is related to PR32306 and to the fact that we don't have a code hoisting
pass.  And related to PR30905 because cross-jumping fixes this up on the
rtl-level for both gcc 4.1 and 4.2:

test:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        movl    $0, a
        movl    $0, a+4
        movl    $0, a+8
        ret

------- Comment #3 From Steven Bosscher 2007-11-10 00:27 -------
As a missed optimization, this bug adds new information.  But as a regression,
this is a dup of bug 30905.

------- Comment #4 From Joerg Wunsch 2007-11-23 10:57 -------
Is the missed optimization in the following code the same?

volatile unsigned char *reg_a = (unsigned char *)42;
volatile unsigned char *reg_b = (unsigned char *)34;

extern void a(void);
extern void b(void);
extern void c(void);

void
decide(void)
{
        signed char diff;

        diff = *reg_a - *reg_b;

        if (diff < 0)
                a();
        else if (diff == 0)
                b();
        else if (diff > 0)
                c();
}

The third "if" statement is partially executed: it apparently remembered
that diff could not be less than 0, but it still tests against 0 even
though that test has just been done before.  Verified on both, the AVR
and i386 target.

Interestingly, by just reordering the code, the third condition will
be eliminated by GCC 4.x (but not by GCC 3.x):

volatile unsigned char *reg_a = (unsigned char *)42;
volatile unsigned char *reg_b = (unsigned char *)34;

extern void a(void);
extern void b(void);
extern void c(void);

void
decide(void)
{
        signed char diff;

        diff = *reg_a - *reg_b;

        if (diff < 0)
                a();
        else if (diff > 0)
                c();
        else if (diff == 0)
                b();
}

If someone thinks that's an entirely different thing than the subject of this
bug, please tell me so, and I'll submit a separate one.

------- Comment #5 From Dave Edwards 2008-10-21 08:28 -------
Subject: RE:  If condition not getting eliminated


Hi Ramana,

Please could you add sdkteam-gnu@icerasemi.com - then we all get to see
it ;-)

Cheers,


-----Original Message-----
From: ramana at icerasemi dot com [mailto:gcc-bugzilla@gcc.gnu.org] 
Sent: 21 October 2008 08:04
To: Dave Edwards
Subject: [Bug middle-end/33315] If condition not getting eliminated



-- 

ramana at icerasemi dot com changed:

           What    |Removed                     |Added
------------------------------------------------------------------------
----
                 CC|                            |ramana at icerasemi dot
com


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

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug