public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/100061] [10/11 Regression] Comparison guarding undefined behaviour disappears
Date: Tue, 13 Apr 2021 13:32:28 +0000	[thread overview]
Message-ID: <bug-100061-4-u0WRYIM6qN@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100061-4@http.gcc.gnu.org/bugzilla/>

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The two match.pd rules that trigger here are:
/* Transform (@0 < @1 and @0 < @2) to use min,
   (@0 > @1 and @0 > @2) to use max */
(for logic (bit_and bit_and bit_and bit_and bit_ior bit_ior bit_ior bit_ior)
     op    (lt      le      gt      ge      lt      le      gt      ge     )
     ext   (min     min     max     max     max     max     min     min    )
 (simplify
  (logic (op:cs @0 @1) (op:cs @0 @2))
  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
       && TREE_CODE (@0) != INTEGER_CST)
   (op @0 (ext @1 @2)))))

and

/* max (a, a + CST) -> a + CST where CST is positive.  */
/* max (a, a + CST) -> a where CST is negative.  */
(simplify
 (max:c @0 (plus@2 @0 INTEGER_CST@1))
  (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
   (if (tree_int_cst_sgn (@1) > 0)
    @2
    @0)))

Those look fine.  What doesn't look fine is that maybe_fold_and_comparisons
and maybe_fold_or_comparisons when calling maybe_fold_comparisons_from_match_pd
pretend they are BIT_AND_EXPR or BIT_IOR_EXPR when they actually are
TRUTH_ANDIF_EXPR or TRUTH_ORIF_EXPR (unless we can prove both comparisons are
in the same bb, but we don't really tell).
Perhaps the cases that were only handled before Martin's patch,
i.e. when gimple_simplified_result_is_gimple_val, was ok because then we don't
really use a stmt that could trigger UB.
Or perhaps ifcombine should check what maybe_fold_and_comparisons has returned
and if it is a comparison where one of the operands is a SSA_NAMEs defining
stmt  doesn't dominate both original comparisons and that stmt or anything it
uses could trigger UB, punt?  Though I'd be afraid we could regress many cases
that old gimple-fold.c stuff got right (if it did).

  parent reply	other threads:[~2021-04-13 13:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-13 10:15 [Bug c/100061] New: " t.josefowitz at gmail dot com
2021-04-13 11:45 ` [Bug tree-optimization/100061] " rguenth at gcc dot gnu.org
2021-04-13 11:52 ` rguenth at gcc dot gnu.org
2021-04-13 12:01 ` [Bug tree-optimization/100061] [10/11 Regression] " jakub at gcc dot gnu.org
2021-04-13 13:00 ` jakub at gcc dot gnu.org
2021-04-13 13:32 ` jakub at gcc dot gnu.org [this message]
2021-04-13 13:49 ` rguenth at gcc dot gnu.org
2021-04-13 13:52 ` rguenth at gcc dot gnu.org
2021-04-13 13:56 ` jakub at gcc dot gnu.org
2021-04-13 14:06 ` t.josefowitz at gmail dot com
2021-08-23 20:06 ` [Bug tree-optimization/100061] [10/11/12 " t.josefowitz at gmail dot com
2021-08-24  6:47 ` rguenth at gcc dot gnu.org
2022-06-28 10:44 ` [Bug tree-optimization/100061] [10/11/12/13 " jakub at gcc dot gnu.org
2023-01-18 16:55 ` jakub at gcc dot gnu.org
2023-01-19 13:22 ` [Bug tree-optimization/100061] [10/11 " rguenth at gcc dot gnu.org
2023-07-07 10:39 ` [Bug tree-optimization/100061] [11 " rguenth 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-100061-4-u0WRYIM6qN@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).