From patchwork Mon May 30 10:07:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 97900 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 4A6C9B6F64 for ; Mon, 30 May 2011 20:10:55 +1000 (EST) Received: (qmail 25679 invoked by alias); 30 May 2011 10:10:53 -0000 Received: (qmail 25668 invoked by uid 22791); 30 May 2011 10:10:52 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS 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; Mon, 30 May 2011 10:10:38 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4UAAcPb022694 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 30 May 2011 06:10:38 -0400 Received: from freie.oliva.athome.lsd.ic.unicamp.br (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4UAAaDg005204 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 30 May 2011 06:10:37 -0400 Received: from livre.localdomain (livre-to-gw.oliva.athome.lsd.ic.unicamp.br [172.31.160.19]) by freie.oliva.athome.lsd.ic.unicamp.br (8.14.4/8.14.4) with ESMTP id p4UAAZbX007843 for ; Mon, 30 May 2011 07:10:35 -0300 Received: from livre.localdomain (aoliva@localhost.localdomain [127.0.0.1]) by livre.localdomain (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p4UA7T4C027966; Mon, 30 May 2011 07:07:29 -0300 Received: (from aoliva@localhost) by livre.localdomain (8.14.3/8.14.3/Submit) id p4UA7STX027964; Mon, 30 May 2011 07:07:28 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [x86] fix FMA cost computation Date: Mon, 30 May 2011 07:07:28 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 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 One of my patches for PR48866 mysteriously regressed fma3-fma.c. It turned out that a rearrangement in the order of emitting insns during expansion caused combine to attempt combinations in a different order, and this ended up exposing a latent error in the cost computation of FMA insns, that caused a desirable combination to be regarded as not profitable. The problem was that, when stripping out NEGs from operands, that would be costless in FMA variants, we took the sub-operand from the wrong variable. Oops. I took the opportunity to fix the names of the fma_fnm* patterns, that were missing the ā€œnā€. Regstrapped on x86_64-linux-gnu and i686-linux-gnu. Ok to install? for gcc/ChangeLog from Alexandre Oliva * config/i386/i386.c (ix86_rtx_costs): Drop NEG from sub for FMA. * config/i386/sse.md: Add n to negated FMA pattern names. Index: gcc/config/i386/i386.c =================================================================== --- gcc/config/i386/i386.c.orig 2011-05-26 05:03:11.755995482 -0300 +++ gcc/config/i386/i386.c 2011-05-26 05:03:20.639013123 -0300 @@ -29231,12 +29231,12 @@ ix86_rtx_costs (rtx x, int code, int out /* Negate in op0 or op2 is free: FMS, FNMA, FNMS. */ sub = XEXP (x, 0); if (GET_CODE (sub) == NEG) - sub = XEXP (x, 0); + sub = XEXP (sub, 0); *total += rtx_cost (sub, FMA, speed); sub = XEXP (x, 2); if (GET_CODE (sub) == NEG) - sub = XEXP (x, 0); + sub = XEXP (sub, 0); *total += rtx_cost (sub, FMA, speed); return true; } Index: gcc/config/i386/sse.md =================================================================== --- gcc/config/i386/sse.md.orig 2011-05-26 05:03:11.755995482 -0300 +++ gcc/config/i386/sse.md 2011-05-26 05:03:20.642013129 -0300 @@ -1731,7 +1731,7 @@ [(set_attr "type" "ssemuladd") (set_attr "mode" "")]) -(define_insn "*fma_fmadd_" +(define_insn "*fma_fnmadd_" [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x") (fma:FMAMODE (neg:FMAMODE @@ -1746,7 +1746,7 @@ [(set_attr "type" "ssemuladd") (set_attr "mode" "")]) -(define_insn "*fma_fmsub_" +(define_insn "*fma_fnmsub_" [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x") (fma:FMAMODE (neg:FMAMODE