From patchwork Thu May 9 18:45:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 242814 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id D00682C0117 for ; Fri, 10 May 2013 04:46:15 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=NxqT1WqcLZPGQuWi8hVB342c9ual+ zcC5KLNhC4Wi8AsqhBpCICTFDCUErfDgAfM5nx1VQnqM/cYudwv1dtrx7saUt47v E0G4aixTTH5prHkDcnazFYkU9UpPIyWHUt21YItSBdhgCjUmsOIisrcGnzdhLAw3 OaAshF1DOBWhFI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=MpvMaQmwMtWxTY7brXNGryXTGBk=; b=d/a rPMD/5M07jHj6MQAicCjtLvFJU/yju2a/zjRBtUQwntOTGvgOUqRsdRYNgTQUtqk l1N7OurhuBXM1kAbmITySSfu9Qnf2CgGAgXx7rZEUfvaxU+VmdzfaEPFd5EEWwZ2 t26iDOQ71r9/jfqDyLSkO0mXSytEahkBOvM2xAIo= Received: (qmail 6634 invoked by alias); 9 May 2013 18:46:09 -0000 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 Received: (qmail 6624 invoked by uid 89); 9 May 2013 18:46:09 -0000 X-Spam-SWARE-Status: No, score=-7.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 09 May 2013 18:46:08 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r49Ik6rt009281 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 9 May 2013 14:46:06 -0400 Received: from zalov.cz (vpn-60-192.rdu2.redhat.com [10.10.60.192]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r49Ik4qH008486 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 9 May 2013 14:46:05 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r49Ik3I8018042; Thu, 9 May 2013 20:46:03 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r49Ik2t6018041; Thu, 9 May 2013 20:46:02 +0200 Date: Thu, 9 May 2013 20:45:56 +0200 From: Jakub Jelinek To: Uros Bizjak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Improve rotation by mode bitsize - 1 Message-ID: <20130509184556.GI1377@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi! This is something I've noticed while working on the rotate recognizer patch I've just posted. We emit say roll %eax instead of roll $1, %eax because the former is shorter, but emit roll $31, %eax instead of the equivalent, but shorter rorl %eax The following patch let us optimize even those. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-05-09 Jakub Jelinek * config/i386/i386.md (rotateinv): New code attr. (*3_1, *si3_1_zext, *qi3_1_slp): Emit rorl %eax instead of roll $31, %eax, etc. Jakub --- gcc/config/i386/i386.md.jj 2013-05-07 10:26:46.000000000 +0200 +++ gcc/config/i386/i386.md 2013-05-09 10:18:36.603489156 +0200 @@ -761,6 +761,9 @@ (define_code_attr rotate_insn [(rotate " ;; Base name for insn mnemonic. (define_code_attr rotate [(rotate "rol") (rotatert "ror")]) +;; Base name for insn mnemonic of rotation in the other direction. +(define_code_attr rotateinv [(rotate "ror") (rotatert "rol")]) + ;; Mapping of abs neg operators (define_code_iterator absneg [abs neg]) @@ -9733,11 +9736,15 @@ (define_insn "*3_1" return "#"; default: - if (operands[2] == const1_rtx - && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))) - return "{}\t%0"; - else - return "{}\t{%2, %0|%0, %2}"; + if (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)) + { + if (operands[2] == const1_rtx) + return "{}\t%0"; + if (CONST_INT_P (operands[2]) + && INTVAL (operands[2]) == GET_MODE_BITSIZE (mode) - 1) + return "{}\t%0"; + } + return "{}\t{%2, %0|%0, %2}"; } } [(set_attr "isa" "*,bmi2") @@ -9799,11 +9806,14 @@ (define_insn "*si3_1_zext" return "#"; default: - if (operands[2] == const1_rtx - && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))) - return "{l}\t%k0"; - else - return "{l}\t{%2, %k0|%k0, %2}"; + if (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)) + { + if (operands[2] == const1_rtx) + return "{l}\t%k0"; + if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 31) + return "{l}\t%k0"; + } + return "{l}\t{%2, %k0|%k0, %2}"; } } [(set_attr "isa" "*,bmi2") @@ -9850,11 +9860,15 @@ (define_insn "*3_1" (clobber (reg:CC FLAGS_REG))] "ix86_binary_operator_ok (, mode, operands)" { - if (operands[2] == const1_rtx - && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))) - return "{}\t%0"; - else - return "{}\t{%2, %0|%0, %2}"; + if (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)) + { + if (operands[2] == const1_rtx) + return "{}\t%0"; + if (CONST_INT_P (operands[2]) + && INTVAL (operands[2]) == GET_MODE_BITSIZE (mode) - 1) + return "{}\t%0"; + } + return "{}\t{%2, %0|%0, %2}"; } [(set_attr "type" "rotate") (set (attr "length_immediate") @@ -9876,11 +9890,14 @@ (define_insn "*qi3_1_slp" || (operands[1] == const1_rtx && TARGET_SHIFT1))" { - if (operands[1] == const1_rtx - && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))) - return "{b}\t%0"; - else - return "{b}\t{%1, %0|%0, %1}"; + if (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)) + { + if (operands[2] == const1_rtx) + return "{b}\t%0"; + if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 7) + return "{b}\t%0"; + } + return "{b}\t{%1, %0|%0, %1}"; } [(set_attr "type" "rotate1") (set (attr "length_immediate")