From patchwork Fri Sep 5 04:04:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 36779 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 95E6420062 for ; Fri, 5 Sep 2014 04:05:07 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id w10sf66172233pde.3 for ; Thu, 04 Sep 2014 21:05:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to:cc :subject:x-original-sender:x-original-authentication-results :content-type; bh=tr22wd4FdvcGcMiOKrcWPsX+U7mcxw7+wtG3URfzCnU=; b=PPuBW3vQiSvscRwg0q88RAI4rPfq0v+p/3vVQXwE7meyvHTrucMko1LrI4BXKsoifa LtFtpAmK5pIMa9hyHs4XPGyWdHSkASOQrrVZr9YXuF18ZCI8/5swPuk5c/xQVELR0mJ4 MNI6yf0dlyJFMZ8FDzMQcV87JSDXR0XMkMJ5+KZ2TeKg7WfPopqmAV3DL28qwtko61Y3 iiw/4mh5wX5XRjVj44BNrcX6jzwLqDO69pgOqxXtcVY0P4MvQ/srEzvshyqbRWUXiPnH K4bywaqrO3SGUFcC/2vqv2YUzF/+X7hIpzDbF6ueyKiMeUgCghbUKr8DkJA+EmWWgOsz pshA== X-Gm-Message-State: ALoCoQlwNd5y5F4VPIQFCP+e12dx4tEnZI0Qb43GYZmcKiO5EMZoCtZe32a+IFhr0W2hOIL6np1t X-Received: by 10.66.118.136 with SMTP id km8mr5230265pab.45.1409889906554; Thu, 04 Sep 2014 21:05:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.113 with SMTP id e104ls590408qgd.33.gmail; Thu, 04 Sep 2014 21:05:06 -0700 (PDT) X-Received: by 10.52.255.232 with SMTP id at8mr6864169vdd.4.1409889906455; Thu, 04 Sep 2014 21:05:06 -0700 (PDT) Received: from mail-vc0-x22c.google.com (mail-vc0-x22c.google.com [2607:f8b0:400c:c03::22c]) by mx.google.com with ESMTPS id m9si2874vcl.104.2014.09.04.21.05.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 21:05:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22c as permitted sender) client-ip=2607:f8b0:400c:c03::22c; Received: by mail-vc0-f172.google.com with SMTP id le20so402490vcb.3 for ; Thu, 04 Sep 2014 21:05:06 -0700 (PDT) X-Received: by 10.52.156.100 with SMTP id wd4mr6850434vdb.39.1409889906333; Thu, 04 Sep 2014 21:05:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp23684vcb; Thu, 4 Sep 2014 21:05:05 -0700 (PDT) X-Received: by 10.66.122.99 with SMTP id lr3mr16608137pab.0.1409889905201; Thu, 04 Sep 2014 21:05:05 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ku8si1209587pbc.247.2014.09.04.21.05.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Sep 2014 21:05:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-376964-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 10711 invoked by alias); 5 Sep 2014 04:04:47 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 10698 invoked by uid 89); 5 Sep 2014 04:04:46 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f53.google.com Received: from mail-pa0-f53.google.com (HELO mail-pa0-f53.google.com) (209.85.220.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 05 Sep 2014 04:04:45 +0000 Received: by mail-pa0-f53.google.com with SMTP id fa1so21127269pad.26 for ; Thu, 04 Sep 2014 21:04:38 -0700 (PDT) X-Received: by 10.70.61.10 with SMTP id l10mr16485770pdr.154.1409889878305; Thu, 04 Sep 2014 21:04:38 -0700 (PDT) Received: from [10.1.1.2] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by mx.google.com with ESMTPSA id ou6sm530099pbb.88.2014.09.04.21.04.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Sep 2014 21:04:36 -0700 (PDT) Message-ID: <54093647.3000200@linaro.org> Date: Fri, 05 Sep 2014 14:04:23 +1000 From: Kugan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jakub Jelinek Subject: pr43550 - remove unnecessary uxts in bswap X-IsSubscribed: yes X-Original-Sender: kugan.vivekanandarajah@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22c as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Hi All, For the bswap built-in, there are unnecessary uxts generated as reported in pr43550. Can we rely on the argument being unsigned and set the SUBREG promoted accordingly. At least in ARM ABI, arguments are supposed to be properly zero/sign extended. Any thoughts? Bootstrapped and regression tested on x86_64 and arm. Thanks, Kugan gcc/testsuite 2014-09-05 Kugan Vivekanandarajah PR target/43550 * gcc.target/arm/pr43550.c: New test. gcc/ 2014-09-05 Kugan Vivekanandarajah PR target/43550 * builtins.c (expand_builtin_bswap): Generate promoted subreg. diff --git a/gcc/builtins.c b/gcc/builtins.c index e5a9b4d..a2f2358 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4517,6 +4517,12 @@ expand_builtin_bswap (enum machine_mode target_mode, tree exp, rtx target, if (!validate_arglist (exp, INTEGER_TYPE, VOID_TYPE)) return NULL_RTX; + if (!target + && (GET_MODE_PRECISION (word_mode) + > TYPE_PRECISION (TREE_TYPE (exp)))) + target = gen_lowpart_SUBREG (TYPE_MODE (TREE_TYPE (exp)), + gen_reg_rtx (word_mode)); + arg = CALL_EXPR_ARG (exp, 0); op0 = expand_expr (arg, subtarget && GET_MODE (subtarget) == target_mode @@ -4528,8 +4534,13 @@ expand_builtin_bswap (enum machine_mode target_mode, tree exp, rtx target, target = expand_unop (target_mode, bswap_optab, op0, target, 1); gcc_assert (target); - - return convert_to_mode (target_mode, target, 1); + target = convert_to_mode (target_mode, target, 1); + if (GET_CODE (target) == SUBREG) + { + SUBREG_PROMOTED_VAR_P (target) = 1; + SUBREG_PROMOTED_SET (target, SRP_UNSIGNED); + } + return target; } /* Expand a call to a unary builtin in EXP. diff --git a/gcc/testsuite/gcc.target/arm/pr43550.c b/gcc/testsuite/gcc.target/arm/pr43550.c index e69de29..7e4b2e0 100644 --- a/gcc/testsuite/gcc.target/arm/pr43550.c +++ b/gcc/testsuite/gcc.target/arm/pr43550.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "uxt" 0 } } */ + +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; + +uint16_t s16 (uint16_t v) +{ + return v >> 8 | v << 8; +} + +uint16_t _s16 (uint16_t v) +{ + return __builtin_bswap16 (v); +} + +uint32_t s32 (uint32_t v) +{ + return __builtin_bswap32 (v); +}