public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Georg-Johann Lay <avr@gjlay.de>
To: kugan <kugan.vivekanandarajah@linaro.org>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Richard Biener <richard.guenther@gmail.com>
Subject: Re: [PR72835] Incorrect arithmetic optimization involving bitfield arguments
Date: Wed, 14 Sep 2016 14:31:00 -0000	[thread overview]
Message-ID: <f8532d88-a304-992b-c399-0d835ba43c18@gjlay.de> (raw)
In-Reply-To: <0a1eaaf8-3ede-cd56-ffb5-40b25f94e46e@linaro.org>

On 09.08.2016 15:43, kugan wrote:
> Hi,
>
> The test-case in PR72835 is failing with -O2 and passing with
> -fno-tree-reassoc. It also passes with -O2 -fno-tree-vrp.
>
> diff of .115t.dse2 and .116t.reassoc1 for the c++ testcase is as follows, which
> looks OK.
>
> +  unsigned int _16;
> +  unsigned int _17;
> +  unsigned int _18;
>
>    <bb 2>:
>    _1 = s1.m2;
>    _2 = (unsigned int) _1;
>    _3 = s1.m3;
>    _4 = (unsigned int) _3;
> -  _5 = -_4;
> -  _6 = _2 * _5;
> +  _5 = _4;
> +  _6 = _5 * _2;
>    var_32.0_7 = var_32;
>    _8 = (unsigned int) var_32.0_7;
>    _9 = s1.m1;
>    _10 = (unsigned int) _9;
> -  _11 = -_10;
> -  _12 = _8 * _11;
> -  c_14 = _6 + _12;
> +  _11 = _10;
> +  _12 = _11 * _8;
> +  _16 = _12 + _6;
> +  _18 = _16;
> +  _17 = -_18;
> +  c_14 = _17;
>    if (c_14 != 4098873984)
>
>
> However, I noticed that when we re-associate and assign different operands to
> the stmts, we are not resetting the flow information to the LHS. This looks
> wrong. Attached patch resets it. With this, the testcases in TH PR is now working.
>
>
> Bootstrap and regression testing for x86_64-linux-gnu is in progress. Is this
> OK for trunk if there is no regression.
>
> Thanks,
> Kugan
>
> gcc/testsuite/ChangeLog:
>
> 2016-08-09  Kugan Vivekanandarajah  <kuganv@linaro.org>
>
>     PR tree-optimization/72835
>     * gcc.dg/torture/pr72835.c: New test.
>
> gcc/ChangeLog:
>
> 2016-08-09  Kugan Vivekanandarajah  <kuganv@linaro.org>
>
>     PR tree-optimization/72835
>     * tree-ssa-reassoc.c (rewrite_expr_tree): Reset value_range of LHS when
>     operands are changed.
>     (rewrite_expr_tree_parallel): Likewise.
>
> Hi,
>
> The test-case in PR72835 is failing with -O2 and passing with -fno-tree-reassoc. It also passes with -O2 -fno-tree-vrp.
>
> diff of .115t.dse2 and .116t.reassoc1 for the c++ testcase is as follows, which looks OK.
>
> +  unsigned int _16;
> +  unsigned int _17;
> +  unsigned int _18;
>
>    <bb 2>:
>    _1 = s1.m2;
>    _2 = (unsigned int) _1;
>    _3 = s1.m3;
>    _4 = (unsigned int) _3;
> -  _5 = -_4;
> -  _6 = _2 * _5;
> +  _5 = _4;
> +  _6 = _5 * _2;
>    var_32.0_7 = var_32;
>    _8 = (unsigned int) var_32.0_7;
>    _9 = s1.m1;
>    _10 = (unsigned int) _9;
> -  _11 = -_10;
> -  _12 = _8 * _11;
> -  c_14 = _6 + _12;
> +  _11 = _10;
> +  _12 = _11 * _8;
> +  _16 = _12 + _6;
> +  _18 = _16;
> +  _17 = -_18;
> +  c_14 = _17;
>    if (c_14 != 4098873984)
>
>
> However, I noticed that when we re-associate and assign different operands to the stmts, we are not resetting the flow information to the LHS. This looks wrong. Attached patch resets it. With this, the testcases in TH PR is now working.
>
>
> Bootstrap and regression testing for x86_64-linux-gnu is in progress. Is this OK for trunk if there is no regression.
>
> Thanks,
> Kugan
>
> gcc/testsuite/ChangeLog:
>
> 2016-08-09  Kugan Vivekanandarajah  <kuganv@linaro.org>
>
>     PR tree-optimization/72835
>     * gcc.dg/torture/pr72835.c: New test.
>
> gcc/ChangeLog:
>
> 2016-08-09  Kugan Vivekanandarajah  <kuganv@linaro.org>
>
>     PR tree-optimization/72835
>     * tree-ssa-reassoc.c (rewrite_expr_tree): Reset value_range of LHS when
>     operands are changed.
>     (rewrite_expr_tree_parallel): Likewise.
>
> pr72835.txt
>
> diff --git a/gcc/testsuite/gcc.dg/torture/pr72835.c b/gcc/testsuite/gcc.dg/torture/pr72835.c
> index e69de29..d7d0a8d 100644
> --- a/gcc/testsuite/gcc.dg/torture/pr72835.c
> +++ b/gcc/testsuite/gcc.dg/torture/pr72835.c
> @@ -0,0 +1,36 @@
> +/* PR tree-optimization/72835 */
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +struct struct_1 {
> +    unsigned int m1 : 6 ;
> +    unsigned int m2 : 24 ;

This test needs dg-require effective target int32plus because it will break on 
int=16bit targets.

> +    unsigned int m3 : 6 ;
> +};
> +
> +unsigned short var_32 = 0x2d10;
> +
> +struct struct_1 s1;
> +
> +void init ()
> +{
> +  s1.m1 = 4;
> +  s1.m2 = 0x7ca4b8;
> +  s1.m3 = 24;
> +}
> +
> +void foo ()
> +{
> +  unsigned int c =
> +    ((unsigned int) s1.m2) * (-((unsigned int) s1.m3))
> +    + (var_32) * (-((unsigned int) (s1.m1)));
> +  if (c != 4098873984)
> +    __builtin_abort ();
> +}
> +
> +int main ()
> +{
> +    init ();
> +    foo ();
> +    return 0;
> +}

      parent reply	other threads:[~2016-09-14 14:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-09 13:43 kugan
2016-08-09 21:43 ` kugan
2016-08-09 21:46   ` Jakub Jelinek
2016-08-09 21:51     ` kugan
2016-08-09 21:55       ` Jakub Jelinek
2016-08-09 22:51         ` kugan
2016-08-10  1:46           ` kugan
2016-08-10  8:57           ` Jakub Jelinek
2016-08-10  9:14             ` kugan
2016-08-10 10:28             ` Richard Biener
2016-08-10 23:09               ` kugan
2016-08-19  8:19                 ` Kugan Vivekanandarajah
2016-08-25 12:24                 ` Richard Biener
2016-09-02  8:09                   ` Kugan Vivekanandarajah
2016-09-14 11:38                     ` Richard Biener
2016-09-18 21:58                       ` kugan
2016-09-19 13:49                         ` Richard Biener
2016-09-20  3:27                           ` kugan
2016-09-20 12:01                             ` Richard Biener
2016-08-09 21:50   ` Andrew Pinski
2016-08-09 21:53     ` kugan
2016-09-14 14:31 ` Georg-Johann Lay [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f8532d88-a304-992b-c399-0d835ba43c18@gjlay.de \
    --to=avr@gjlay.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kugan.vivekanandarajah@linaro.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).