From patchwork Wed Feb 2 23:25:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 81592 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 650D1B70EC for ; Thu, 3 Feb 2011 10:25:23 +1100 (EST) Received: (qmail 21882 invoked by alias); 2 Feb 2011 23:25:21 -0000 Received: (qmail 21873 invoked by uid 22791); 2 Feb 2011 23:25:20 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 02 Feb 2011 23:25:16 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p12NPE3c011102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Feb 2011 18:25:15 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p12NPD2b006771 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 2 Feb 2011 18:25:14 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p12NPDFG014888 for ; Thu, 3 Feb 2011 00:25:13 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p12NPDQP014887 for gcc-patches@gcc.gnu.org; Thu, 3 Feb 2011 00:25:13 +0100 Date: Thu, 3 Feb 2011 00:25:13 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix FMA_EXPR expansion if fma insn isn't supported (PR target/47312) Message-ID: <20110202232513.GP30899@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 Hi! If target setting ends up being different between cc1 and lto1 compilation, we can have FMA_EXPRs in the IL which ICE during expansion, as there is no insn for them. The following patch fixes it by expanding it as a fma{,l,f} call in that case (x * y + z). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-02-02 Jakub Jelinek PR target/47312 * expr.c (expand_expr_real_2) : If target doesn't expand fma, expand FMA_EXPR as fma{,f,l} call. * gcc.target/i386/pr47312.c: New test. Jakub --- gcc/expr.c.jj 2011-01-28 20:35:51.000000000 +0100 +++ gcc/expr.c 2011-02-02 17:34:32.121461641 +0100 @@ -7695,6 +7695,34 @@ expand_expr_real_2 (sepops ops, rtx targ optab opt = fma_optab; gimple def0, def2; + /* If there is no insn for FMA, emit it as __builtin_fma{,f,l} + call. */ + if (optab_handler (fma_optab, mode) == CODE_FOR_nothing) + { + tree fn = built_in_decls[BUILT_IN_FMA], call_expr; + + if (fn != NULL_TREE + && mode != TYPE_MODE (TREE_TYPE (TREE_TYPE (fn)))) + fn = NULL_TREE; + if (fn == NULL_TREE) + { + fn = built_in_decls[BUILT_IN_FMAF]; + if (fn != NULL_TREE + && mode != TYPE_MODE (TREE_TYPE (TREE_TYPE (fn)))) + fn = NULL_TREE; + } + if (fn == NULL_TREE) + { + fn = built_in_decls[BUILT_IN_FMAL]; + if (fn != NULL_TREE + && mode != TYPE_MODE (TREE_TYPE (TREE_TYPE (fn)))) + fn = NULL_TREE; + } + gcc_assert (fn != NULL_TREE); + call_expr = build_call_expr (fn, 3, treeop0, treeop1, treeop2); + return expand_builtin (call_expr, target, subtarget, mode, false); + } + def0 = get_def_for_expr (treeop0, NEGATE_EXPR); def2 = get_def_for_expr (treeop2, NEGATE_EXPR); --- gcc/testsuite/gcc.target/i386/pr47312.c.jj 2011-02-02 17:39:11.600424932 +0100 +++ gcc/testsuite/gcc.target/i386/pr47312.c 2011-02-02 17:48:59.407388842 +0100 @@ -0,0 +1,23 @@ +/* PR target/47312 */ +/* { dg-do link } */ +/* { dg-require-effective-target lto } */ +/* { dg-require-effective-target xop } */ +/* { dg-options "-O -flto -mno-sse3 -mxop" } */ + +extern double fma (double, double, double); +extern float fmaf (float, float, float); +extern long double fmal (long double, long double, long double); + +volatile float f; +volatile double d; +volatile long double ld; + +int +main () +{ + f = fmaf (f, f, f); + d = fma (d, d, d); + ld = fmal (ld, ld, ld); + asm volatile ("" : : "r" (&f), "r" (&d), "r" (&ld) : "memory"); + return 0; +}