From mboxrd@z Thu Jan 1 00:00:00 1970 From: sje@cup.hp.com To: gcc-gnats@gcc.gnu.org Cc: reva@cup.hp.com Subject: c/4648: gcc generates bad code at -O2 for SPEC crafty pgm on HPPA 32 HP-UX Date: Mon, 22 Oct 2001 17:36:00 -0000 Message-id: <20011023003049.7144.qmail@sourceware.cygnus.com> X-SW-Source: 2001-10/msg00478.html List-Id: >Number: 4648 >Category: c >Synopsis: gcc generates bad code at -O2 for SPEC crafty pgm on HPPA 32 HP-UX >Confidential: no >Severity: serious >Priority: high >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Mon Oct 22 17:36:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: reva@cup.hp.com >Release: 3.0 >Organization: >Environment: HP-UX B.11.00 on HPPA (32 bits) >Description: GCC generates bad code for the SPEC crafty program at -O2. The problem goes away with -fno-schedule-insns or with -fno-gcse. It seems to be related to the if-conversion optimization but it may be a scheduler bug that is exposed by if-conversion. A test program (bug.c) is attached, and here is the bad assembly language that gets generated along with some comments on what is wrong with it. L$0044 ldi 9,%r20 copy %r20,%r19 ldil LR'L$C0002,%r23 ldo RR'L$C0002(%r23),%r26 ldw RR'lastx-$global$(%r1),%r22 addil LR'rootx_beta-$global$,%r27 ldw RR'rootx_beta-$global$(%r1),%r21 addil LR'rootx_value-$global$,%r27 ==> updates r1 for rootx_value copy %r1,%r23 comclr,> %r21,%r19,%r0 copy %r22,%r19 stw %r20,RR'rootx_value-$global$(%r23) ==> stores 9 into rootx_value stw %r19,RR'lastx-$global$(%r1) ==> tries to store 9 into lastx, but we have the wrong location since r1 has not been updated for lastx. The next addil instruction has to come before the stw into lastx. addil LR'lastx-$global$,%r27 .CALL ARGW0=GR,ARGW1=GR bl printf,%r2 >How-To-Repeat: Compile bug.c with -O0 and you will get two prints saying "lastx = 9". If you compile with -O2 you get two prints saying "lastx = 3", which is incorrect. >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="bug.c" Content-Disposition: inline; filename="bug.c" char auto_kibitz_list[100][20]; int root_alpha; int root_beta; int root_value; int iteration_depth; int search_failed_high; int search_failed_low; int easy_move; int time_abort; unsigned int nodes_searched; int trace_level; signed char abort_search; signed char searched_this_root_move[256]; int *last[65]; unsigned int noise_level; unsigned int root_nodes[256]; int lastx; int rootx_beta; int rootx_value; main() { Iterate(5,6,9); } int Iterate(int wtm, int search_type, int root_list_done) { int *mvp; char buffer[500], *buffp, *bufftemp; int i, value=0, time_used; int twtm, used_w, used_b; int cpu_start, cpu_end; int correct, correct_count, material=0, sorted, temp; lastx = 3; rootx_beta = 32768; rootx_value = 1; for (i=0;i<256;i++) root_nodes[i]=0; for (;iteration_depth<=60;iteration_depth++) { if (trace_level) { printf("==================================\n"); printf("= search iteration %2d =\n",iteration_depth); printf("==================================\n"); } search_failed_high=0; search_failed_low=0; while (!time_abort && !abort_search) { if (value >= root_beta) { search_failed_high=1; root_alpha=root_beta-1; root_value=root_alpha; root_beta=32768 +1; searched_this_root_move[0]=0; } else if (value <= root_alpha) { if (!search_failed_high) { for (mvp=last[0];mvpnoise_level && !time_abort && !abort_search) { } } else break; } else break; } rootx_value = 9; if (rootx_value