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
This commit is contained in:
Jakub Jelinek 2014-10-17 12:50:16 +02:00 committed by Jakub Jelinek
parent 9d4ded759a
commit 4eb4a256cd
4 changed files with 74 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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);