https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103188

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aldyh at gcc dot gnu.org

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Caused by g:e82c382971664d6fd138cc36020db4b1a91885c6, the call tree roots at

#666394 0x00000000015f2170 in should_duplicate_loop_header_p (
    header=<basic_block 0x7ffff654fbc8 (14)>, loop=0x7ffff66aa9f0, 
    limit=0x7fffffffd97c, query=0x3fccb70)
    at /home/rguenther/src/gcc3/gcc/tree-ssa-loop-ch.c:83
83            && !entry_loop_condition_is_static (loop, query))

likely ranger is confused by the intermediate IL (from other loops header
copying), the IL is kept partly not in up-to-date SSA form (because running
update_ssa is costly so we run it once after doing all header copying in
a function).

In this case we applied loop header copying to loop 4 containing loop 5
which we are now processing.

Not up-to-date SSA form means that while SSA defs are copied, the SSA uses
in a stmt are still old and _not_ replaced with their current definition.
There's only so much you can do with such IL, in particular invoking SCEV
isn't among that.

You can actually check whether a SSA name may be affected by checking
name_registered_for_update_p.  SCEV doesn't do that.

In the end that means that we'd have to do the ranger analysis before
actually applying the header copying.

Note that the current place of the

  /* Avoid loop header copying when optimizing for size unless we can
     determine that the loop condition is static in the first
     iteration.  */
  if (optimize_loop_for_size_p (loop)
      && !loop->force_vectorize
      && !entry_loop_condition_is_static (loop, query))
    {

is off in any case, since we iterate on blocks to copy, instead it should
be done exactly once per loop.  So we can do the "head", up until this
and the very first should_duplicate_loop_header_p first for each loop,
recording candidates in a vector and in a second loop process them all,
not doing the already done entry_loop_condition_is_static.

Let me cook up a patch to do that.

Reply via email to