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

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ah, the missed store motion is because of the IS_NAN (k) check which
makes the memory accesses only conditional executed and thus possibly
trap.  We "fix" that only during loop unswitching which hoists the
invariant check.  But there's no store-motion after unswitching.
Removing this check shows we can apply store-motion.

  /* If it can trap, it must be always executed in LOOP.
     Readonly memory locations may trap when storing to them, but
     tree_could_trap_p is a predicate for rvalues, so check that
     explicitly.  */
  base = get_base_address (ref->mem.ref);
  if ((tree_could_trap_p (ref->mem.ref)
       || (DECL_P (base) && TREE_READONLY (base)))
      /* ???  We can at least use false here, allowing loads?  We
         are forcing conditional stores if the ref is not always
         stored to later anyway.  So this would only guard
         the load we need to emit.  Thus when the ref is not
         loaded we can elide this completely?  */
      && !ref_always_accessed_p (loop, ref, true))
    return false;

as the comment explains we cannot do "conditional" initialization, thus
guard the load with the duplicated invariant condition.

Reply via email to