On 5/18/22 02:28, Richard Biener wrote:
On Tue, May 17, 2022 at 8:40 PM Andrew MacLeod via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
I haven't checked this patch in yet.  This implements a side effect that
the divisor cannot be 0 after a divide executes. This allows us to fold
the divide away:

a = b / c;
if (c == 0)
    dead();

This bootstraps on x86_64-pc-linux-gnu with no regressions, but I first
wanted to check to see if there are some flags or conditions that should
e checked in order NOT to do this optimization.  I am guessing there is
probably something :-)    Anyway, this is how we straightforwardly add
side effects now.

Does the patch conditions need tweaking to apply the side effect?
What does "after the stmt" mean?  If the stmt throws internally then on
the EH edge the divisor can be zero.

How do you fold away the divide in your above example?

We dont fold anyway the divide, just the condition checking if c == 0.. this would be identical in function to

b= *ptr;
if (ptr == 0)
  dead();

after the b = *ptr stmt is done, ptr is known to be non-zero. likewise,  after a = b / c, all subsequent stmts know c is non-zero

Any outgoing EH edge from the block will not have this side effect applied (ie ptr and c will still be varying, or whatever they were to start).  All other edges will have the non-zero effect, as will any stmts in this block which occur after the initial one that triggers the side effect.

Andrew


Reply via email to