On 01/07/2013 01:42 PM, Steven Bosscher wrote:
For optimizations it's a bit more difficult.
Somewhat. For what I'm suggesting, the way we'd miss an optimization
would be if by removing the unreachable block and simplifying the CFG we
ultimately remove a conditional which produced a result which we could
use later.
Something like this (tweaking your 2nd test):
int foo (int b, int c, int d)
{
int res, r = 0;
res = 5 * d + b;
if (d)
__builtin_unreachable ();
if (c)
r = res;
return r + d;
}
What I'm suggesting would effectively remove the conditional and
__builtin_unreacahble, so at the source level it'd look like:
int foo (int b, int c, int d)
{
int res, r = 0;
res = 5 * d + b;
if (c)
r = res;
return r + d;
}
By removing the conditional, we've lost the fact that to reach the
return statement, "d" must be zero, which is useful in optimizing the
return statement.
The situations I'm
looking at, are all sinking related, and I suspect that most missed
optimizations will be of this form:
int foo (int b, int c, int d)
{
int res, r = 0;
res = 5 * d + b;
if (d)
__builtin_unreachable ();
if (c)
r = res;
return r;
}
I don't see how my proposal would inhibit sinking in this kind of code.
In fact, it'd made it easier.
I already showed how the control dependence graph looks Wrong with
__builtin_unreachable calls in place. Any transformation using the CDG
will also be less effective because of this.
And what I'm suggesting would actually fix the post dominator tree,
among other things. Where we potentially lose is the tweaked case
above. However, if we do the optimization at the right time, we can get
the benefits we're both looking for, I believe.
jeff