From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86232 invoked by alias); 1 Jun 2019 16:16:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 86218 invoked by uid 89); 1 Jun 2019 16:16:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*M:1c8b X-HELO: mail-ot1-f68.google.com Received: from mail-ot1-f68.google.com (HELO mail-ot1-f68.google.com) (209.85.210.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 01 Jun 2019 16:16:26 +0000 Received: by mail-ot1-f68.google.com with SMTP id l17so12289214otq.1 for ; Sat, 01 Jun 2019 09:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=jTE7BaNeQgVymtA5+gdGMWIeZLUfA7l1s403mOO9MU8=; b=Qyb31QTh9tYK2ZFNoznLu5fBt/HW6ZpoMwEx6SLjyFJOBf+W51hR8HJNtnYgaVv7t4 TEBlNji3vintIOMr1I3c63o1s+6jgbxJJr7j1nq0O8+jncG3JRMN1etiZZg5+sqa+W1S zu3PiHWsbkJLG5MfQaa1dkSHRqKrYCKcibgaN2kETPczatPGXBhMiv01yXIhXYHylTqc jKM9M8ntQQA7RGeaNHV7lCcbzbVZ0LdZKVAEw96cmf0IR+MRAC1xUQhHsoLCsvfpO8mB 6xVKVGio2/Gkvasg3f4vFB3mIA2KxLbM2cDh96/UTOcmUjjRmnHEhsSe8qR8O/sZgqee S31g== Return-Path: Received: from [192.168.0.41] (97-118-125-210.hlrn.qwest.net. [97.118.125.210]) by smtp.gmail.com with ESMTPSA id q125sm1424049oih.33.2019.06.01.09.16.23 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2019 09:16:23 -0700 (PDT) Subject: Re: [PATCH] include MEM_REF type in tree dumps (PR 90676) From: Martin Sebor To: gcc-patches References: Message-ID: <6f658a37-2b2f-1c8b-9a46-c7064530d29e@gmail.com> Date: Sat, 01 Jun 2019 16:16:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------DD37F717A0AD92AD130A590F" X-IsSubscribed: yes X-SW-Source: 2019-06/txt/msg00013.txt.bz2 This is a multi-part message in MIME format. --------------DD37F717A0AD92AD130A590F Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-length: 1523 A patch with a ChangeLog this time is attached. On 6/1/19 9:53 AM, Martin Sebor wrote: > I spent a bunch of time the other day trying to understand why > the second of the two assignments below to a char array was > apparently not being done by trunk > >   a[0] = 1; >   a[1] = 0; > > The optimized GIMPLE dump simply shows: > >   MEM[(char *)&a] = 1; > > when in the past it showed: > >   MEM[(char[2] *)&a2] = 1; > > After some debugging I figured out that this is the result of > the store merging pass transforming the two assignments into > one: > >   *(short int *)a = 1; > > and the MEM_REF dump mentioning only the type of the second > operand and not the type of the access. > > To avoid this confusion the attached patch adds to the dump > a cast to the MEM_REF type for accesses whose size is not equal > to the size of the operand (when the sizes are the same no new > cast is prepended).  The effect is that with store merging in > effect, the dump for the above becomes > >   MEM[(short int *)(char *)&a] = 1; > > This should make both the size and the type of the access clear > and help avoid the confusion.  The output isn't the same as in > earlier releases because because the access really is done via > a short pointer and not as an array of char. > > There is more detail in MEM_REF that could be included here but > it seems that the size of the access is essential to interpreting > the dumps. > > Tested on x86_64-linux with only minimal testsuite fallout. > > Martin --------------DD37F717A0AD92AD130A590F Content-Type: text/x-patch; name="gcc-90676.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-90676.diff" Content-length: 8876 PR middle-end/90676 - default GIMPLE dumps lack information gcc/ChangeLog: PR middle-end/90676 * tree-pretty-print.c (dump_generic_node): Include MEM_REF type in output when different size than operand. gcc/testsuite/ChangeLog: PR middle-end/90676 * gcc.dg/tree-ssa/dump-6.c: New test. * g++.dg/tree-ssa/pr19807.C: Adjust expected output. * g++.dg/tree-ssa/ssa-dse-1.C: Same. * gcc.dg/tree-ssa/pr30375.c: Same. * gcc.dg/tree-ssa/slsr-27.c (f): Same. * gcc.dg/tree-ssa/slsr-28.c (f): Same. * gcc.dg/tree-ssa/slsr-29.c (f): Same. * gcc.dg/tree-ssa/ssa-dse-24.c: Same. diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr19807.C b/gcc/testsuite/g++.dg/tree-ssa/pr19807.C index cbe06b4ce62..08e0dd13115 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr19807.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr19807.C @@ -11,7 +11,8 @@ void foo(void) z = 1 + &a[1]; } -/* { dg-final { scan-tree-dump-times "&MEM\\\[\\\(void .\\\)&a \\\+ 8B\\\]" 3 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "&MEM\\\[\\\(void .\\\)&a \\\+ 8B\\\]" 3 "optimized" { target { ! store_merge } } } } + { dg-final { scan-tree-dump-times "&MEM\\\[\\(int \\*\\)\\\(void .\\\)&a \\\+ 8B\\\]" 3 "optimized" { target { store_merge } } } } */ void bar(int i) diff --git a/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-1.C b/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-1.C index 1fd8dec99e9..da9fc3b9c6a 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-1.C +++ b/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-1.C @@ -97,5 +97,5 @@ int main() } -/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct FixBuf \\*\\)& \\+ \[0-9\]+B\\\] = {}" 1 "dse1" } } */ - +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct FixBuf \\*\\)& \\+ \[0-9\]+B\\\] = {}" 1 "dse1" { target { ! store_merge } } } } + { dg-final { scan-tree-dump-times "MEM\\\[\\(char\\\[176] \\*\\)\\(struct FixBuf \\*\\)& \\+ \[0-9\]+B\\\] = {}" 1 "dse1" { target { store_merge } } } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dump-6.c b/gcc/testsuite/gcc.dg/tree-ssa/dump-6.c new file mode 100644 index 00000000000..8b4a51c6cbf --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/dump-6.c @@ -0,0 +1,37 @@ +/* PR middle-end/90676 - default GIMPLE dumps lack information + { dg-do compile } + { dg-options "-O2 -fdump-tree-store-merging" } + { dg-require-effective-target int32plus } + { dg-require-effective-target store_merge } */ + + +extern char a2[2]; + +void f2 (void) +{ + a2[0] = 1; + a2[1] = 0; +} + +extern char a4[4]; + +void f4 (void) +{ + a4[0] = 1; + a4[1] = 0; + a4[2] = 0; + a4[3] = 0; +} + +extern char a8[8]; + +void f8 (void) +{ + a8[0] = 1; + for (int i = 1; i != 8; ++i) + a8[i] = 0; +} + +/* { dg-final { scan-tree-dump "MEM\\\[\\(unsigned short \\*\\)\\(char \\*\\)\\&a2] = " "store-merging"} } + { dg-final { scan-tree-dump "MEM\\\[\\(unsigned int \\*\\)\\(char \\*\\)\\&a4] = " "store-merging"} } + { dg-final { scan-tree-dump "MEM\\\[\\(unsigned long \\*\\)\\(char \\*\\)\\&a8] = " "store-merging"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr30375.c b/gcc/testsuite/gcc.dg/tree-ssa/pr30375.c index 4494a2b0bd6..1d47e4c39eb 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr30375.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr30375.c @@ -22,5 +22,6 @@ void test_signed_msg_encoding(void) f(); } -/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct _s \\*\\)&signInfo \\+ \[0-9\]+B\\\] = {}" 1 "dse1" } } */ +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct _s \\*\\)&signInfo \\+ \[0-9\]+B\\\] = {}" 1 "dse1" { target { ! store_merge } } } } + { dg-final { scan-tree-dump-times "MEM\\\[\\(char\\\[8] \\*\\)\\(struct _s \\*\\)&signInfo \\+ \[0-9\]+B\\\] = {}" 1 "dse1" { target { store_merge } } } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/slsr-27.c b/gcc/testsuite/gcc.dg/tree-ssa/slsr-27.c index 35b3d00ee44..ea9aad9c4cc 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/slsr-27.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/slsr-27.c @@ -19,4 +19,5 @@ f (struct x *p, unsigned int n) /* { dg-final { scan-tree-dump-times "\\* 4;" 1 "dom3" { target { int32 } } } } */ /* { dg-final { scan-tree-dump-times "\\* 2;" 1 "dom3" { target { int16 } } } } */ /* { dg-final { scan-tree-dump-times "p_\\d\+\\(D\\) \\+ \[^\r\n\]*_\\d\+;" 1 "dom3" } } */ -/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 3 "dom3" } } */ +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 3 "dom3" { target { ! store_merge } } } } */ +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(int \\*\\)\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 3 "dom3" { target { store_merge } } } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/slsr-28.c b/gcc/testsuite/gcc.dg/tree-ssa/slsr-28.c index 732d2324db5..37526a3d9fb 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/slsr-28.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/slsr-28.c @@ -23,4 +23,5 @@ f (struct x *p, unsigned int n) /* { dg-final { scan-tree-dump-times "\\* 4;" 1 "dom3" { target { int32 } } } } */ /* { dg-final { scan-tree-dump-times "\\* 2;" 1 "dom3" { target { int16 } } } } */ /* { dg-final { scan-tree-dump-times "p_\\d\+\\(D\\) \\+ \[^\r\n\]*_\\d\+" 1 "dom3" } } */ -/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 9 "dom3" } } */ +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 9 "dom3" { target { ! store_merge } } } } */ +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(int \\*\\)\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 9 "dom3" { target { store_merge } } } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/slsr-29.c b/gcc/testsuite/gcc.dg/tree-ssa/slsr-29.c index a22cc7906da..8499f2bd28c 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/slsr-29.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/slsr-29.c @@ -25,4 +25,5 @@ f (struct x *p, unsigned int n) /* { dg-final { scan-tree-dump-times "\\* 4;" 1 "dom3" { target { int32 } } } } */ /* { dg-final { scan-tree-dump-times "\\* 2;" 1 "dom3" { target { int16 } } } } */ /* { dg-final { scan-tree-dump-times "p_\\d\+\\(D\\) \\+ \[^\r\n\]*_\\d\+" 1 "dom3" } } */ -/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 9 "dom3" } } */ +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 9 "dom3" { target { ! store_merge } } } } */ +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(int \\*\\)\\(struct x \\*\\)\[^\r\n\]*_\\d\+" 9 "dom3" { target { store_merge } } } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-24.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-24.c index 282194c1e32..709adce32bf 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-24.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-24.c @@ -59,4 +59,5 @@ void foo(int prec, bar (&info); } -/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct printf_info \\*\\)&info \\+ \[0-9\]+B\\\] = {}" 1 "dse1" } } */ +/* { dg-final { scan-tree-dump-times "MEM\\\[\\(struct printf_info \\*\\)&info \\+ \[0-9\]+B\\\] = {}" 1 "dse1" { target { ! store_merge } } } } + { dg-final { scan-tree-dump-times "MEM\\\[\\(char\\\[4] \\*\\)\\(struct printf_info \\*\\)&info \\+ \[0-9\]+B\\\] = {}" 1 "dse1" { target { store_merge } } } } */ diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 4ba9170ddd3..649c81e06cd 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -1690,21 +1690,32 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, } else { - tree ptype; - pp_string (pp, "MEM["); + tree nodetype = TREE_TYPE (node); + tree op0 = TREE_OPERAND (node, 0); + tree op1 = TREE_OPERAND (node, 1); + tree op1type = TYPE_MAIN_VARIANT (TREE_TYPE (op1)); + + if (!tree_int_cst_equal (TYPE_SIZE (nodetype), + TYPE_SIZE (TREE_TYPE (op1type)))) + { + /* If the size of the type of the operand is not the same + as the size of the MEM_REF expression include a cast + to a pointer to the type of the latter to make it clear + how many bytes of memory are being accessed. */ + pp_left_paren (pp); + dump_generic_node (pp, nodetype, spc, flags | TDF_SLIM, false); + pp_string (pp, " *)"); + } + pp_left_paren (pp); - ptype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1))); - dump_generic_node (pp, ptype, - spc, flags | TDF_SLIM, false); + dump_generic_node (pp, op1type, spc, flags | TDF_SLIM, false); pp_right_paren (pp); - dump_generic_node (pp, TREE_OPERAND (node, 0), - spc, flags, false); - if (!integer_zerop (TREE_OPERAND (node, 1))) + dump_generic_node (pp, op0, spc, flags, false); + if (!integer_zerop (op1)) { pp_string (pp, " + "); - dump_generic_node (pp, TREE_OPERAND (node, 1), - spc, flags, false); + dump_generic_node (pp, op1, spc, flags, false); } if ((flags & TDF_ALIAS) && MR_DEPENDENCE_CLIQUE (node) != 0) --------------DD37F717A0AD92AD130A590F--