[Bug c/87123] New: incorrect optimization involving INT_MIN and conditional operator

2018-08-28 Thread andy.koppe at analog dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87123

Bug ID: 87123
   Summary: incorrect optimization involving INT_MIN and
conditional operator
   Product: gcc
   Version: 7.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: andy.koppe at analog dot com
  Target Milestone: ---

Reproduced using gcc 5.4.0 on Ubuntu 16.04, gcc 7.3.0 on Cygwin64, and also a
gcc 7.2.1 for ARM:

$ cat test.c
#include 
int x = 0x8000;
int main(void)
{
  unsigned y = (unsigned)(x < 0 ? -x : x) >> 8;
  if (y == 0x80)
printf("Test passed\n");
  else
printf("Test failed: y = %#x, expected 0x80\n", y);
}
$ gcc -O2 test.c
$ ./a.out
Test failed: y = 0x80, expected 0x80

Looking at the generated assembly, the "Test passed" path has been optimized
out. The test passes below -O2, or if "(x < 0 ? -x : x)" is replaced with just
"-x".

[Bug c/87123] incorrect optimization involving INT_MIN and conditional operator

2018-08-28 Thread andy.koppe at analog dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87123

--- Comment #2 from Andy Koppe  ---
You are right. The test passes when casting to unsigned before negation.

[Bug c/87123] incorrect optimization involving INT_MIN and conditional operator

2018-08-28 Thread andy.koppe at analog dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87123

--- Comment #6 from Andy Koppe  ---
Thanks, consider me duly embarrased.

[Bug c/102711] New: Infinite loop with extern calls removed with -O2 or higher

2021-10-12 Thread andy.koppe at analog dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102711

Bug ID: 102711
   Summary: Infinite loop with extern calls removed with -O2 or
higher
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: andy.koppe at analog dot com
  Target Milestone: ---

Created attachment 51591
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51591&action=edit
Minimized example

Compiling the minimised example below (and attached) with -O2 or higher, if
FAIL is defined, the second infinite loop is removed. Code is produced for it
when FAIL is not defined.

Reproduced with gcc 10.3.1 for aarch64-none-elf, gcc 11.2.0 for
x86_64-pc-cygwin, and gcc 9.3.0 for x86_64-linux-gnu.

$ cat test.c
int bar(void);

void foo(void)
{
  if (!bar())
for (;;);

  for (;;) {
static int flag = 0;
int ret = 0;
bar();
if (flag) {
  ret = bar();
  if (!ret)
ret = bar();
}
flag = !bar();
#ifdef FAIL
if (!ret)
#endif
  bar();
  }
}

$ aarch64-none-elf-gcc -O2 -S test.c -DFAIL

$ cat test.s
.arch armv8-a
.file   "test.c"
.text
.align  2
.p2align 4,,11
.global foo
.type   foo, %function
foo:
stp x29, x30, [sp, -16]!
mov x29, sp
bl  bar
.L2:
b   .L2
.size   foo, .-foo
.ident  "GCC: (GNU Toolchain for the A-profile Architecture
10.3-2021.07 (arm-10.29)) 10.3.1 20210621"