From: Jakub Jelinek Date: Tue, 18 Dec 2007 00:13:29 +0000 (+0100) Subject: re PR rtl-optimization/34490 (r128833 causes miscompilation of glibc clock_gettime.c) X-Git-Tag: releases/gcc-4.3.0~918 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc7c279e97760bba05fa4d637d5652f8559eab3a;p=thirdparty%2Fgcc.git re PR rtl-optimization/34490 (r128833 causes miscompilation of glibc clock_gettime.c) PR rtl-optimization/34490 * simplify-rtx.c (simplify_const_relational_operation): If !sign, don't reduce mmin/mmax using num_sign_bit_copies. * gcc.c-torture/execute/20071216-1.c: New test. From-SVN: r131023 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c71729dc02c3..c3595a4dc61f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2007-12-18 Jakub Jelinek + + PR rtl-optimization/34490 + * simplify-rtx.c (simplify_const_relational_operation): If !sign, + don't reduce mmin/mmax using num_sign_bit_copies. + 2007-12-17 Kaveh R. Ghazi * doc/install.texi: Change recommended MPFR from 2.2.1 > 2.3.0. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 0371339d5405..fd14e407dc84 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -4233,15 +4233,17 @@ simplify_const_relational_operation (enum rtx_code code, else { rtx mmin_rtx, mmax_rtx; - unsigned int sign_copies = num_sign_bit_copies (trueop0, mode); get_mode_bounds (mode, sign, mode, &mmin_rtx, &mmax_rtx); - /* Since unsigned mmin will never be interpreted as negative, use - INTVAL (and an arithmetic right shift). */ - mmin = INTVAL (mmin_rtx) >> (sign_copies - 1); - /* Since signed mmax will always be positive, use UINTVAL (and - a logical right shift). */ - mmax = UINTVAL (mmax_rtx) >> (sign_copies - 1); + mmin = INTVAL (mmin_rtx); + mmax = INTVAL (mmax_rtx); + if (sign) + { + unsigned int sign_copies = num_sign_bit_copies (trueop0, mode); + + mmin >>= (sign_copies - 1); + mmax >>= (sign_copies - 1); + } } switch (code) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1650e37b85c0..d42c3345884b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-12-18 Jakub Jelinek + + PR rtl-optimization/34490 + * gcc.c-torture/execute/20071216-1.c: New test. + 2007-12-17 Kaveh R. Ghazi * gcc.dg/torture/builtin-math-4.c: Remove XFAIL. diff --git a/gcc/testsuite/gcc.c-torture/execute/20071216-1.c b/gcc/testsuite/gcc.c-torture/execute/20071216-1.c new file mode 100644 index 000000000000..a337b773af8f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20071216-1.c @@ -0,0 +1,38 @@ +/* PR rtl-optimization/34490 */ + +extern void abort (void); + +static int x; + +int +__attribute__((noinline)) +bar (void) +{ + return x; +} + +int +foo (void) +{ + long int b = bar (); + if ((unsigned long) b < -4095L) + return b; + if (-b != 38) + b = -2; + return b + 1; +} + +int +main (void) +{ + x = 26; + if (foo () != 26) + abort (); + x = -39; + if (foo () != -1) + abort (); + x = -38; + if (foo () != -37) + abort (); + return 0; +}