public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1
Date: Thu, 16 Jun 2022 12:36:42 +0000	[thread overview]
Message-ID: <bug-105984-4-tk8zCvZs29@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105984-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:74e6a40335765077e235269f19d2d9905d0d9e44

commit r13-1133-g74e6a40335765077e235269f19d2d9905d0d9e44
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Jun 16 14:36:04 2022 +0200

    match.pd: Fix up __builtin_mul_overflow_p signed type optimization
[PR105984]

    Earlier in the simplification pattern, we require that @0 has compatible
    type to the type of IMAGPART_EXPR, but for @1 which is a non-zero constant
    all we require is that it the constant fits into that type.
    Later the code checks if the constant is negative, because when min / max
    values are divided by negative divisor, lo will be higher than hi.
    In the following testcase, @1 has unsigned char type, while @0 has
    int type, so @1 which is 254 is wi::neg_p and we were swapping lo and hi,
    even when @1 cast to int isn't negative.

    We could use tree_int_cst_sgn (@1) < 0 as the check instead and it would
    work both for narrower types of @1 and even same or wider ones, but
    I've noticed we probably don't want to call fold_convert (TREE_TYPE (@0),
@1)
    twice and when we save that result in a temporary, we can just use
wi::neg_p
    on that temporary.

    2022-06-16  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/105984
            * match.pd (__builtin_mul_overflow_p (x, cst, (stype) 0) ->
            x > stype_max / cst || x < stype_min / cst): fold_convert @1
            to TREE_TYPE (@0) just once and test for negative divisor
            also on that folded constant instead of on @1.

            * gcc.c-torture/execute/pr105984.c: New test.

  parent reply	other threads:[~2022-06-16 12:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15  5:20 [Bug middle-end/105984] New: " zsojka at seznam dot cz
2022-06-15  9:15 ` [Bug middle-end/105984] " rguenth at gcc dot gnu.org
2022-06-15  9:26 ` jakub at gcc dot gnu.org
2022-06-15 11:18 ` jakub at gcc dot gnu.org
2022-06-16 12:36 ` cvs-commit at gcc dot gnu.org [this message]
2022-06-16 12:38 ` jakub 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-105984-4-tk8zCvZs29@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).