http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57904

--- Comment #14 from Jeffrey A. Law <law at redhat dot com> ---
So a quick prototype which reuses the infrastructure from the
phi-only-propagator cleans things up quite nicely.

Given this block after substitute_and_fold does its thing:

<bb 2>:
ubound.0_3 = 0;
size.1_4 = ubound.0_3 + 1;
size.1_5 = MAX_EXPR <size.1_4, 0>;
_6 = size.1_5 * 4;
_7 = (character(kind=4)) _6;
_8 = MAX_EXPR <_7, 1>;
sizes_9 = __builtin_malloc (_8);
size.3_10 = MAX_EXPR <ubound.0_3, 0>;
_11 = size.3_10 * 4;
_12 = (character(kind=4)) _11;
_13 = MAX_EXPR <_12, 1>;
strides_14 = __builtin_malloc (_13);
MEM[(integer(kind=4)[0:D.1917] *)sizes_9][0] = 1;
if (ubound.0_3 > 0)
  goto <bb 3>;
else
  goto <bb 6>;


I (manually) seed the phi-only propagator's 2nd step with _3 as being a newly
exposed destination of a copy/constant initialization and let that trivial
propagator do its thing...  Resulting in:

<bb 2>:
sizes_9 = __builtin_malloc (4);
strides_14 = __builtin_malloc (1);
MEM[(integer(kind=4)[0:D.1917] *)sizes_9][0] = 1;
goto <bb 6>;

Which is exactly what we want.  Also note that we collapse the conditional at
the end of the block.  That in turn makes the problematic loop unreachable and
it goes away as one would expect.

The problem I see is I'd prefer not to expose this in substitute_and_fold
directly.  That routine is used by multiple propagators.  I'm thinking that
instead we can have a callback to the pass utilizing substitute_and_fold that
gets called when something has folded.

Reply via email to