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 tree-optimization/107541] [13 Regression] wrong code at -O1, -O2 and -O3 on x86_64-linux-gnu
Date: Mon, 07 Nov 2022 11:42:02 +0000	[thread overview]
Message-ID: <bug-107541-4-nHnAWBkiWv@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107541-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Aldy Hernandez <aldyh@gcc.gnu.org>:

https://gcc.gnu.org/g:3bff15c1c9fb3eb0bb042717e072476ec2d6d88c

commit r13-3752-g3bff15c1c9fb3eb0bb042717e072476ec2d6d88c
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 7 08:40:12 2022 +0100

    [range-op] Restrict division by power of 2 optimization to positive
numbers.

    The problem here is that we are transforming a division by a power of
    2 into a right shift, and using this to shift the maybe nonzero bits.
    This gives the wrong result when the number being divided is negative.

    In the testcase we are dividing this by 8:

            [irange] int [-256, -255] NONZERO 0xffffff01

    and coming up with:

            [irange] int [-32, -31] NONZERO 0xffffffe0

    The maybe nonzero bits are wrong as -31 has the LSB set (0xffffffe1)
    whereas the bitmask says the lower 4 bits are off.

            PR tree-optimization/107541

    gcc/ChangeLog:

            * range-op.cc (operator_div::fold_range): Restrict power of 2
            optimization to positive numbers.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/pr107541.c: New test.

  parent reply	other threads:[~2022-11-07 11:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-06 12:56 [Bug tree-optimization/107541] New: " zhendong.su at inf dot ethz.ch
2022-11-06 18:20 ` [Bug tree-optimization/107541] [13 Regression] " pinskia at gcc dot gnu.org
2022-11-06 18:28 ` franckbehaghel_gcc at protonmail dot com
2022-11-06 18:30 ` pinskia at gcc dot gnu.org
2022-11-06 21:51 ` franckbehaghel_gcc at protonmail dot com
2022-11-07  7:03 ` rguenth at gcc dot gnu.org
2022-11-07  7:57 ` aldyh at gcc dot gnu.org
2022-11-07  9:18 ` aldyh at gcc dot gnu.org
2022-11-07 11:42 ` cvs-commit at gcc dot gnu.org [this message]
2022-11-07 11:43 ` aldyh 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-107541-4-nHnAWBkiWv@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).