From patchwork Thu Jun 25 17:08:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Collison X-Patchwork-Id: 488496 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2BE4014012C for ; Fri, 26 Jun 2015 03:08:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=xgRGez6U; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type :content-transfer-encoding; q=dns; s=default; b=o4U04AH25s7c4V2J 5jWLk+cBO+ntVIZgd1/uEz8j1PBhhPqw2JKsbB7/7QJ3NV0iO8GfxSBmP32r1fz9 iJqUVh5enDYugld35HREHWNX5DnD5F03Wp+3SPwJLIVr1hblXG3bUiNLePGBU+Bm XrrXfl9pyQ/KLp5zt7mkpQvGb3M= 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 :message-id:date:from:mime-version:to:subject:content-type :content-transfer-encoding; s=default; bh=QJMRQBAjA6mAIpQ+KAk4hr 8zbKc=; b=xgRGez6UVGQtHs+Psoj4Ve7Rg8yN2fbuiMAd1d1HN8dy4wDATdwtpf 7YFF55JfCO8oy/SY0z+eGz8xY3fWlaggmt8sN7YNUcVJSb/3aruLkh34DK/S8JFY feJMPUtPMwlKG9vfgqdbxwTy/1AzhP/z5jbTCY2fUkFVcbAbj7mRY= Received: (qmail 6363 invoked by alias); 25 Jun 2015 17:08:21 -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 6298 invoked by uid 89); 25 Jun 2015 17:08:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 X-HELO: mail-pa0-f46.google.com Received: from mail-pa0-f46.google.com (HELO mail-pa0-f46.google.com) (209.85.220.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 25 Jun 2015 17:08:14 +0000 Received: by paceq1 with SMTP id eq1so53015860pac.3 for ; Thu, 25 Jun 2015 10:08:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:organization:user-agent :mime-version:to:subject:content-type:content-transfer-encoding; bh=efOQazzXPHtWSKn0yp9xe1qFyPgZfiWtodKkWdlxEiw=; b=T7C/ULDkt+c8lqYTTxMaLJbI4APntuzACzT4cuIUTag+5TmGn9cDBxv1B8gUHbtAse R9VGSjT8qD0Bdn+hAoYNSPioZNgU+lwvSuvijGw/MbV/btnjY2g3sRFhJrqc2U0DrtQw LwSBYP8O+b56p47KA44TgJOoY3xPxPt7SF+AC3FpHV80UCgZo/k3/ssRv9pw196F++l9 /2HSRt44rOrr2BlNA2KB7Xz0YCZpHCkB2+xyx6ToYefm4hX4IlCfjD28BtM29/QTm/ht KzNor2VGu0lUnJus/56w+AAuonVlBy2v6BqK2xCBlL+SpQklsNlmWBf3acOvXVCrZpRH Jhpw== X-Gm-Message-State: ALoCoQnNVd3WsMxDEQhhzPuQWBnQBoiQEQR0pgiJQo6MDJbdqc7vlYv+SrFNFpyCLTy8x/Z2u0Zi X-Received: by 10.70.47.9 with SMTP id z9mr93839300pdm.69.1435252091715; Thu, 25 Jun 2015 10:08:11 -0700 (PDT) Received: from [192.168.1.15] (ip70-162-241-179.ph.ph.cox.net. [70.162.241.179]) by mx.google.com with ESMTPSA id u8sm30685576pdj.46.2015.06.25.10.08.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2015 10:08:11 -0700 (PDT) Message-ID: <558C3576.3070108@linaro.org> Date: Thu, 25 Jun 2015 10:08:06 -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: gcc-patches@gcc.gnu.org Subject: [ARM] Optimize compare against smin/umin This patch is designed to optimize constructs such as: #define min(x, y) ((x) <= (y)) ? (x) : (y) unsignedint foo (unsignedint i, unsignedint x ,unsignedint y) { return i < (min (x, y)); } int bar (int i,int x,int y) { return i < (min (x, y)); } Patch was tested on arm-linux-gnueabi, arm-linux-gnueabihf, armeb-linux-gnueabihf. Okay for trunk? 2015-06-24 Michael Collison * gcc/config/arm/arm.md (*arm_smin_cmp): New pattern. (*arm_umin_cmp): Likewise. diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index 1ac8af0..994c95f 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -3455,6 +3455,28 @@ (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" + "#" + "" + [(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_expand "umaxsi3" [(parallel [ (set (match_operand:SI 0 "s_register_operand" "") @@ -3521,6 +3543,22 @@ (set_attr "type" "store1")] ) +(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" + "#" + "" + [(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_insn "*store_minmaxsi" [(set (match_operand:SI 0 "memory_operand" "=m") (match_operator:SI 3 "minmax_operator"