[Bug target/83133] Superflous x86 test instructions in generated assembly.

ubizjak at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Nov 24 16:43:00 GMT 2017


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

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Maxim Egorushkin from comment #2)

> Could you provide an example where that "dangerous optimization" would break
> well-formed code please?

--cut here--
#include <stdio.h>

void positive (int a) { printf ("positive: %i\n", a); }
void nonpositive (int a) { printf ("nonpositive: %i\n", a); }

void
__attribute__((noinline))
g (int a, int b)
{
  int diff = a - b;

  if (diff > 0)
    return positive (diff);
  else
    return nonpositive (diff);
}

int
main ()
{
  int a = -0x80000000;
  int b = 0x01;

  g (a, b);

  return 0;
}
--cut here--

$ gcc -O2 ttt.c
$ ./a.out
positive: 2147483647

$ gcc -O0 ttt.c
$ ./a.out
positive: 2147483647

$ clang -O2 ttt.c
$ ./a.out
nonpositive: 2147483647          <--------- HERE!

$ clang -O0 ttt.c
$ ./a.out
positive: 2147483647


More information about the Gcc-bugs mailing list