public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114937] New: [11 regression] -ftree-vrp optimizes out range check before conditional increment
@ 2024-05-03 13:41 mital at mitalashok dot co.uk
  2024-05-03 13:50 ` [Bug tree-optimization/114937] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mital at mitalashok dot co.uk @ 2024-05-03 13:41 UTC (permalink / raw)
  To: gcc-bugs

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+

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-12 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-03 13:41 [Bug tree-optimization/114937] New: [11 regression] -ftree-vrp optimizes out range check before conditional increment mital at mitalashok dot co.uk
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

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).