From 4eb4a256cd4a39555f4d834c47cabc2e136ed02a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 17 Oct 2014 12:50:16 +0200 Subject: [PATCH] re PR tree-optimization/63302 (Code with 64-bit long long constants is miscompiled on 32-bit host) PR tree-optimization/63302 * tree-ssa-reassoc.c (optimize_range_tests_xor, optimize_range_tests_diff): Use !integer_pow2p () instead of tree_log2 () < 0. * gcc.c-torture/execute/pr63302.c: New test. From-SVN: r216391 --- gcc/ChangeLog | 7 +++ gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/gcc.c-torture/execute/pr63302.c | 60 +++++++++++++++++++ gcc/tree-ssa-reassoc.c | 4 +- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr63302.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c3167864c1b..d8d9bcd9702 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2014-10-17 Jakub Jelinek + + PR tree-optimization/63302 + * tree-ssa-reassoc.c (optimize_range_tests_xor, + optimize_range_tests_diff): Use !integer_pow2p () instead of + tree_log2 () < 0. + 2014-10-17 Martin Liska * ipa-icf.c (sem_function::merge): Local flags are set to false diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 218cb5628cf..0cc62217943 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-17 Jakub Jelinek + + PR tree-optimization/63302 + * gcc.c-torture/execute/pr63302.c: New test. + 2014-10-17 Tom de Vries PR rtl-optimization/61605 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr63302.c b/gcc/testsuite/gcc.c-torture/execute/pr63302.c new file mode 100644 index 00000000000..99670241bb3 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr63302.c @@ -0,0 +1,60 @@ +/* PR tree-optimization/63302 */ + +#ifdef __SIZEOF_INT128__ +#if __SIZEOF_INT128__ * __CHAR_BIT__ == 128 +#define USE_INT128 +#endif +#endif +#if __SIZEOF_LONG_LONG__ * __CHAR_BIT__ == 64 +#define USE_LLONG +#endif + +#ifdef USE_INT128 +__attribute__((noinline, noclone)) int +foo (__int128 x) +{ + __int128 v = x & (((__int128) -1 << 63) | 0x7ff); + + return v == 0 || v == ((__int128) -1 << 63); +} +#endif + +#ifdef USE_LLONG +__attribute__((noinline, noclone)) int +bar (long long x) +{ + long long v = x & (((long long) -1 << 31) | 0x7ff); + + return v == 0 || v == ((long long) -1 << 31); +} +#endif + +int +main () +{ +#ifdef USE_INT128 + if (foo (0) != 1 + || foo (1) != 0 + || foo (0x800) != 1 + || foo (0x801) != 0 + || foo ((__int128) 1 << 63) != 0 + || foo ((__int128) -1 << 63) != 1 + || foo (((__int128) -1 << 63) | 1) != 0 + || foo (((__int128) -1 << 63) | 0x800) != 1 + || foo (((__int128) -1 << 63) | 0x801) != 0) + __builtin_abort (); +#endif +#ifdef USE_LLONG + if (bar (0) != 1 + || bar (1) != 0 + || bar (0x800) != 1 + || bar (0x801) != 0 + || bar (1LL << 31) != 0 + || bar (-1LL << 31) != 1 + || bar ((-1LL << 31) | 1) != 0 + || bar ((-1LL << 31) | 0x800) != 1 + || bar ((-1LL << 31) | 0x801) != 0) + __builtin_abort (); +#endif + return 0; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 4714a389eb3..ac33f75e89b 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -2200,7 +2200,7 @@ optimize_range_tests_xor (enum tree_code opcode, tree type, lowxor = fold_binary (BIT_XOR_EXPR, type, lowi, lowj); if (lowxor == NULL_TREE || TREE_CODE (lowxor) != INTEGER_CST) return false; - if (tree_log2 (lowxor) < 0) + if (!integer_pow2p (lowxor)) return false; highxor = fold_binary (BIT_XOR_EXPR, type, highi, highj); if (!tree_int_cst_equal (lowxor, highxor)) @@ -2247,7 +2247,7 @@ optimize_range_tests_diff (enum tree_code opcode, tree type, tem1 = fold_binary (MINUS_EXPR, type, lowj, lowi); if (tem1 == NULL_TREE || TREE_CODE (tem1) != INTEGER_CST) return false; - if (tree_log2 (tem1) < 0) + if (!integer_pow2p (tem1)) return false; type = unsigned_type_for (type); -- 2.30.2