diff options
author | Jakub Jelinek <jakub@redhat.com> | 2014-10-17 12:50:16 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2014-10-17 12:50:16 +0200 |
commit | 4eb4a256cd4a39555f4d834c47cabc2e136ed02a (patch) | |
tree | 57d50dcdf67827495420438304dc1e393caa452f /gcc | |
parent | 9d4ded759a1367ebe6588be36d0ea1410e24e3ca (diff) | |
download | gcc-4eb4a256cd4a39555f4d834c47cabc2e136ed02a.zip gcc-4eb4a256cd4a39555f4d834c47cabc2e136ed02a.tar.gz gcc-4eb4a256cd4a39555f4d834c47cabc2e136ed02a.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr63302.c | 60 | ||||
-rw-r--r-- | gcc/tree-ssa-reassoc.c | 4 |
4 files changed, 74 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c316786..d8d9bcd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2014-10-17 Jakub Jelinek <jakub@redhat.com> + + 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 <mliska@suse.cz> * ipa-icf.c (sem_function::merge): Local flags are set to false diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 218cb56..0cc6221 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-17 Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/63302 + * gcc.c-torture/execute/pr63302.c: New test. + 2014-10-17 Tom de Vries <tom@codesourcery.com> 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 0000000..9967024 --- /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 4714a38..ac33f75 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); |