[backport from gcc-4.7.3 r191802 ] gcc/ 2012-09-27 Jakub Jelinek PR target/54703 * simplify-rtx.c (simplify_binary_operation_1): Perform (x - (x & y)) -> (x & ~y) optimization only for integral modes. gcc/testsuite/ 2012-09-27 Jakub Jelinek PR target/54703 * gcc.target/i386/pr54703.c: New test. --- gcc-4.6.3/gcc/simplify-rtx.c.~1~ 2011-12-23 10:16:08.000000000 +0100 +++ gcc-4.6.3/gcc/simplify-rtx.c 2012-09-29 16:46:10.000000000 +0200 @@ -2099,7 +2099,7 @@ simplify_binary_operation_1 (enum rtx_co neg_const_int (mode, op1)); /* (x - (x & y)) -> (x & ~y) */ - if (GET_CODE (op1) == AND) + if (INTEGRAL_MODE_P (mode) && GET_CODE (op1) == AND) { if (rtx_equal_p (op0, XEXP (op1, 0))) { --- gcc-4.6.3/gcc/testsuite/gcc.target/i386/pr54703.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.6.3/gcc/testsuite/gcc.target/i386/pr54703.c 2012-09-29 16:46:10.000000000 +0200 @@ -0,0 +1,36 @@ +/* PR target/54703 */ +/* { dg-do run { target sse2_runtime } } */ +/* { dg-options "-O -msse2" } */ +/* { dg-options "-O -msse2 -mavx -mtune=bdver1" { target avx_runtime } } */ + +extern void abort (void); +typedef double V __attribute__((vector_size(16))); + +union { + unsigned long long m[2]; + V v; +} u = { { 0xffffffffff000000ULL, 0xffffffffff000000ULL } }; + +static inline V +foo (V x) +{ + V y = __builtin_ia32_andpd (x, u.v); + V z = __builtin_ia32_subpd (x, y); + return __builtin_ia32_mulpd (y, z); +} + +void +test (V *x) +{ + V a = { 2.1, 2.1 }; + *x = foo (foo (a)); +} + +int +main () +{ + test (&u.v); + if (u.m[0] != 0x3acbf487f0a30550ULL || u.m[1] != u.m[0]) + abort (); + return 0; +}