From patchwork Tue Dec 7 17:38:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Meissner X-Patchwork-Id: 74586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6AB41B6F10 for ; Wed, 8 Dec 2010 04:39:12 +1100 (EST) Received: (qmail 25029 invoked by alias); 7 Dec 2010 17:39:10 -0000 Received: (qmail 25019 invoked by uid 22791); 7 Dec 2010 17:39:09 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e3.ny.us.ibm.com (HELO e3.ny.us.ibm.com) (32.97.182.143) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 07 Dec 2010 17:39:03 +0000 Received: from d01dlp02.pok.ibm.com (d01dlp02.pok.ibm.com [9.56.224.85]) by e3.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id oB7HKn1v014476 for ; Tue, 7 Dec 2010 12:21:02 -0500 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id D63E64DE8041 for ; Tue, 7 Dec 2010 12:37:09 -0500 (EST) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oB7Hd0BM457098 for ; Tue, 7 Dec 2010 12:39:00 -0500 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oB7HcxTp028000 for ; Tue, 7 Dec 2010 10:38:59 -0700 Received: from hungry-tiger.westford.ibm.com (sig-9-65-200-190.mts.ibm.com [9.65.200.190]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id oB7Hcx2r027965; Tue, 7 Dec 2010 10:38:59 -0700 Received: by hungry-tiger.westford.ibm.com (Postfix, from userid 500) id AA3BEF7CE0; Tue, 7 Dec 2010 12:38:57 -0500 (EST) Date: Tue, 7 Dec 2010 12:38:57 -0500 From: Michael Meissner To: gcc-patches@gcc.gnu.org, rguenther@suse.de, jakub@redhat.com Subject: [PATCH] PR 42327: Add checks for sqrt optab being present before doing pow (x, 0.75) optimization Message-ID: <20101207173857.GA14620@hungry-tiger.westford.ibm.com> Mail-Followup-To: Michael Meissner , gcc-patches@gcc.gnu.org, rguenther@suse.de, jakub@redhat.com MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Content-Scanned: Fidelis XPS MAILER X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Jakub Jelinek and Richard Guenther asked that I put in checks for a port having a sqrt instruction before optimizing pow (x, 0.75) into sqrt(sqrt(x)) * sqrt(x). This patch adds those checks. I did a bootstrap and make check, and there were no regressions. Is this ok to apply to the tree? [gcc] 2010-12-07 Michael Meissner PR middle-end/42694 * builtins.c (expand_builtin_pow_root): Don't optimize pow(x,y) where y is 0.25, 1./6., or 0.75 if the target does not have a sqrt instruction, but do optimize if y is 0.5 or 1./6. since that changes an expensive call into a cheaper one. [gcc/testsuite] 2010-12-07 Michael Meissner PR middle-end/42694 * gcc.target/powerpc/ppc-pow.c: New file to make sure pow (x, 0.75) is not optimized if the machine has no sqrt instruction. Index: gcc/builtins.c =================================================================== --- gcc/builtins.c (revision 167551) +++ gcc/builtins.c (working copy) @@ -3068,7 +3068,8 @@ expand_builtin_pow_root (location_t loc, if (REAL_VALUES_EQUAL (c, dconsthalf)) op = build_call_nofold_loc (loc, sqrtfn, 1, arg0); - else + /* Don't do this optimization if we don't have a sqrt insn. */ + else if (optab_handler (sqrt_optab, mode) != CODE_FOR_nothing) { REAL_VALUE_TYPE dconst1_4 = dconst1; REAL_VALUE_TYPE dconst3_4; @@ -3114,7 +3115,8 @@ expand_builtin_pow_root (location_t loc, op = build_call_nofold_loc (loc, cbrtfn, 1, arg0); /* Now try 1/6. */ - else if (optimize_insn_for_speed_p ()) + else if (optimize_insn_for_speed_p () + && optab_handler (sqrt_optab, mode) != CODE_FOR_nothing) { REAL_VALUE_TYPE dconst1_6 = dconst1_3; SET_REAL_EXP (&dconst1_6, REAL_EXP (&dconst1_6) - 1); Index: gcc/testsuite/gcc.target/powerpc/ppc-pow.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/ppc-pow.c (revision 0) +++ gcc/testsuite/gcc.target/powerpc/ppc-pow.c (revision 0) @@ -0,0 +1,34 @@ +/* { dg-do compile { target { { powerpc*-*-* } && { ! powerpc*-apple-darwin* } } } } */ +/* { dg-options "-O2 -ffast-math -mcpu=power6" } */ +/* { dg-final { scan-assembler-times "fsqrt" 3 } } */ +/* { dg-final { scan-assembler-times "fmul" 1 } } */ +/* { dg-final { scan-assembler-times "bl pow" 1 } } */ +/* { dg-final { scan-assembler-times "bl sqrt" 1 } } */ + +double +do_pow_0_75_default (double a) +{ + return __builtin_pow (a, 0.75); /* should generate 2 fsqrts */ +} + +double +do_pow_0_5_default (double a) +{ + return __builtin_pow (a, 0.5); /* should generate fsqrt */ +} + +#pragma GCC target "no-powerpc-gpopt,no-powerpc-gfxopt" + +double +do_pow_0_75_nosqrt (double a) +{ + return __builtin_pow (a, 0.75); /* should call pow */ +} + +double +do_pow_0_5_nosqrt (double a) +{ + return __builtin_pow (a, 0.5); /* should call sqrt */ +} + +#pragma GCC reset_options