From patchwork Sun Jul 26 22:54:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Collison X-Patchwork-Id: 51475 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 7D55022DA5 for ; Sun, 26 Jul 2015 22:54:28 +0000 (UTC) Received: by lbcjf8 with SMTP id jf8sf21827261lbc.0 for ; Sun, 26 Jul 2015 15:54:27 -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:references:in-reply-to:content-type :content-transfer-encoding:x-original-sender :x-original-authentication-results; bh=FnEnrzUkf1Fjpyk6gWrZFIvw7ojTByeEU9xhdS4Szw4=; b=gozNPT9Kdy7sZ9pVoQhZVO6qneZgtCT/AKqWpN38JYf/FNFY/UBNYNqIv+L73kIQX5 DzADTJ7qq6JE0c2NTzGA+RZfM+UvFLJhT+DvcUjmerc62ZVLBnnWDehuFFWIVenMnf2C T7ba8nOK9/ICtq8hRjw6eufbJjeMMJ2106huWEh7oM7s93QmDp1NBCBfO+GwmqzRK13o x5OOZsCrg2wuAehh1cWSukCGJ0sSFCzHIV0pu2RlYKEsFPWGpk2QWZtNok3tRLVNDDwZ oASis2GrBYz4rFJ5BYwZ37gn1iYH8eAxn2f5rDya5+uUdXoULqRKeQFztT6w+OLJXS6u iPjg== X-Gm-Message-State: ALoCoQmFQIfRw4DB09v22Hffdu8009Yp/z6lo5TmYzhdmsCw5h57pBzLmFoB5WvkTaZSW0mGNqBK X-Received: by 10.180.96.137 with SMTP id ds9mr4104498wib.2.1437951267102; Sun, 26 Jul 2015 15:54:27 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.116 with SMTP id v20ls578122lal.22.gmail; Sun, 26 Jul 2015 15:54:26 -0700 (PDT) X-Received: by 10.152.180.134 with SMTP id do6mr23461580lac.95.1437951266872; Sun, 26 Jul 2015 15:54:26 -0700 (PDT) Received: from mail-la0-x236.google.com (mail-la0-x236.google.com. [2a00:1450:4010:c03::236]) by mx.google.com with ESMTPS id n15si13688993lbh.142.2015.07.26.15.54.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 15:54:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::236 as permitted sender) client-ip=2a00:1450:4010:c03::236; Received: by lahh5 with SMTP id h5so38968415lah.2 for ; Sun, 26 Jul 2015 15:54:26 -0700 (PDT) X-Received: by 10.112.120.134 with SMTP id lc6mr24196887lbb.86.1437951266466; Sun, 26 Jul 2015 15:54:26 -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.112.7.198 with SMTP id l6csp1205378lba; Sun, 26 Jul 2015 15:54:25 -0700 (PDT) X-Received: by 10.66.253.40 with SMTP id zx8mr60250770pac.56.1437951264333; Sun, 26 Jul 2015 15:54:24 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f4si39108927pas.118.2015.07.26.15.54.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 15:54:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-403935-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 24619 invoked by alias); 26 Jul 2015 22:54:12 -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 24599 invoked by uid 89); 26 Jul 2015 22:54:11 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f171.google.com Received: from mail-pd0-f171.google.com (HELO mail-pd0-f171.google.com) (209.85.192.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 26 Jul 2015 22:54:08 +0000 Received: by pdrg1 with SMTP id g1so40955651pdr.2 for ; Sun, 26 Jul 2015 15:54:06 -0700 (PDT) X-Received: by 10.70.109.162 with SMTP id ht2mr60218611pdb.101.1437951246784; Sun, 26 Jul 2015 15:54:06 -0700 (PDT) Received: from [192.168.1.14] (ip70-176-202-128.ph.ph.cox.net. [70.176.202.128]) by smtp.googlemail.com with ESMTPSA id c5sm25775294pds.87.2015.07.26.15.54.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 15:54:06 -0700 (PDT) Message-ID: <55B5650B.2060601@linaro.org> Date: Sun, 26 Jul 2015 15:54:03 -0700 From: Michael Collison User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: ramrad01@arm.com CC: gcc-patches Subject: Re: [ARM] Optimize compare against smin/umin References: <558C3576.3070108@linaro.org> In-Reply-To: X-Original-Sender: michael.collison@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::236 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 Here is an updated patch that addresses the issues you mentioned: 2015-07-24 Michael Collison * gcc/config/arm/arm.md (*arm_smin_cmp): New pattern. (*arm_umin_cmp): Likewise. * gcc.target/arm/mincmp.c: Test min compare idiom. diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index 0be70a8..361c292 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -3455,6 +3455,44 @@ (set_attr "type" "multiple,multiple")] ) +;; t = (s/u)min (x, y) +;; cc = cmp (t, z) +;; is the same as +;; cmp x, z +;; cmpge(u) y, z + +(define_insn_and_split "*arm_smin_cmp" + [(set (reg:CC CC_REGNUM) + (compare:CC + (smin:SI (match_operand:SI 0 "s_register_operand" "r") + (match_operand:SI 1 "s_register_operand" "r")) + (match_operand:SI 2 "s_register_operand" "r")))] + "TARGET_32BIT" + "#" + "&& reload_completed" + [(set (reg:CC CC_REGNUM) + (compare:CC (match_dup 0) (match_dup 2))) + (cond_exec (ge:CC (reg:CC CC_REGNUM) (const_int 0)) + (set (reg:CC CC_REGNUM) + (compare:CC (match_dup 1) (match_dup 2))))] +) + +(define_insn_and_split "*arm_umin_cmp" + [(set (reg:CC CC_REGNUM) + (compare:CC + (umin:SI (match_operand:SI 0 "s_register_operand" "r") + (match_operand:SI 1 "s_register_operand" "r")) + (match_operand:SI 2 "s_register_operand" "r")))] + "TARGET_32BIT" + "#" + "&& reload_completed" + [(set (reg:CC CC_REGNUM) + (compare:CC (match_dup 0) (match_dup 2))) + (cond_exec (geu:CC (reg:CC CC_REGNUM) (const_int 0)) + (set (reg:CC CC_REGNUM) + (compare:CC (match_dup 1) (match_dup 2))))] +) + (define_expand "umaxsi3" [(parallel [ (set (match_operand:SI 0 "s_register_operand" "") diff --git a/gcc/testsuite/gcc.target/arm/mincmp.c b/gcc/testsuite/gcc.target/arm/mincmp.c new file mode 100644 index 0000000..2a55c6d --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/mincmp.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-require-effective-target arm32 } */ + +#define min(x, y) ((x) <= (y)) ? (x) : (y) + +unsigned int foo (unsigned int i, unsigned int x ,unsigned int y) +{ + return i < (min (x, y)); +} + +int bar (int i, int x, int y) +{ + return i < (min (x, y)); +} + +/* { dg-final { scan-assembler "cmpcs" } } */ +/* { dg-final { scan-assembler "cmpge" } } */