From patchwork Thu Aug 23 21:01:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teresa Johnson X-Patchwork-Id: 179721 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 0874A2C008F for ; Fri, 24 Aug 2012 07:01:50 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1346360511; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=HRtA1Wq fM8koOq8na6zJp2CJ0+Q=; b=eevBsW9zltsAFOv1HIPt2/1zOmssknvhzePsEjq 0bRMAGHzIPehtBnCq4Ap2ONJNcx9cE2n8JSS1GLAsshRPCU4MIGPBPJs5U2ve0s1 fUVxNDxmFZnap2FPris3EYTa4KmBnCbh5cJSZLbOSMkUfBk/6nQZ/e/7QAtI+h7Y jOmM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:X-System-Of-Record:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=EK4bELbCBVrGrnJJVn1XmvHbaYMVTejUm0AXqtc44wwk/gCUhlBe2qEPRwfrPN eud+G/kfVP2kqLQc7RWMxTqVWbOhAAH41f+iDgVCbiw0ovq3cSfKfiWGB4UmkVVz +GrcRWkA1vd9s4GM/xX4sdKfL8kTGi0Yo2qjIGUHj6HP8=; Received: (qmail 9693 invoked by alias); 23 Aug 2012 21:01:46 -0000 Received: (qmail 9681 invoked by uid 22791); 23 Aug 2012 21:01:45 -0000 X-SWARE-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_XF X-Spam-Check-By: sourceware.org Received: from mail-vb0-f47.google.com (HELO mail-vb0-f47.google.com) (209.85.212.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 23 Aug 2012 21:01:23 +0000 Received: by vbbfr13 with SMTP id fr13so1462500vbb.20 for ; Thu, 23 Aug 2012 14:01:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-system-of-record:x-gm-message-state; bh=3cOsk5jzTGTCyCBIChKiDDMYJY+STw2PhxAoz8fAutc=; b=N7hD0UpOOmqhy5Cz4TrzJOjSIVPUI0RaU6x/ZZ4tz0pnya8qy7WtEEQixNkdvAXTau 1rpSA4Jr298GNTrhzHD92J45iWU/W+AYItbZL3sKbD6WeNrYxuFxJokdFsG144Q6Kih0 mqDaA8NbSBbPVYEL6V1BEdey8TbQQmU4ygm2p6JBZbFrCc0yGudlcIF8lSjEVPgyO2wy y2NFF5i1UucNz7FyxBSdGmm5MZGit42kEmsAPLX/vqDp9sAJZoDOmlgCo/zTBpaOauu3 Cf5K2DjKC/0FwFGMtafkSVEsEpLtO7OChdJYlBeWvRxsLo3DUI5f9XeUP2e/a6/i+xnP KeeA== Received: by 10.58.35.51 with SMTP id e19mr2825558vej.27.1345755682516; Thu, 23 Aug 2012 14:01:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.58.35.51 with SMTP id e19mr2825546vej.27.1345755682339; Thu, 23 Aug 2012 14:01:22 -0700 (PDT) Received: by 10.58.14.168 with HTTP; Thu, 23 Aug 2012 14:01:22 -0700 (PDT) Date: Thu, 23 Aug 2012 14:01:22 -0700 Message-ID: Subject: [google/4_7] New fix to avoid LCP stalling andw with 0xff From: Teresa Johnson To: gcc-patches@gcc.gnu.org, David Li X-System-Of-Record: true X-Gm-Message-State: ALoCoQnvX+i44xAMHlOBhg9IDHIjy0yaQ89fgdPRTC2a8OaCUcnZdjpZAm4VEeKHA6C+pMLdRVyAakJWsGxErQDbSXlDU4uIT7yTuvaxJuL/O50MoF3N3JtbrXA3s+LvPKSy7dvKt5409b5ZQCCDRbHKHQYQo04/AC3f4pppm4SNygQlYWOdVAMfiX3aa5RZER5m3lBCwAR4 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 This patch is for google branches only. This is the patch I plan to apply after reverting an earlier set of patches ported over from trunk that addressed the same problem but were causing some performance regressions. This is a narrower fix I had originally prepared before finding the trunk patches. This addresses only the specific problem of the and*i_1 patterns preferring to match an earlier set of patterns "r,0,Z" when the source and dest registers are the same, thus preferring to keep the instruction as an "andw" instead of using a zero-extending move when the constant is 0xff. We now will prefer to convert to a zero-extending move when the constant is 0xff and the machine has LCP stalls. Google ref b/6615073. Tested with crosstool. Ok for google-4_7? 2012-08-23 Teresa Johnson * config/i386/i386.md (anddi_1): Add new r,qm,Lh pattern first to catch an and with 0xff that would be turned into an andw on machines with length-changing prefix stalls, and instead convert it into a zero-extending move. (andsi_1, andhi_1): Ditto. * config/i386/constraints.md (La): Rename from "L". (Lh): New constraint to match possible LCP stalling ands. * config/i386/i386.c (ix86_binary_operator_ok): Update for rename of "L" constraint. Index: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 188251) +++ config/i386/i386.md (working copy) @@ -7697,10 +7697,10 @@ "ix86_expand_binary_operator (AND, mode, operands); DONE;") (define_insn "*anddi_1" - [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r,r") + [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,rm,r,r") (and:DI - (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,qm") - (match_operand:DI 2 "x86_64_szext_general_operand" "Z,re,rm,L"))) + (match_operand:DI 1 "nonimmediate_operand" "%qm,0,0,0,qm") + (match_operand:DI 2 "x86_64_szext_general_operand" "Lh,Z,re,rm,La"))) (clobber (reg:CC FLAGS_REG))] "TARGET_64BIT && ix86_binary_operator_ok (AND, DImode, operands)" { @@ -7738,8 +7738,8 @@ return "and{q}\t{%2, %0|%0, %2}"; } } - [(set_attr "type" "alu,alu,alu,imovx") - (set_attr "length_immediate" "*,*,*,0") + [(set_attr "type" "imovx,alu,alu,alu,imovx") + (set_attr "length_immediate" "0,*,*,*,0") (set (attr "prefix_rex") (if_then_else (and (eq_attr "type" "imovx") @@ -7747,12 +7747,12 @@ (match_operand 1 "ext_QIreg_operand" ""))) (const_string "1") (const_string "*"))) - (set_attr "mode" "SI,DI,DI,SI")]) + (set_attr "mode" "SI,SI,DI,DI,SI")]) (define_insn "*andsi_1" - [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r,r") - (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,qm") - (match_operand:SI 2 "x86_64_general_operand" "re,rm,L"))) + [(set (match_operand:SI 0 "nonimmediate_operand" "=r,rm,r,r") + (and:SI (match_operand:SI 1 "nonimmediate_operand" "%qm,0,0,qm") + (match_operand:SI 2 "x86_64_general_operand" "Lh,re,rm,La"))) (clobber (reg:CC FLAGS_REG))] "ix86_binary_operator_ok (AND, SImode, operands)" { @@ -7783,7 +7783,7 @@ return "and{l}\t{%2, %0|%0, %2}"; } } - [(set_attr "type" "alu,alu,imovx") + [(set_attr "type" "imovx,alu,alu,imovx") (set (attr "prefix_rex") (if_then_else (and (eq_attr "type" "imovx") @@ -7791,7 +7791,7 @@ (match_operand 1 "ext_QIreg_operand" ""))) (const_string "1") (const_string "*"))) - (set_attr "length_immediate" "*,*,0") + (set_attr "length_immediate" "0,*,*,0") (set_attr "mode" "SI")]) ;; See comment for addsi_1_zext why we do use nonimmediate_operand @@ -7807,9 +7807,9 @@ (set_attr "mode" "SI")]) (define_insn "*andhi_1" - [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r") - (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,qm") - (match_operand:HI 2 "general_operand" "rn,rm,L"))) + [(set (match_operand:HI 0 "nonimmediate_operand" "=r,rm,r,r") + (and:HI (match_operand:HI 1 "nonimmediate_operand" "%qm,0,0,qm") + (match_operand:HI 2 "general_operand" "Lh,rn,rm,L"))) (clobber (reg:CC FLAGS_REG))] "ix86_binary_operator_ok (AND, HImode, operands)" { @@ -7826,15 +7826,15 @@ return "and{w}\t{%2, %0|%0, %2}"; } } - [(set_attr "type" "alu,alu,imovx") - (set_attr "length_immediate" "*,*,0") + [(set_attr "type" "imovx,alu,alu,imovx") + (set_attr "length_immediate" "0,*,*,0") (set (attr "prefix_rex") (if_then_else (and (eq_attr "type" "imovx") (match_operand 1 "ext_QIreg_operand" "")) (const_string "1") (const_string "*"))) - (set_attr "mode" "HI,HI,SI")]) + (set_attr "mode" "SI,HI,HI,SI")]) ;; %%% Potential partial reg stall on alternative 2. What to do? (define_insn "*andqi_1" Index: config/i386/constraints.md =================================================================== --- config/i386/constraints.md (revision 184516) +++ config/i386/constraints.md (working copy) @@ -148,13 +148,19 @@ (and (match_code "const_int") (match_test "IN_RANGE (ival, -128, 127)"))) -(define_constraint "L" +(define_constraint "La" "@code{0xFF}, @code{0xFFFF} or @code{0xFFFFFFFF} for AND as a zero-extending move." (and (match_code "const_int") (match_test "ival == 0xff || ival == 0xffff || ival == (HOST_WIDE_INT) 0xffffffff"))) +(define_constraint "Lh" + "@code{0xFF} for AND as a zero-extending move when there are LCP stalls." + (and (match_code "const_int") + (match_test "ival == 0xff") + (match_test "TARGET_LCP_STALL"))) + (define_constraint "M" "0, 1, 2, or 3 (shifts for the @code{lea} instruction)." (and (match_code "const_int") Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 188251) +++ config/i386/i386.c (working copy) @@ -16331,7 +16331,7 @@ ix86_binary_operator_ok (enum rtx_code code, enum && (mode == HImode || mode == SImode || (TARGET_64BIT && mode == DImode)) - && satisfies_constraint_L (src2)); + && satisfies_constraint_La (src2)); return true; }