public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mital at mitalashok dot co.uk" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/114937] New: [11 regression] -ftree-vrp optimizes out range check before conditional increment
Date: Fri, 03 May 2024 13:41:31 +0000	[thread overview]
Message-ID: <bug-114937-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114937
           Summary: [11 regression] -ftree-vrp optimizes out range check
                    before conditional increment
           Product: gcc
           Version: 11.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mital at mitalashok dot co.uk
  Target Milestone: ---

https://godbolt.org/z/fdMGWa4nq

    int f(int x) {
      const int y = x;
      if (x != INT_MAX) {
        ++x;
      }

      return (x > y) ? x : 0;
    }

    int z = INT_MAX;
    int main(void) {
        // Prints INT_MIN when it should print 0
        __builtin_printf("%d\n", f(z));
    }

`f` is miscompiled at `-O1 -ftree-vrp` (also `-O2`) in GCC10/11 to return `x+1`
unconditionally.  
The same happens with `if (x != INT_MIN) --x; return (x < y) ? x : 0;`.

This does not happen in GCC9 or GCC12+

             reply	other threads:[~2024-05-03 13:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 13:41 mital at mitalashok dot co.uk [this message]
2024-05-03 13:50 ` [Bug tree-optimization/114937] " rguenth at gcc dot gnu.org
2024-05-03 13:54 ` rguenth at gcc dot gnu.org
2024-05-03 14:21 ` mital at mitalashok dot co.uk
2024-05-06 10:50 ` rguenth at gcc dot gnu.org
2024-05-12 10:35 ` mikpelinux at gmail dot com

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-114937-4@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).