From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21320 invoked by alias); 20 Feb 2002 21:56:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 21264 invoked by uid 71); 20 Feb 2002 21:56:01 -0000 Resent-Date: 20 Feb 2002 21:56:01 -0000 Resent-Message-ID: <20020220215601.21260.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, dann@godzilla.ics.uci.edu Received:(qmail 11944 invoked by uid 61); 20 Feb 2002 21:52:16 -0000 Message-Id:<20020220215216.11937.qmail@sources.redhat.com> Date: Wed, 20 Feb 2002 14:16:00 -0000 From: dann@godzilla.ics.uci.edu Reply-To: dann@godzilla.ics.uci.edu To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/5738: GCSE missed optimization X-SW-Source: 2002-02/txt/msg00524.txt.bz2 List-Id: >Number: 5738 >Category: optimization >Synopsis: GCSE missed optimization >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: pessimizes-code >Submitter-Id: net >Arrival-Date: Wed Feb 20 13:56:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: dann@godzilla.ics.uci.edu >Release: CVS >Organization: >Environment: sparc-sun-solaris2.8 >Description: GCSE not working The following code: struct foo { unsigned short *p; }; void func (struct foo *s, unsigned int *coord, _Bool delta) { unsigned short change; if (delta) { change = *((s)->p++); *coord += change; } else { change = *((s)->p++); *coord += change; *coord += *((s)->p++) << 8; } } generates when compiled with gcc from CVS on SPARC (with -O2) func: !#PROLOGUE# 0 !#PROLOGUE# 1 andcc %o2, 0xff, %g0 mov %o0, %o5 be .LL2 mov %o1, %o4 ld [%o0], %o0 ld [%o1], %o2 lduh [%o0], %o3 sll %o3, 16, %o1 srl %o1, 16, %o1 add %o2, %o1, %o2 add %o0, 2, %o0 st %o0, [%o5] b .LL1 st %o2, [%o4] .LL2: ld [%o0], %o0 lduh [%o0], %o3 ld [%o1], %o2 add %o0, 2, %o0 lduh [%o0], %o1 add %o2, %o3, %o2 sll %o1, 8, %o1 add %o2, %o1, %o2 add %o0, 2, %o0 st %o2, [%o4] st %o0, [%o5] .LL1: retl nop GCSE should be able to realize that The sequence: change = *((s)->p++); *coord += change; occurs on both branches of the conditional and move it before. >How-To-Repeat: Compile the code above with -O2 and look at the assembly, one branch of the conditional should be empty. >Fix: n/a >Release-Note: >Audit-Trail: >Unformatted: