Summary: | [3.3/3.4 Regression] [strength-reduce] -O2 optimalization produces wrong code | ||
---|---|---|---|
Product: | gcc | Reporter: | samal <samal> |
Component: | rtl-optimization | Assignee: | Eric Botcazou <ebotcazou> |
Status: | RESOLVED FIXED | ||
Severity: | critical | CC: | gcc-bugs |
Priority: | P1 | Keywords: | wrong-code |
Version: | 3.0.4 | ||
Target Milestone: | 3.3.1 | ||
Host: | i386-pc-linux-gnu | Target: | i?86-*-* powerpc-*-* |
Build: | i386-pc-linux-gnu | Known to work: | |
Known to fail: | Last reconfirmed: | 2003-07-16 02:17:44 |
Description
samal@kam.mff.cuni.cz
2003-07-16 01:52:58 UTC
Fix: Compile without optimization or with version 2.95 ... ;-) I can confirm this on i686-pc-linux with gcc 3.0.4, 3.3.1 (20030707), the mainline (20030714) but it did not produce bad code with 2.95.3. I can also confirm this on powerpc-apple-darwin6.6 (mainline 20030715) so it looks to be strength reduce bug because if I use -fno-strength-reduce, I get the correct result. I also get bad code with the mainline (20030715) on i686-unknown-openbsd3.1. The code looks valid to me, no pointers at all so this is not the aliasing problem that the other strength-reduce problems are about. Here is the diff for powerpc with temp.s being the correct code (-O2 -fno-strength-reduce), t.s (-O2): --- t.s Tue Jul 15 22:15:53 2003 +++ temp.s Tue Jul 15 22:15:55 2003 @@ -23,17 +23,19 @@ stwu r1,-80(r1) L12: mr r30,r28 - li r29,2 +L11: addi r28,r28,1 -L19: + li r29,0 +L9: addi r30,r30,1 addis r3,r31,ha16(LC0-"L00000000001$pb") la r3,lo16(LC0-"L00000000001$pb")(r3) + addi r29,r29,1 mr r4,r28 mr r5,r30 bl L_printf$stub - addic. r29,r29,-1 - bge+ cr0,L19 + cmpwi cr7,r29,2 + ble+ cr7,L9 addis r3,r31,ha16(LC1-"L00000000001$pb") mr r4,r28 la r3,lo16(LC1-"L00000000001$pb")(r3) @@ -41,6 +43,8 @@ bl L_printf$stub cmpwi cr7,r30,10 bgt- cr7,L1 + cmpw cr7,r28,r30 + ble+ cr7,L11 addis r3,r31,ha16(LC2-"L00000000001$pb") mr r4,r28 la r3,lo16(LC2-"L00000000001$pb")(r3) Here is a testcase suited for the testsuite: void f(char*,int,int) __attribute__((__noinline__)); void f(char *t,int i,int j){if(t[0]=='C')abort();} int main() { int i; int first= 0; int last= 0; while (last<3) { last = first; while(first<=last) { first++; for (i=0;i<3;i++){ last++; f("A",first,last); } if (last>10) return 0; f("B",first,last); } f("C",first,last); } return 0; } Investigating. Subject: Bug 11536 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2003-07-21 16:52:38 Modified files: gcc : ChangeLog unroll.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: 20030721-1.c Log message: PR optimization/11536 * unroll.c (loop_iterations): Do not replace a register holding the final value by its equivalent before the loop if it is not invariant. PR optimization/11536 * gcc.dg/20030721-1.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.579&r2=2.580 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/unroll.c.diff?cvsroot=gcc&r1=1.200&r2=1.201 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2901&r2=1.2902 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030721-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 Subject: Bug 11536 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-07-21 17:50:05 Modified files: gcc : ChangeLog unroll.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: 20030721-1.c Log message: PR optimization/11536 * unroll.c (loop_iterations): Do not replace a register holding the final value by its equivalent before the loop if it is not invariant. PR optimization/11536 * gcc.dg/20030721-1.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.678&r2=1.16114.2.679 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/unroll.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.184.2.4&r2=1.184.2.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.239&r2=1.2261.2.240 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030721-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1 Fixed in GCC 3.3.1 and GCC 3.4. |