public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110337] New: Wrong code at -O2/s on x86_64-linux-gnu
@ 2023-06-21 14:42 shaohua.li at inf dot ethz.ch
  2023-06-21 22:51 ` [Bug c/110337] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-06-21 14:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110337
           Summary: Wrong code at -O2/s on x86_64-linux-gnu
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This seems to be a recent regression on GCC -O2/s

$ cat a.c
int printf(const char *, ...);
int a, e;
static short b = 3, f;
long c;
char d;
short g() {
  e = a;
  for (; a != 4;)
    return 39570 + d + b;
  return 0;
}
int main() {
  int h;
  f = g();
  int i = f;
  h = i < 0 ? i : i >> 14;
  c = b && h;
  printf("%d\n", (int)c);
}
$
$ gcc-tk -O0 a.c && ./a.out
1
$ gcc-tk -O2 a.c && ./a.out
-1
$

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

* [Bug c/110337] Wrong code at -O2/s on x86_64-linux-gnu
  2023-06-21 14:42 [Bug c/110337] New: Wrong code at -O2/s on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
@ 2023-06-21 22:51 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-21 22:51 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 110252.
  if (i_9 >= 0)
    goto <bb 3>; [59.00%]
  else
    goto <bb 4>; [41.00%]
;;    succ:       3 [59.0% (guessed)]  count:633507680 (estimated locally)
(TRUE_VALUE,EXECUTABLE)
;;                4 [41.0% (guessed)]  count:440234144 (estimated locally)
(FALSE_VALUE,EXECUTABLE)

;;   basic block 3, loop depth 0, count 633507681 (estimated locally)
;;    prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED)
;;    pred:       2 [59.0% (guessed)]  count:633507680 (estimated locally)
(TRUE_VALUE,EXECUTABLE)
  # RANGE [irange] int [0, 1] NONZERO 0x1
  iftmp.6_10 = i_9 >> 14;
;;    succ:       4 [always]  count:633507681 (estimated locally)
(FALLTHRU,EXECUTABLE)

;;   basic block 4, loop depth 0, count 1073741824 (estimated locally), maybe
hot
;;    prev block 3, next block 1, flags: (NEW, REACHABLE, VISITED)
;;    pred:       3 [always]  count:633507681 (estimated locally)
(FALLTHRU,EXECUTABLE)
;;                2 [41.0% (guessed)]  count:440234144 (estimated locally)
(FALSE_VALUE,EXECUTABLE)

        i_9 >= 0 ? iftmp.6_10 : 1
Matching expression match.pd:1990, gimple-match-5.cc:23
Matching expression match.pd:1990, gimple-match-5.cc:23
Applying pattern match.pd:5283, gimple-match-4.cc:870
Applying pattern match.pd:1378, gimple-match-3.cc:7714
Applying pattern match.pd:1885, gimple-match-9.cc:1391
Applying pattern match.pd:4745, gimple-match-2.cc:16250
Folded into the sequence:
_4 = i_9 >= 0;
_2 = (int) _4;
_8 = i_9 < 0;
_13 = (int) _8;
_14 = iftmp.6_10 | _13;


The problem is i_9 >> 14 is only [0,1] iff inside the condition.

*** This bug has been marked as a duplicate of bug 110252 ***

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

end of thread, other threads:[~2023-06-21 22:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21 14:42 [Bug c/110337] New: Wrong code at -O2/s on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
2023-06-21 22:51 ` [Bug c/110337] " pinskia at gcc dot gnu.org

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