From patchwork Sun May 6 23:04:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 157197 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 C4C80B6FAF for ; Mon, 7 May 2012 09:04:57 +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=1336950299; 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=XWw8L2yT/TgWhSKP6XnYV3VLAi8=; b=u1EEXcDRL43m1LYu3/MtV2LAg1e6+FpkQcIN/qobsp2BZVOTX4MT5Ih9rRyeXe 4RgHNRm8RrTiv9LiFvRp/xa0E0gsePtHX5bnKj45/7/noSLVLAose6uBaCU5Qm6Z ToDcU2JbNunQKuszucmY1fHUNdCIAXI5O4D8bg4uRqDvM= 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=MRF5og6PTEky8B79DVl7JA/Etg5UxTIWuoZV9dCfS/a5YI7q2v0dTKyJL2s9lc E02WH6LczvzAevzTQ78mzGggle4XGHX6uoblxNDD2AZB7YNp+sgoOrN4MYqNx8DD /UnRmEJrxCBlaCD5A4CsovO0qdiaXrqtz6TYu6mCi14ew=; Received: (qmail 8520 invoked by alias); 6 May 2012 23:04:52 -0000 Received: (qmail 8510 invoked by uid 22791); 6 May 2012 23:04:51 -0000 X-SWARE-Spam-Status: No, hits=-4.8 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_LZ, TW_ZC, TW_ZJ X-Spam-Check-By: sourceware.org Received: from mail-yw0-f47.google.com (HELO mail-yw0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 06 May 2012 23:04:33 +0000 Received: by yhjj56 with SMTP id j56so4321933yhj.20 for ; Sun, 06 May 2012 16:04:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.182.73 with SMTP id n49mr17098579yhm.100.1336345473144; Sun, 06 May 2012 16:04:33 -0700 (PDT) Received: by 10.146.124.5 with HTTP; Sun, 6 May 2012 16:04:33 -0700 (PDT) In-Reply-To: References: <1335533422-11066-1-git-send-email-bonzini@gnu.org> Date: Mon, 7 May 2012 01:04:33 +0200 Message-ID: Subject: Re: [PATCH] x86: emit tzcnt unconditionally From: Uros Bizjak To: Paolo Bonzini Cc: 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, Apr 30, 2012 at 10:09 AM, Uros Bizjak wrote: > On Fri, Apr 27, 2012 at 3:30 PM, Paolo Bonzini wrote: >> tzcnt is encoded as "rep;bsf" and unlike lzcnt is a drop-in replacement >> if we don't care about the flags (it has the same semantics for non-zero >> values). >> >> Since bsf is usually slower, just emit tzcnt unconditionally.  However, >> write it as rep;bsf unless -mbmi is in use, to cater for old assemblers. > > Please emit "rep;bsf" when optimize_insn_for_speed_p () is true. > >> Bootstrapped on a non-BMI x86_64-linux host, regtest in progress. >> Ok for mainline? > > OK with the optimize_insn_for_speed_p conditional. I have committed similar patch, where we emit bsf when optimizing for size (saving a whopping one byte) and rep;bsf for !TARGET_BMI. The same functionality can be added to *ffs_1, since we don't care what ends in the register for input operand == 0 (this is the key difference between tzcnt and bsf). 2012-05-06 Uros Bizjak Paolo Bonzini * config/i386/i386.md (ctz2): Emit rep;bsf even for !TARGET_BMI and bsf when optimizing for size. (*ffs_1): Ditto. Tested on x86_64-pc-linux-gnu {,-m32}, committed to mainline SVN. Uros. 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}"; +} [(set_attr "type" "alu1") (set_attr "prefix_0f" "1") + (set (attr "prefix_rep") + (if_then_else + (match_test "optimize_function_for_size_p (cfun)") + (const_string "0") + (const_string "1"))) (set_attr "mode" "")]) (define_insn "ctz2" @@ -12123,14 +12136,21 @@ (clobber (reg:CC FLAGS_REG))] "" { - if (TARGET_BMI) + 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 - return "bsf{}\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}"; } [(set_attr "type" "alu1") (set_attr "prefix_0f" "1") - (set (attr "prefix_rep") (symbol_ref "TARGET_BMI")) + (set (attr "prefix_rep") + (if_then_else + (match_test "optimize_function_for_size_p (cfun)") + (const_string "0") + (const_string "1"))) (set_attr "mode" "")]) (define_expand "clz2"