This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
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.
Created an attachment (id=14158) [edit] Sample Testcase
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
As a missed optimization, this bug adds new information. But as a regression, this is a dup of bug 30905.
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.
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.