public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/93491] Wrong optimization: const-function moved over control flow leading to crashes
       [not found] <bug-93491-4@http.gcc.gnu.org/bugzilla/>
@ 2021-09-01  9:08 ` rguenth at gcc dot gnu.org
  2021-09-01  9:32 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-01  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
'const' and trapping/EH are distinct bits, and definiteily
tree/gimple_could_trap_p reports true for the 1 / i; stmt.  Note that traps
are not considered a "side-effect" and thus passes just checking for
gimple_has_side_effects will not get this.

But traps in general are difficult beasts, and what to do when facing them
depends on the actual transform.  In this case it is tree PRE hoisting the
g(0) call.

It's vn_reference_may_trap that handles calls optimistically:

/* Return true if the reference operation REF may trap.  */

bool
vn_reference_may_trap (vn_reference_t ref)
{
  switch (ref->operands[0].opcode)
    {
    case MODIFY_EXPR:
    case CALL_EXPR:
      /* We do not handle calls.  */
    case ADDR_EXPR:
      /* And toplevel address computations never trap.  */
      return false;

but note that tree_could_trap_p for example only looks at the actual
call instruction, not at as to whether the called function execution
might trap.  So calls need to be handled specially and we don't have
a way to test/record for whether a called function might trap.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/93491] Wrong optimization: const-function moved over control flow leading to crashes
       [not found] <bug-93491-4@http.gcc.gnu.org/bugzilla/>
  2021-09-01  9:08 ` [Bug tree-optimization/93491] Wrong optimization: const-function moved over control flow leading to crashes rguenth at gcc dot gnu.org
@ 2021-09-01  9:32 ` rguenth at gcc dot gnu.org
  2021-09-01 10:56 ` cvs-commit at gcc dot gnu.org
  2021-09-01 10:56 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-01  9:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixing this FAILs the testcase for PR88087

FAIL: gcc.dg/tree-ssa/pr88087.c scan-tree-dump pre "Eliminated: 1"

which exactly asks for this kind of transform:

int f();
int d;
void c()
{
  for (;;)
    {
      f();
      int (*fp)() __attribute__((const)) = (void *)f;
      d = fp();
    }
}

/* We shouldn't ICE and hoist the const call of fp out of the loop.  */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/93491] Wrong optimization: const-function moved over control flow leading to crashes
       [not found] <bug-93491-4@http.gcc.gnu.org/bugzilla/>
  2021-09-01  9:08 ` [Bug tree-optimization/93491] Wrong optimization: const-function moved over control flow leading to crashes rguenth at gcc dot gnu.org
  2021-09-01  9:32 ` rguenth at gcc dot gnu.org
@ 2021-09-01 10:56 ` cvs-commit at gcc dot gnu.org
  2021-09-01 10:56 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-01 10:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:13a43a90aea368a25da50762eba4873bafb4e448

commit r12-3284-g13a43a90aea368a25da50762eba4873bafb4e448
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Sep 1 11:49:39 2021 +0200

    tree-optimization/93491 - avoid PRE of trapping calls across exits

    This makes us avoid PREing calls that could trap across other
    calls that might not return.  The PR88087 testcase has exactly
    such case so I've refactored the testcase to contain a valid PRE.
    I've also adjusted PRE to not consider pure calls possibly
    not returning in line with what we do elsewhere.

    Note we don't have a good idea whether a function always returns
    normally or whether its body is known to never trap.  That's
    something IPA could compute.

    2021-09-01  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/93491
            * tree-ssa-pre.c (compute_avail): Set BB_MAY_NOTRETURN
            after processing the stmt itself.  Do not consider
            pure functions possibly not returning.  Properly avoid
            adding possibly trapping calls to EXP_GEN when there's
            a preceeding possibly not returning call.
            * tree-ssa-sccvn.c (vn_reference_may_trap): Conservatively
            not handle calls.

            * gcc.dg/torture/pr93491.c: New testcase.
            * gcc.dg/tree-ssa/pr88087.c: Change to valid PRE opportunity.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/93491] Wrong optimization: const-function moved over control flow leading to crashes
       [not found] <bug-93491-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-09-01 10:56 ` cvs-commit at gcc dot gnu.org
@ 2021-09-01 10:56 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-01 10:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-01 10:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-93491-4@http.gcc.gnu.org/bugzilla/>
2021-09-01  9:08 ` [Bug tree-optimization/93491] Wrong optimization: const-function moved over control flow leading to crashes rguenth at gcc dot gnu.org
2021-09-01  9:32 ` rguenth at gcc dot gnu.org
2021-09-01 10:56 ` cvs-commit at gcc dot gnu.org
2021-09-01 10:56 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).