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/111151] [12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu
Date: Tue, 26 Mar 2024 10:22:14 +0000	[thread overview]
Message-ID: <bug-111151-4-yUd5HDJlHn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111151-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #15 from GCC 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:c4f2c84e8fa369856aee76679590eb613724bfb0

commit r14-9668-gc4f2c84e8fa369856aee76679590eb613724bfb0
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 26 11:21:38 2024 +0100

    fold-const: Punt on MULT_EXPR in extract_muldiv MIN/MAX_EXPR case
[PR111151]

    As I've tried to explain in the comments, the extract_muldiv_1
    MIN/MAX_EXPR optimization is wrong for code == MULT_EXPR.
    If the multiplication is done in unsigned type or in signed
    type with -fwrapv, it is fairly obvious that max (a, b) * c
    in many cases isn't equivalent to max (a * c, b * c) (or min if c is
    negative) due to overflows, but even for signed with undefined overflow,
    the optimization could turn something without UB in it (where
    say a * c invokes UB, but max (or min) picks the other operand where
    b * c doesn't).
    As for division/modulo, I think it is in most cases safe, except if
    the problematic INT_MIN / -1 case could be triggered, but we can
    just punt for MAX_EXPR because for MIN_EXPR if one operand is INT_MIN,
    we'd pick that operand already.  It is just for completeness, match.pd
    already has an optimization which turns x / -1 into -x, so the division
    by zero is mostly theoretical.  That is also why in the testcase the
    i case isn't actually miscompiled without the patch, while the c and f
    cases are.

    2024-03-26  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/111151
            * fold-const.cc (extract_muldiv_1) <case MAX_EXPR>: Punt for
            MULT_EXPR altogether, or for MAX_EXPR if c is -1.

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

  parent reply	other threads:[~2024-03-26 10:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25  6:39 [Bug middle-end/111151] New: " jwzeng at nuaa dot edu.cn
2023-08-25  7:16 ` [Bug middle-end/111151] " rguenth at gcc dot gnu.org
2023-08-25  7:16 ` rguenth at gcc dot gnu.org
2023-08-25 11:51 ` mikpelinux at gmail dot com
2023-08-25 12:27 ` rguenth at gcc dot gnu.org
2023-08-25 12:28 ` rguenth at gcc dot gnu.org
2023-08-25 12:35 ` rguenth at gcc dot gnu.org
2023-08-26  3:27 ` pinskia at gcc dot gnu.org
2024-03-22 13:40 ` law at gcc dot gnu.org
2024-03-22 17:29 ` jakub at gcc dot gnu.org
2024-03-22 17:37 ` jakub at gcc dot gnu.org
2024-03-22 17:41 ` jakub at gcc dot gnu.org
2024-03-22 17:57 ` jakub at gcc dot gnu.org
2024-03-22 18:48 ` jakub at gcc dot gnu.org
2024-03-22 19:15 ` jakub at gcc dot gnu.org
2024-03-25  7:23 ` rguenth at gcc dot gnu.org
2024-03-25 11:01 ` jakub at gcc dot gnu.org
2024-03-25 12:45 ` rguenth at gcc dot gnu.org
2024-03-26 10:22 ` cvs-commit at gcc dot gnu.org [this message]
2024-03-26 10:32 ` [Bug middle-end/111151] [12/13 " jakub at gcc dot gnu.org
2024-03-26 15:43 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:55 ` 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-111151-4-yUd5HDJlHn@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).