public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
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	[thread overview]
Message-ID: <20011023003049.7144.qmail@sourceware.cygnus.com> (raw)

>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];mvp<last[1];mvp++)
              searched_this_root_move[mvp-last[0]]=0;
            search_failed_low=1;
            root_alpha=-32768 -1;
            root_value=root_alpha;
            easy_move=0;
            if (nodes_searched>noise_level && !time_abort && !abort_search) {
            }
          }
          else break;
        }
        else
          break;
      }
      rootx_value = 9;
      if (rootx_value<rootx_beta)
        lastx=rootx_value;
      printf("lastx = %d\n",lastx);
      if (correct) correct_count++;
      else correct_count=0;

        printf("lastx = %d\n",lastx);
        if (value != -(32768 -1))
          return;
    }
}


             reply	other threads:[~2001-10-22 17:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-22 17:36 sje [this message]
2002-01-04 21:33 rodrigc
2002-01-07  8:56 Steve Ellcey
2002-02-17 18:33 rodrigc
2002-03-30 17:01 rth
2002-03-30 17:36 Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20011023003049.7144.qmail@sourceware.cygnus.com \
    --to=sje@cup.hp.com \
    --cc=gcc-gnats@gcc.gnu.org \
    --cc=reva@cup.hp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).