All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>,
	Dibyendu Majumdar <mobile@majumdar.org.uk>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: sparse-next and preview of 0.5.1-rc5
Date: Wed, 19 Jul 2017 20:19:02 -0700	[thread overview]
Message-ID: <CANeU7QkevpEdcp-WmM820sjJ4-LhVyPHeGHETh64WG3jPzewhA@mail.gmail.com> (raw)
In-Reply-To: <20170719221738.2gkctzmdjajz4uec@ltop.local>

On Wed, Jul 19, 2017 at 3:17 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
>
> Even now, I'm not really back. Just taking time to reply here
> while I have the opportunity to.

OK. Good to know then guessing


>> Can you show me some C input file that your original patch will do the
>> right thing and current one will miss the opportunity to simplify?
>> Even for the case it is just a suspect of producing worse code is fine.
>> Just point me to some test case, I will investigate and compare the
>> results.
>
> Test cases are test cases and code is code.
>
> I'll copy here verbatim the commit message of the patch that was fixed
> by the original patch (the one that had "Fixes: 51cfbc90a5e1462fcd624a1598ecd985a508a5d6

I still don't have a valid test case to difference sparse-next
and your patch series.

If your test case is that switch statement, I make a test case
out of it. Sparse-next and yoru patch show the same result
bytecode wise:

int *ptr;
int foo(int *p, int i)
{

switch (i - i) {        // will be optimized to 0
case 0:                 // will be the simple branch
return 0;
case 1:                 // will be optimized away
p = ptr;
do {            // will be an unreachable loop
   *p++ = 123;
} while (--i);
}
return 1;
}

$ ./test-linearize /tmp/d.c
/tmp/d.c:1:5: warning: symbol 'ptr' was not declared. Should it be static?
/tmp/d.c:2:5: warning: symbol 'foo' was not declared. Should it be static?
foo:
.L0:
<entry-point>
ret.32      $0

You know what I want. I want the test case can show sparse-next
have bug or less optimal than your series. If every thing else is
the same, the one in sparse-next is simpler.

>
>         commit 51cfbc90a5e1462fcd624a1598ecd985a508a5d6
>         Author: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
>         Date:   2017-04-26 12:21:21 +0200
>
>             fix: kill unreachable BBs after killing a child
>
>             When simplifying a switch into a simple branch all the now
>             unused children of the current BB must be removed.
>             If one of these children become now orphaned, it is directly
>             killed (it will need to be killed soon or later since it is
>             unreachable).
>
>             However, if one of the killed children is the header of a loop
>             where some variables are updated this may cause problems.
>             Indeed, by killing the header (which contains the phisrc of
>             the entry value of the variable) the whole loop may become
>             unreachable but is not killed yet, OTOH simplification of
>             the associated OP_PHI may create a cycle which may then be
>             detected later by simplify_one_memop() which will issue a
>             "crazy programmer" warning while the programmer was innocent.

That sounds very much like the wine dead loop case recently report on
the mailing list. I think you are likely having a bug elsewhere make you
believe that you have to kill instruction there. I just tested, your patches
will do the dead loop on the wine test C file as well. We might talking about
the same bug.
>
>             This situation can be seen in code like:
>                     int *p;
>                     switch (i - i) {        // will be optimized to 0
>                     case 0:                 // will be the simple branch
>                             return 0;
>                     case 1:                 // will be optimized away
>                             p = ptr;
>                             do {            // will be an unreachable loop
>                                     *p++ = 123;
>                             } while (--i);
>                     }
>
>             Fix this by calling kill_unreachable_bbs() after having
>             simplified the switch into a branch. This will avoid to
>             create a cycle with because of the removed phisrc in the
>             header and as an added benefit will avoid to waste time
>             trying to simplify BBs that are unreachable.
>
>             In addition, it's now useless to call kill_bb() for each
>             removed switch's children as kill_unreachable_bbs() will
>             do that too.

The simple patch in sparse-next has the same output result

> It's not at all a problem of some missing optimization opportunity.
> It's a problem of applying some optimization (OP_PHI simplification)
> and then giving a warning for the consequence of this optimization
> (the "crazy programmer" warning) in incorrect conditions/wrong
> assumption (a variable must not be considered as undefined if it
> is part of an unreachable BB, it should just be ignored).
>
> I hope it is clear enough now.

Can you show me a test C code trigger the problem?

> I also assure that instead of quickly rewriting someone's patch
> (because you don't like it and think you can do better) it would
> be so much better to simply:
I did.
> - *say* what you don't like in the patch

Might have simpler way.

> - *ask* why things are done like this way

I also did. I repeatedly ask for the test C code that show the bug
if I don't immediately remove the dead code.

> - *ask* if things couldn't be done this other way instead.

Same as above. Show me the code please. I would much rather
looking at the test C code that demo the problem than arguing here.

Chris

  reply	other threads:[~2017-07-20  3:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-14 17:48 sparse-next and preview of 0.5.1-rc5 Christopher Li
2017-07-15 18:22 ` Luc Van Oostenryck
2017-07-16  2:34   ` Christopher Li
2017-07-17  1:20     ` Christopher Li
2017-07-19 22:17     ` Luc Van Oostenryck
2017-07-20  3:19       ` Christopher Li [this message]
2017-07-20 22:35         ` Luc Van Oostenryck
2017-07-21  3:40           ` Christopher Li
2017-07-22  3:55             ` Christopher Li
2017-07-26  9:00               ` Luc Van Oostenryck
2017-07-26 16:10                 ` Christopher Li
2017-07-26 19:28                   ` Luc Van Oostenryck

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=CANeU7QkevpEdcp-WmM820sjJ4-LhVyPHeGHETh64WG3jPzewhA@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=mobile@majumdar.org.uk \
    --cc=torvalds@linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.