public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/105142] [12 Regression] Wrong code with -O2 since r12-2591
Date: Mon, 04 Apr 2022 09:28:13 +0000	[thread overview]
Message-ID: <bug-105142-4-EEIifkD6zZ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105142-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #4)
> Hmm, I think the error happens earlier already when we simplify
> 
> _2 < _16 && (_4 > _2) to _2 < _4
> 
> I do have a patch to do the rewrite into defined overflow which definitely
> fixes a latent issue but not this bug.

Which happens through

Applying pattern match.pd:6775, gimple-match.cc:54944
Applying pattern match.pd:3153, gimple-match.cc:177685

_2 < _16 & _2 < _4

match.pd:6775 -> _2 < min (_16, _4)

and

min (_16, _16 + 5713568809962283044)

match.pd:3153 -> _16 + 5713568809962283044 (aka _4)

which is all "nice" and validates that we can replace the inner condition
with itself but it ignores that it only subsumes the outer condition if
the outer condition is true.

That's a real tough nut to crack.  It basically means that we cannot
really combine two conditions if the definition chain of the inner
condition is under the outer condition (and involves undefined overflow),
unless we somehow can decide whether the outer condition tests for overflow
of any of the guarded stmts.  In practice this means not simplifying
interesting cases I guess and likely fold-const.cc code is susceptible
to the very same issue.

A "simple" workaround would pass in context BBs to maybe_fold_and_comparisons
and adjust maybe_fold_comparisons_from_match_pd with a custom
follow_all_ssa_edges variant, disallowing (signed) operation expansion from
the inner BB.  I will experiment with that to see what the fallout would be.
Note combining will have similar issues with using flow-sensitive range info
from inner BB defined stmts constrained by the outer check.

  parent reply	other threads:[~2022-04-04  9:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-03 22:13 [Bug tree-optimization/105142] New: [12 Regression] Wrong code with -O2 vsevolod.livinskiy at gmail dot com
2022-04-03 22:20 ` [Bug tree-optimization/105142] [12 Regression] Wrong code with -O2 since r12-2591 jakub at gcc dot gnu.org
2022-04-03 22:33 ` jakub at gcc dot gnu.org
2022-04-04  7:27 ` rguenth at gcc dot gnu.org
2022-04-04  9:07 ` rguenth at gcc dot gnu.org
2022-04-04  9:25 ` jakub at gcc dot gnu.org
2022-04-04  9:26 ` jakub at gcc dot gnu.org
2022-04-04  9:28 ` rguenth at gcc dot gnu.org [this message]
2022-04-04  9:32 ` rguenth at gcc dot gnu.org
2022-04-04 10:11 ` rguenth at gcc dot gnu.org
2022-04-04 11:20 ` rguenth at gcc dot gnu.org
2022-04-04 12:43 ` rguenth at gcc dot gnu.org
2022-04-06  6:15 ` cvs-commit at gcc dot gnu.org
2022-04-06  6:17 ` rguenth at gcc dot gnu.org
2022-11-11 14:05 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105142-4-EEIifkD6zZ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).