public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
To: Richard Biener <richard.guenther@gmail.com>,
	Jakub Jelinek <jakub@redhat.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PR72835] Incorrect arithmetic optimization involving bitfield arguments
Date: Fri, 19 Aug 2016 08:19:00 -0000	[thread overview]
Message-ID: <CAELXzTNMY8VW9ZbDcGohmEtT4W6-=PEdAyuow+H_SSZ2X4to3Q@mail.gmail.com> (raw)
In-Reply-To: <e331b985-4951-1111-6f99-5af718064c78@linaro.org>

Ping?

https://gcc.gnu.org/ml/gcc-patches/2016-08/msg00872.html

Thanks,
Kugan

On 11 August 2016 at 09:09, kugan <kugan.vivekanandarajah@linaro.org> wrote:
> Hi,
>
>
> On 10/08/16 20:28, Richard Biener wrote:
>>
>> On Wed, Aug 10, 2016 at 10:57 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>
>>> On Wed, Aug 10, 2016 at 08:51:32AM +1000, kugan wrote:
>>>>
>>>> I see it now. The problem is we are just looking at (-1) being in the
>>>> ops
>>>> list for passing changed to rewrite_expr_tree in the case of
>>>> multiplication
>>>> by negate.  If we have combined (-1), as in the testcase, we will not
>>>> have
>>>> the (-1) and will pass changed=false to rewrite_expr_tree.
>>>>
>>>> We should set changed based on what happens in try_special_add_to_ops.
>>>> Attached patch does this. Bootstrap and regression testing are ongoing.
>>>> Is
>>>> this OK for trunk if there is no regression.
>>>
>>>
>>> I think the bug is elsewhere.  In particular in
>>> undistribute_ops_list/zero_one_operation/decrement_power.
>>> All those look problematic in this regard, they change RHS of statements
>>> to something that holds a different value, while keeping the LHS.
>>> So, generally you should instead just add a new stmt next to the old one,
>>> and adjust data structures (replace the old SSA_NAME in some ->op with
>>> the new one).  decrement_power might be a problem here, dunno if all the
>>> builtins are const in all cases that DSE would kill the old one,
>>> Richard, any preferences for that?  reset flow sensitive info + reset
>>> debug
>>> stmt uses, or something different?  Though, replacing the LHS with a new
>>> anonymous SSA_NAME might be needed too, in case it is before SSA_NAME of
>>> a
>>> user var that doesn't yet have any debug stmts.
>>
>>
>> I'd say replacing the LHS is the way to go, with calling the appropriate
>> helper
>> on the old stmt to generate a debug stmt for it / its uses (would need
>> to look it
>> up here).
>>
>
> Here is an attempt to fix it. The problem arises when in
> undistribute_ops_list, we linearize_expr_tree such that NEGATE_EXPR is added
> (-1) MULT_EXPR (OP). Real problem starts when we handle this in
> zero_one_operation. Unlike what was done earlier, we now change the stmt
> (with propagate_op_to_signle use or by directly) such that the value
> computed by stmt is no longer what it used to be. Because of this, what is
> computed in undistribute_ops_list and rewrite_expr_tree are also changed.
>
> undistribute_ops_list already expects this but rewrite_expr_tree will not if
> we dont pass the changed as an argument.
>
> The way I am fixing this now is, in linearize_expr_tree, I set ops_changed
> to true if we change NEGATE_EXPR to (-1) MULT_EXPR (OP). Then when we call
> zero_one_operation with ops_changed = true, I replace all the LHS in
> zero_one_operation with the new SSA and replace all the uses. I also call
> the rewrite_expr_tree with changed = false in this case.
>
> Does this make sense? Bootstrapped and regression tested for
> x86_64-linux-gnu without any new regressions.
>
> Thanks,
> Kugan
>
>
> gcc/testsuite/ChangeLog:
>
> 2016-08-10  Kugan Vivekanandarajah  <kuganv@linaro.org>
>
>         PR tree-optimization/72835
>         * gcc.dg/tree-ssa/pr72835.c: New test.
>
> gcc/ChangeLog:
>
> 2016-08-10  Kugan Vivekanandarajah  <kuganv@linaro.org>
>
>         PR tree-optimization/72835
>         * tree-ssa-reassoc.c (zero_one_operation): Incase of NEGATE_EXPR
> create and use
>          new SSA_NAME.
>         (try_special_add_to_ops): Return true if we changed the value in
> operands.
>         (linearize_expr_tree): Return true if try_special_add_top_ops set
> ops_changed to true.
>         (undistribute_ops_list): Likewise.
>         (reassociate_bb): Pass ops_changed returned by linearlize_expr_tree
> to rewrite_expr_tree.
>
>
>
> whil cif we change the operands such that the
>
> /zero_one_operation

  reply	other threads:[~2016-08-19  8:19 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 [this message]
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

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='CAELXzTNMY8VW9ZbDcGohmEtT4W6-=PEdAyuow+H_SSZ2X4to3Q@mail.gmail.com' \
    --to=kugan.vivekanandarajah@linaro.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --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).