From: Jakub Jelinek Date: Mon, 18 Oct 2010 10:08:47 +0000 (+0200) Subject: re PR middle-end/46019 (x / (0x200000000ULL << y) miscompilation with 32-bit HWI) X-Git-Tag: releases/gcc-4.4.6~308 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cac8db81e3a7dc06e8384dd3c3f82805e15ddff;p=thirdparty%2Fgcc.git re PR middle-end/46019 (x / (0x200000000ULL << y) miscompilation with 32-bit HWI) PR middle-end/46019 * fold-const.c (fold_binary_loc): If integer_pow2p has TREE_INT_CST_LOW zero, look at TREE_INT_CST_HIGH. * gcc.c-torture/execute/pr46019.c: New test. From-SVN: r165621 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 63fdea3f3f26..aff534d49fde 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-10-18 Jakub Jelinek + + PR middle-end/46019 + * fold-const.c (fold_binary_loc): If integer_pow2p has + TREE_INT_CST_LOW zero, look at TREE_INT_CST_HIGH. + 2010-10-07 John David Anglin PR target/45820 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 4d5e70d4b268..5c549c589bc4 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -11658,7 +11658,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) if (integer_pow2p (sval) && tree_int_cst_sgn (sval) > 0) { tree sh_cnt = TREE_OPERAND (arg1, 1); - unsigned long pow2 = exact_log2 (TREE_INT_CST_LOW (sval)); + unsigned long pow2; + + if (TREE_INT_CST_LOW (sval)) + pow2 = exact_log2 (TREE_INT_CST_LOW (sval)); + else + pow2 = exact_log2 (TREE_INT_CST_HIGH (sval)) + + HOST_BITS_PER_WIDE_INT; if (strict_overflow_p) fold_overflow_warning (("assuming signed overflow does not " diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0f41aa67bbe6..dae7bfcca655 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-10-18 Jakub Jelinek + + PR middle-end/46019 + * gcc.c-torture/execute/pr46019.c: New test. + 2010-10-16 John David Anglin Backport from mainline diff --git a/gcc/testsuite/gcc.c-torture/execute/pr46019.c b/gcc/testsuite/gcc.c-torture/execute/pr46019.c new file mode 100644 index 000000000000..b0365576ac85 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr46019.c @@ -0,0 +1,14 @@ +/* PR middle-end/46019 */ + +extern void abort (void); + +int +main (void) +{ + unsigned long long l = 0x40000000000ULL; + int n; + for (n = 0; n < 8; n++) + if (l / (0x200000000ULL << n) != (0x200 >> n)) + abort (); + return 0; +}