I get failures when building and testing MPFR with: gcc (Debian 20141209-1) 5.0.0 20141209 (experimental) [trunk revision 218514] on x86_64, using: ./configure --enable-assert=full CC=gcc-snapshot 'CFLAGS=-Wall -O2 -g' Using -O1 only makes the problems disappear. If I simplify the MPFR code to: int mpfr_set_si_2exp (mpfr_ptr x, long i, mpfr_exp_t e, mpfr_rnd_t rnd_mode) { if (i == 0) { return 0; } else { unsigned long ai; ai = i >= 0 ? (unsigned long) i : - (unsigned long) i; if ((i >= 0 ? (unsigned long) i : - (unsigned long) i) != ai) printf ("Error!\n"); printf ("i = %ld\n", i); printf ("ai = %lX\n", ai); return 0; } } in set_si_2exp.c, and call: mpfr_set_si_2exp (x, 1, 0, 0); I get: i = 1 ai = FFFFFFFFFFFFFFFF If I remove the if ((i >= 0 ? (unsigned long) i : - (unsigned long) i) != ai) printf ("Error!\n"); test, I get: i = 1 ai = 1 as expected. I don't know why, but I didn't manage to get a standalone testcase.
Without the standalone test case we can't do much, unfortunately. Would you have at least the preprocessed source?
Created attachment 34242 [details] testcase part 1 (tst1.c)
Created attachment 34243 [details] testcase part 2 (tst2.c)
(In reply to Marek Polacek from comment #1) > Without the standalone test case we can't do much, unfortunately. Would you > have at least the preprocessed source? It was actually a standalone test case, but one needs separate compilation to run it: $ gcc-snapshot -Wall -Wextra -O2 -c tst1.c $ gcc-snapshot -Wall -Wextra -O2 -c tst2.c $ gcc-snapshot tst1.o tst2.o -o tst $ ./tst i = 1 ai = FFFFFFFFFFFFFFFF
Confirmed. Testcase can be combined to one file: markus@x4 tmp % cat test.c #include <stdio.h> __attribute__((noinline)) int f (long i) { if (i == 0) { return 0; } else { unsigned long ai; ai = i >= 0 ? (unsigned long) i : - (unsigned long) i; if ((i >= 0 ? (unsigned long) i : - (unsigned long) i) != ai) printf ("Error!\n"); printf ("i = %ld\n", i); printf ("ai = %lX\n", ai); return 0; } } int main (void) { f (1); return 0; }
A better version: void __attribute__ ((noinline, noclone)) bar (long int i) { asm (""); } int __attribute__ ((noinline, noclone)) f (long i) { if (i == 0) return 0; else { unsigned long ai = i >= 0 ? (unsigned long) i : -(unsigned long) i; if ((i >= 0 ? (unsigned long) i : -(unsigned long) i) != ai) bar (0); bar (i); return ai; } } int main (void) { if (f (1) != 1) __builtin_abort (); }
-fno-if-conversion seems to help.
I had: __attribute__((noinline, noclone)) void bar (long i, unsigned long j) { if (i != 1 || j != 1) __builtin_abort (); } __attribute__((noinline, noclone)) void foo (long i) { unsigned long j; if (!i) return; j = i >= 0 ? (unsigned long) i : - (unsigned long) i; if ((i >= 0 ? (unsigned long) i : - (unsigned long) i) != j) __builtin_abort (); bar (i, j); } int main () { foo (1); return 0; } In any case, regressed with r217646, works with -O0/-O1, or -O2 -m32, fails with -O2 (on x86_64-linux).
(In reply to Marek Polacek from comment #7) > -fno-if-conversion seems to help. Then this is most likely a Dup of another bug which has a few version of a patch posted now.
(In reply to Andrew Pinski from comment #9) > (In reply to Marek Polacek from comment #7) > > -fno-if-conversion seems to help. > > Then this is most likely a Dup of another bug which has a few version of a > patch posted now. PR63917?
(In reply to Markus Trippelsdorf from comment #10) > > Then this is most likely a Dup of another bug which has a few version of a > > patch posted now. > > PR63917? yes.
Fixed by r218658.
Author: jakub Date: Fri Dec 12 12:43:34 2014 New Revision: 218665 URL: https://gcc.gnu.org/viewcvs?rev=218665&root=gcc&view=rev Log: PR rtl-optimization/64255 * gcc.c-torture/execute/pr64255.c: New test. PR rtl-optimization/64260 * gcc.c-torture/execute/pr64260.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr64255.c trunk/gcc/testsuite/gcc.c-torture/execute/pr64260.c Modified: trunk/gcc/testsuite/ChangeLog