From patchwork Mon Jul 25 00:44:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 72682 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp888586qga; Sun, 24 Jul 2016 17:44:40 -0700 (PDT) X-Received: by 10.66.220.73 with SMTP id pu9mr24750891pac.77.1469407479980; Sun, 24 Jul 2016 17:44:39 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 84si30387962pfa.66.2016.07.24.17.44.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Jul 2016 17:44:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-432392-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; spf=pass (google.com: domain of gcc-patches-return-432392-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-432392-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=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=Dq1VHJnGbYpHdBarM+9q6Fqu6JdJU+xn7z5O1XG/rHrP+/ 5iN8A0O+G0x83nKcmnlSOXCrdvF6g2T4ufM9X8o6IZTuyHIPvMBGkuK8hGKfMkrG twPr6yrxIClDlvDAcKzKzB7f8EzUhrd33eyJPsVDd85kKHmVFFpqVxoYUfzQs= 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=5m3mFiHXkr7okGjnDenVzEXqMZY=; b=JbFcnO3bmVtdqPEQ+Jqw zMI4ft4PxEdMfrdwXmt/8luEAnz/u9HWwTMBJ2Wv9G6D88eqwTshcEefuroy7SiZ U60CaMqhKrMu01sIemoKqY0QES1Y895gmiRwwfFSL+zOEovmVb3glkbOeE5d8uYs RvFU7oVqY8exEZOMRXIl9hk= Received: (qmail 31939 invoked by alias); 25 Jul 2016 00:44:28 -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 31923 invoked by uid 89); 25 Jul 2016 00:44:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=UD:pd, matchpd, match.pd, UD:match.pd X-HELO: mail-it0-f44.google.com Received: from mail-it0-f44.google.com (HELO mail-it0-f44.google.com) (209.85.214.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 25 Jul 2016 00:44:17 +0000 Received: by mail-it0-f44.google.com with SMTP id f6so73875940ith.1 for ; Sun, 24 Jul 2016 17:44:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=9O3/j5f5XIoc2ObI4EtZax/krS9BLtidVwHm9LF1M2s=; b=TAe/hKVhQDOv8lcAecJSZIyLwpWFFxqecg0MVsd6Q0PxXAdMyfSln2yjBMQPcXm7Kr vo+821w7VyR+x8lB/jDidodJ8/guqPdciCZ1ZrONK7RW3/58N2gMJstn35QBfKwOVwbX /zjLXqaoUJLAPsOLzOxW+BhTvIc3J74b2PwBDj1OB0mSvKG/xh0l6tqwMYxKasIJkFTH p0eOoYlcrvkCwjMltfJfug1474+POt9sSU+gUjl36qif7c01oo3ISl2QpphaXG1ilcfJ NC/GkRskofCBPXVa53cOXTse8tFjZ2+8UeQbsTzwa4jHvMRRYousB73g4cMVatD1aiak ROCg== X-Gm-Message-State: AEkoouuL6SthxgV4vIL1lucHj+UnRgS27M6nUGqxDFn6swl3mAVg1iQmLqEjDAcaBIQx1jhE4k6rfxPcyLuD0uth X-Received: by 10.36.219.65 with SMTP id c62mr6472678itg.44.1469407454947; Sun, 24 Jul 2016 17:44:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.48.197 with HTTP; Sun, 24 Jul 2016 17:44:14 -0700 (PDT) From: Prathamesh Kulkarni Date: Mon, 25 Jul 2016 06:14:14 +0530 Message-ID: Subject: [PR70920] transform (intptr_t) x eq/ne CST to x eq/ne (typeof x) cst To: Richard Biener , gcc Patches X-IsSubscribed: yes Hi Richard, The attached patch tries to fix PR70920. It adds your pattern from comment 1 in the PR (with additional gating on INTEGRAL_TYPE_P to avoid regressing finalize_18.f90) and second pattern, which is reverse of the first transform. I needed to update ssa-dom-branch-1.c because with patch applied, jump threading removed the second if (i != 0B) block. The dumps with and without patch for ssa-dom-branch-1.c start to differ with forwprop1: before: : _1 = temp_16(D)->code; _2 = _1 == 42; _3 = (int) _2; _4 = (long int) _3; temp_17 = (struct rtx_def *) _4; if (temp_17 != 0B) goto ; else goto ; after: : _1 = temp_16(D)->code; _2 = _1 == 42; _3 = (int) _2; _4 = (long int) _2; temp_17 = (struct rtx_def *) _4; if (_1 == 42) goto ; else goto ; I suppose the transform is correct for above test-case ? Then vrp dump shows: Threaded jump 5 --> 9 to 13 Threaded jump 8 --> 9 to 13 Threaded jump 3 --> 9 to 13 Threaded jump 12 --> 9 to 14 Removing basic block 9 basic block 9, loop depth 0 pred: if (i1_10(D) != 0B) goto ; else goto ; succ: 10 11 So there remained two instances of if (i1_10 (D) != 0B) in dom2 dump file, and hence needed to update the test-case. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK to commit ? PS: Writing changelog entries for match.pd is a bit tedious. Should we add optional names for pattern so we can refer to them by names in the ChangeLog for the more complicated ones ? Or maybe just use comments: (simplify /* name */ ... ) -;) Thanks, Prathamesh diff --git a/gcc/match.pd b/gcc/match.pd index 21bf617..7c736be 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3408,3 +3408,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) { CONSTRUCTOR_ELT (ctor, idx / k)->value; }) (BIT_FIELD_REF { CONSTRUCTOR_ELT (ctor, idx / k)->value; } @1 { bitsize_int ((idx % k) * width); }))))))))) + +/* PR70920: Transform (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST. */ + +(for cmp (ne eq) + (simplify + (cmp (convert@2 @0) INTEGER_CST@1) + (if (POINTER_TYPE_P (TREE_TYPE (@0)) + && INTEGRAL_TYPE_P (TREE_TYPE (@2))) + (cmp @0 (convert @1))))) + +/* Reverse of the above case: + x has integral_type, CST is a pointer constant. + Transform (typeof CST)x eq/ne CST to x eq/ne (typeof x) CST. */ + +(for cmp (ne eq) + (simplify + (cmp (convert @0) @1) + (if (POINTER_TYPE_P (TREE_TYPE (@1)) + && INTEGRAL_TYPE_P (TREE_TYPE (@0))) + (cmp @0 (convert @1))))) diff --git a/gcc/testsuite/gcc.dg/pr70920-1.c b/gcc/testsuite/gcc.dg/pr70920-1.c new file mode 100644 index 0000000..9b7e2d0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70920-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-gimple" } */ + +#include + +void f1(); +void f2(); + +void +foo (int *a) +{ + if ((intptr_t) a == 0) + { + f1 (); + if (a) + f2 (); + } +} + +/* { dg-final { scan-tree-dump "if \\(a == 0B\\)" "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/pr70920-2.c b/gcc/testsuite/gcc.dg/pr70920-2.c new file mode 100644 index 0000000..2db9897 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70920-2.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop-details" } */ + +#include + +void f1(); +void f2(); + +void +foo (int *a) +{ + int cst = 0; + if ((intptr_t) a == cst) + { + f1 (); + if (a) + f2 (); + } +} + +/* { dg-final { scan-tree-dump "gimple_simplified to if \\(a_\[0-9\]*\\(D\\) == 0B\\)" "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.dg/pr70920-3.c b/gcc/testsuite/gcc.dg/pr70920-3.c new file mode 100644 index 0000000..71e0d8d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70920-3.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-Wno-int-to-pointer-cast -fdump-tree-gimple" } */ + +#include + +void f1(); +void f2(); + +void +foo (int a) +{ + if ((int *) a == 0) + { + f1 (); + if (a) + f2 (); + } +} + +/* { dg-final { scan-tree-dump "if \\(a == 0\\)" "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/pr70920-4.c b/gcc/testsuite/gcc.dg/pr70920-4.c new file mode 100644 index 0000000..f92c5a6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70920-4.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop-details -Wno-int-to-pointer-cast" } */ + +#include + +void f1(); +void f2(); + +void +foo (int a) +{ + void *cst = 0; + if ((int *) a == cst) + { + f1 (); + if (a) + f2 (); + } +} + +/* { dg-final { scan-tree-dump "gimple_simplified to if \\(a_\[0-9\]*\\(D\\) == 0\\)" "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-branch-1.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-branch-1.c index 18f9041..d38e3a8 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-branch-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-branch-1.c @@ -21,7 +21,7 @@ try_combine (rtx i1, rtx newpat) /* There should be three tests against i1. Two from the hash table dumps, one in the code itself. */ -/* { dg-final { scan-tree-dump-times "if .i1_" 3 "dom2"} } */ +/* { dg-final { scan-tree-dump-times "if .i1_" 2 "dom2"} } */ /* There should be no actual jump threads realized by DOM. The legitimize jump threads are handled in VRP and those discovered