From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10100 invoked by alias); 23 Apr 2012 12:50:29 -0000 Received: (qmail 10086 invoked by uid 22791); 23 Apr 2012 12:50:27 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,TW_BG X-Spam-Check-By: sourceware.org Received: from mail-gy0-f175.google.com (HELO mail-gy0-f175.google.com) (209.85.160.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Apr 2012 12:50:14 +0000 Received: by ghbz2 with SMTP id z2so6478172ghb.20 for ; Mon, 23 Apr 2012 05:50:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.101.134.40 with SMTP id l40mr4524256ann.33.1335185413761; Mon, 23 Apr 2012 05:50:13 -0700 (PDT) Received: by 10.101.118.15 with HTTP; Mon, 23 Apr 2012 05:50:13 -0700 (PDT) In-Reply-To: References: Date: Mon, 23 Apr 2012 12:50:00 -0000 Message-ID: Subject: Re: A case where PHI-OPT pessimizes the code From: Steven Bosscher To: Richard Guenther Cc: GCC Mailing List , Richard Guenther , Alan Modra Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg00783.txt.bz2 On Mon, Apr 23, 2012 at 2:27 PM, Richard Guenther wrote: > int foo (_Bool b) > { > =A0if (b) > =A0 =A0return 1; > =A0else > =A0 =A0return 0; > } Indeed PHI-OPT performs the transformation on this code, too. But the resulting code on powerpc64 is fine: [stevenb@gcc1-power7 gcc]$ cat t.c.149t.optimized ;; Function foo (foo, funcdef_no=3D0, decl_uid=3D1996, cgraph_uid=3D0) foo (_Bool b) { int D.2006; : D.2006_4 =3D (int) b_2(D); return D.2006_4; } [stevenb@gcc1-power7 gcc]$ cat t.s .file "t.c" .section ".toc","aw" .section ".text" .align 2 .p2align 4,,15 .globl foo .section ".opd","aw" .align 3 foo: .quad .L.foo,.TOC.@tocbase,0 .previous .type foo, @function .L.foo: blr .long 0 .byte 0,0,0,0,0,0,0,0 .size foo,.-.L.foo .ident "GCC: (GNU) 4.8.0 20120418 (experimental) [trunk revision 186580]" [stevenb@gcc1-power7 gcc]$ However, this C test case shows the problem: [stevenb@gcc1-power7 gcc]$ head -n 24 t.c #define ONEUL (1UL) int foo (long unsigned int a) { _Bool b; long unsigned int cst, csui; if (a > 27) goto return_zero; /*cst =3D 217579583UL;*/ cst =3D (ONEUL << 0) | (ONEUL << 1) | (ONEUL << 2) | (ONEUL << 3) | (ONEUL << 4) | (ONEUL << 5) | (ONEUL << 19) | (ONEUL << 20) | (ONEUL << 21) | (ONEUL << 22) | (ONEUL << 23) | (ONEUL << 26) | (ONEUL << 27); csui =3D (ONEUL << a); b =3D ((csui & cst) !=3D 0); if (b) return 1; else return 0; return_zero: return 0; } [stevenb@gcc1-power7 gcc]$ ./cc1 -quiet -O2 -fdump-tree-all t.c [stevenb@gcc1-power7 gcc]$ cat t.s .file "t.c" .section ".toc","aw" .section ".text" .align 2 .p2align 4,,15 .globl foo .section ".opd","aw" .align 3 foo: .quad .L.foo,.TOC.@tocbase,0 .previous .type foo, @function .L.foo: cmpldi 7,3,27 bgt 7,.L3 li 10,1 lis 9,0xcf8 sld 3,10,3 ori 9,9,63 and. 10,3,9 mfcr 9 rlwinm 9,9,3,1 xori 3,9,1 blr .p2align 4,,15 .L3: .L2: li 3,0 blr .long 0 .byte 0,0,0,0,0,0,0,0 .size foo,.-.L.foo .ident "GCC: (GNU) 4.8.0 20120418 (experimental) [trunk revision 186580]" I will file a PR for this later today, maybe after trying on a few other targets to see if this is a middle-end problem or a target issue. Ciao! Steven