From a049ad91707d07af6fe197f6c4336ba35ba0134a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 16 Feb 2010 08:15:37 +0000 Subject: [PATCH] re PR rtl-optimization/41917 (Strange athrithmetic result with -O3) PR rtl-optimization/41917 * rtlanal.c (num_sign_bit_copies1) : If sign bit of second operand isn't known to be 0, return 1. testsuite: * gcc.c-torture/execute/pr41917.c: New test. From-SVN: r156795 --- gcc/ChangeLog | 6 ++++++ gcc/rtlanal.c | 12 +++++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.c-torture/execute/pr41917.c | 21 +++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr41917.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 750cd0b65d20..e1acf6202df9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-02-16 Paolo Bonzini + + PR rtl-optimization/41917 + * rtlanal.c (num_sign_bit_copies1) : If sign bit of second + operand isn't known to be 0, return 1. + 2010-02-04 Richard Guenther PR rtl-optimization/42952 diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c index 060ed9e969ca..0502850cbe10 100644 --- a/gcc/rtlanal.c +++ b/gcc/rtlanal.c @@ -4444,8 +4444,16 @@ num_sign_bit_copies1 (const_rtx x, enum machine_mode mode, const_rtx known_x, known_x, known_mode, known_ret); case UMOD: - /* The result must be <= the second operand. */ - return cached_num_sign_bit_copies (XEXP (x, 1), mode, + /* The result must be <= the second operand. If the second operand + has (or just might have) the high bit set, we know nothing about + the number of sign bit copies. */ + if (bitwidth > HOST_BITS_PER_WIDE_INT) + return 1; + else if ((nonzero_bits (XEXP (x, 1), mode) + & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0) + return 1; + else + return cached_num_sign_bit_copies (XEXP (x, 1), mode, known_x, known_mode, known_ret); case DIV: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3f12af921e0f..82618ad8a290 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-02-16 Paolo Bonzini + + * gcc.c-torture/execute/pr41917.c: New test. + 2010-02-04 Jerry DeLisle PR libfortran/42901 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr41917.c b/gcc/testsuite/gcc.c-torture/execute/pr41917.c new file mode 100644 index 000000000000..4a9ada921c4f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr41917.c @@ -0,0 +1,21 @@ +/* PR rtl-optimization/41917 */ + +extern void abort (void); +unsigned int a = 1; + +int +main (void) +{ + unsigned int b, c, d; + + if (sizeof (int) != 4 || (int) 0xc7d24b5e > 0) + return 0; + + c = 0xc7d24b5e; + d = a | -2; + b = (d == 0) ? c : (c % d); + if (b != c) + abort (); + + return 0; +} -- 2.47.2