From patchwork Tue Oct 3 19:54:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 114717 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2266299qgn; Tue, 3 Oct 2017 12:54:59 -0700 (PDT) X-Received: by 10.84.131.105 with SMTP id 96mr18306315pld.229.1507060499167; Tue, 03 Oct 2017 12:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507060499; cv=none; d=google.com; s=arc-20160816; b=Nqhy0RhWo2tDDFYi3d3vW8Y1JgIDfRo8CJm8J8sYH8mfkNvqFyxtac4WaxhRl7A8mk EhpxR91/xCIxXA/l6dezTLluscsZ/2OhC/0sz+uHKkCOisZmj0j647AHg7TYiBynDdnN /saFC8bLuf6KnCJKSCg7TMlP4gYzYxm4M2fCory/Ln8pzKyA127Z5O7TwOxHNMgQZKD+ h5u3iiOWY3ca3LBpgoIot7FnRj20Th6zOD5Hwe7KXHmEa1REg7LGBHCCJR9I0QfNgCwy 9edBPCERz6jFf2z06Pf3aFSZby8J4ALMuDd84FNEQdbx0613sHmlEdPkl/Jd7gsXEKkC nEnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=WFwgJ8Kok5SXcSRCkFM3l8Rawz5sR34bn5CQrCkGumo=; b=uYTvZmmWS+zZ9CO/qF83xZFiaQojO3OcsNEgHxoubP4MRgP3ibqX9A3IxZ2fxy+scp i9AB0pdjiRlAU/3kL69jhcAnxbNYWImc5RJPhaeTPrD2axAserAOCFydDr2Eg6YvGTmB LD6Mu/bf2EbdxbDgRGrR1BU88EqYZoim/Ujr7rwGm4HoCzOVOiY+jsVcfPnq+M/n9jqz 04Smt3SICoZvp2cvybgQYzoiDWTvwK72mlPapwSpdQqLQ+jmsUVXF04sOqHoAxkCuBiq NF9oPI7JYRg/d/0XYxWoWk0K81JoLYSzuOFVWGiCe3FeY3RUGRNw1tUrhiCkKBQ08LTW Ss1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bspEB3qE; spf=pass (google.com: domain of gcc-patches-return-463409-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-463409-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id o6si10408068plk.45.2017.10.03.12.54.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Oct 2017 12:54:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-463409-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bspEB3qE; spf=pass (google.com: domain of gcc-patches-return-463409-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-463409-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=OODUMPtFV+9QnZyE/VPaHFv6A+H5XBn6fWWPxzHAMLoyi6 qIKGALC/yKnSu8Cma8Q2R9lKOWg7+Af6X9dS4Efvds8eN26ue+A9ecskdPdQ1clk YuWg9JlCxBgcNtWbMeYGPMDQ5+Ac/dnEWz6fSCRb7GQBYnJ2ikxw0F4YODdNc= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=kgm2t/pSge0VH+HovUYWm7I5CwE=; b=bspEB3qELOxnqEacexuU sgr5Nfwi14fOvSG2eSJ5dfg2y+/F15ipxaau0PFMzJ1Ju0yl9xmWAdTtKoKQx1r9 xLU6g3BuihFN782stWtb9pvc9u3rnG6pt+xj4MCa1Ar1fjSCdIUd5WTnYVVNmlAE hKdZNUnfFYbu18TFL1MDCrs= Received: (qmail 49762 invoked by alias); 3 Oct 2017 19:54:45 -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 49747 invoked by uid 89); 3 Oct 2017 19:54:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=D*1, Hx-languages-length:1842 X-HELO: mail-wr0-f181.google.com Received: from mail-wr0-f181.google.com (HELO mail-wr0-f181.google.com) (209.85.128.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Oct 2017 19:54:43 +0000 Received: by mail-wr0-f181.google.com with SMTP id l24so4278556wre.1 for ; Tue, 03 Oct 2017 12:54:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=xVci0Hm/wrR0acNxCn1MFigOyPBE9DFabOuM3iZBapU=; b=Ebawh7ePBPFtdX0Obf4d04MqPCLnug/PEiROqn5co2gwHPR4a7ZYzv030k6zzHaIit /ZdZkD6z0pE+0wsK7+g3g1e7ysI2h+REQxFrW8GKSSBzvLqCzcmRi9AnAFruzDj0HbkR Ro8UHZupM6Q1VAWbWU1qubwRVyKMx936wLuovBLW9KfDFH7N7cebITm5LUmdd38GOZtd 4QiOErq0AuNbRKhNkUwV/b0d27bDVQ0EQF+VGzPsi8UZlLz1MSNkLqfWBLHSR8lx5qQ2 YO+x+pz38oUoa55DAy/uYDxuWZi8alI0IqW/pjq4iwYnDqcg2u5wIt/tBtRJojV9ibsD KnFA== X-Gm-Message-State: AHPjjUjPEiEoiQFmJCu2af4OuS0D6Qft//jSSfvfaDANvlME82FlHTrc BUcKhDP+pEj8Tpp0GwPDWQNzn38yjxHEVjb96qL+79s8 X-Google-Smtp-Source: AOwi7QAwW1Z+aYhgFA+dxXeBbpBDyOY+KGWhE+WrQnQ/GCnBJSN77ZVTsBbBJ+lQaGphAWwA7aA4vi7NwgCqoJVuhOw= X-Received: by 10.223.157.203 with SMTP id q11mr17589863wre.96.1507060480527; Tue, 03 Oct 2017 12:54:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.128.207 with HTTP; Tue, 3 Oct 2017 12:54:39 -0700 (PDT) From: Prathamesh Kulkarni Date: Tue, 3 Oct 2017 12:54:39 -0700 Message-ID: Subject: Transform (x >> cst) != 0 to x >= (1 << cst) and (x >> cst) == 0 to x < (1 << cst) To: gcc Patches , Richard Biener , marc.glisse@inria.fr X-IsSubscribed: yes Hi, This follow-up patch implements the patterns mentioned in $subject. Bootstrap+test in progress on x86_64-unknown-linux-gnu and aarch64-linux-gnu. OK to commit if passes ? Thanks, Prathamesh 2017-10-03 Prathamesh Kulkarni * match.pd ((X >> CST) == 0 -> X < (1 << CST)): New pattern. ((X >> CST) != 0 -> X >= (1 << CST)): Likewise. testsuite/ * gcc.dg/tree-ssa/cmpdiv.c: Add test-cases f3 and f4. diff --git a/gcc/match.pd b/gcc/match.pd index 43ab226a705..883ad5ba53c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1287,6 +1287,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (VECTOR_TYPE_P (type) || !VECTOR_TYPE_P (TREE_TYPE (@0)))) (ocmp @0 @1)))) +/* Transform + (x >> cst) != 0 -> x >= (1 << cst) + (x >> cst) == 0 -> x < (1 << cst) + if x, cst are unsigned. */ +(for cmp (eq ne) + ocmp (lt ge) + (simplify + (cmp (rshift @0 INTEGER_CST@1) integer_zerop) + (if (TYPE_UNSIGNED (TREE_TYPE (@0)) + && (VECTOR_TYPE_P (type) || !VECTOR_TYPE_P (TREE_TYPE (@0)))) + (ocmp @0 (lshift { build_int_cstu (TREE_TYPE (@0), 1); } @1))))) + /* X == C - X can never be true if C is odd. */ (for cmp (eq ne) (simplify diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c index 14161f5ea6f..fc5bc8c3674 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c @@ -15,4 +15,19 @@ _Bool f2(unsigned x, unsigned y) return t2; } +_Bool f3(unsigned x) +{ + unsigned t1 = x >> 4; + _Bool t2 = (t1 != 0); + return t2; +} + +_Bool f4(unsigned x) +{ + unsigned t1 = x >> 4; + _Bool t2 = (t1 == 0); + return t2; +} + /* { dg-final { scan-tree-dump-not "trunc_div_expr" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "rshift_expr" "optimized" } } */