From patchwork Mon May 7 07:36:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 157246 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 C87DDB6EF1 for ; Mon, 7 May 2012 17:37:01 +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=1336981023; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=bWfzkDhVL6FhCrY9d4zdmcE7c4Y=; b=NhIOvPV4ydFdT3u8mwrUJg2V/lEKSiyXKXZ++2Fy3GReIs+0Cv2oY5GJogpPqD SYr3lpxJvNOICVMxo6za+yF/IWlbaJf2LMKzjk0TEki5YUGGQeLPAsiWcdVM5NwB E17AeBhV2qoZA7meM1UMzjnm/7F5tZM4fUsNxDXdqqIfM= 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:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=SCeJ6VoZL0VsNsA9gWB32ItSuSE/q/Hx67Wh+m3P+m7Nr4V4DEqrQTITRog5Jg YRcJJtx3+eveLJkG1wj3HHLgHsG1wLGk2TsgIV6PaV6+0kkN/ZpP3+SG+UGUYFta 1ok5UTOelnVCNM1kq8GumbEM8TuVF7uUrRGmWzWg2/lQY=; Received: (qmail 6980 invoked by alias); 7 May 2012 07:36:55 -0000 Received: (qmail 6627 invoked by uid 22791); 7 May 2012 07:36:52 -0000 X-SWARE-Spam-Status: No, hits=-4.9 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_ZC X-Spam-Check-By: sourceware.org Received: from mail-yx0-f175.google.com (HELO mail-yx0-f175.google.com) (209.85.213.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 May 2012 07:36:39 +0000 Received: by yenm3 with SMTP id m3so4387961yen.20 for ; Mon, 07 May 2012 00:36:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.37.202 with SMTP id y50mr18064295yha.63.1336376198795; Mon, 07 May 2012 00:36:38 -0700 (PDT) Received: by 10.146.124.5 with HTTP; Mon, 7 May 2012 00:36:38 -0700 (PDT) In-Reply-To: <20120507054325.GE16117@tyan-ft48-01.lab.bos.redhat.com> References: <1335533422-11066-1-git-send-email-bonzini@gnu.org> <20120507054325.GE16117@tyan-ft48-01.lab.bos.redhat.com> Date: Mon, 7 May 2012 09:36:38 +0200 Message-ID: Subject: Re: [PATCH] x86: emit tzcnt unconditionally From: Uros Bizjak To: Jakub Jelinek Cc: Paolo Bonzini , gcc-patches@gcc.gnu.org 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 On Mon, May 7, 2012 at 7:43 AM, Jakub Jelinek wrote: >> Index: i386.md >> =================================================================== >> --- i386.md   (revision 187217) >> +++ i386.md   (working copy) >> @@ -12112,9 +12112,22 @@ >>     (set (match_operand:SWI48 0 "register_operand" "=r") >>       (ctz:SWI48 (match_dup 1)))] >>    "" >> -  "bsf{}\t{%1, %0|%0, %1}" >> +{ >> +  if (optimize_function_for_size_p (cfun)) >> +    return "bsf{}\t{%1, %0|%0, %1}"; >> +  else if (TARGET_BMI) >> +    return "tzcnt{}\t{%1, %0|%0, %1}"; >> +  else >> +    /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI.  */ >> +    return "rep; bsf{}\t{%1, %0|%0, %1}"; >> +} > > Shouldn't that be done only for generic tuning?  If somebody uses > -mtune=native, then emitting rep; bsf is overkill, the code is intended > to be run on a CPU without (or with TARGET_BMI with) tzcnt insn support. Yes, this is a good idea. Something like attached patch? Thanks, Uros. Index: i386.md =================================================================== --- i386.md (revision 187223) +++ i386.md (working copy) @@ -12114,18 +12114,22 @@ "" { if (optimize_function_for_size_p (cfun)) - return "bsf{}\t{%1, %0|%0, %1}"; + ; else if (TARGET_BMI) return "tzcnt{}\t{%1, %0|%0, %1}"; - else + else if (TARGET_GENERIC) /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI. */ return "rep; bsf{}\t{%1, %0|%0, %1}"; + + return "bsf{}\t{%1, %0|%0, %1}"; } [(set_attr "type" "alu1") (set_attr "prefix_0f" "1") (set (attr "prefix_rep") (if_then_else - (match_test "optimize_function_for_size_p (cfun)") + (and (match_test "optimize_function_for_size_p (cfun)") + (not (ior (match_test "TARGET_BMI") + (match_test "TARGET_GENERIC")))) (const_string "0") (const_string "1"))) (set_attr "mode" "")]) @@ -12137,18 +12141,22 @@ "" { if (optimize_function_for_size_p (cfun)) - return "bsf{}\t{%1, %0|%0, %1}"; + ; else if (TARGET_BMI) return "tzcnt{}\t{%1, %0|%0, %1}"; - else + else if (TARGET_GENERIC) /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI. */ return "rep; bsf{}\t{%1, %0|%0, %1}"; + + return "bsf{}\t{%1, %0|%0, %1}"; } [(set_attr "type" "alu1") (set_attr "prefix_0f" "1") (set (attr "prefix_rep") (if_then_else - (match_test "optimize_function_for_size_p (cfun)") + (and (match_test "optimize_function_for_size_p (cfun)") + (not (ior (match_test "TARGET_BMI") + (match_test "TARGET_GENERIC")))) (const_string "0") (const_string "1"))) (set_attr "mode" "")])