From: Jakub Jelinek Date: Mon, 8 Jul 2013 08:11:08 +0000 (+0200) Subject: re PR rtl-optimization/57829 (Wrong constant folding) X-Git-Tag: releases/gcc-4.9.0~5093 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=046f1eeec356d116ef3dcfc512d0ef8085efc8bf;p=thirdparty%2Fgcc.git re PR rtl-optimization/57829 (Wrong constant folding) PR rtl-optimization/57829 * simplify-rtx.c (simplify_binary_operation_1) : Ensure that mask bits outside of mode are just sign-extension from mode to HWI. * gcc.c-torture/execute/pr57829.c: New test. From-SVN: r200768 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6ece60c2148b..e4fc901528c5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2013-07-08 Jakub Jelinek + + PR rtl-optimization/57829 + * simplify-rtx.c (simplify_binary_operation_1) : Ensure that + mask bits outside of mode are just sign-extension from mode to HWI. + 2013-07-08 Michael Zolotukhin * config/i386/i386-opts.h (enum stringop_alg): Add vector_loop. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 9bb31e76ed98..be54db8f5d03 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2818,6 +2818,7 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode, HOST_WIDE_INT mask = INTVAL (trueop1) << count; if (mask >> count == INTVAL (trueop1) + && trunc_int_for_mode (mask, mode) == mask && (mask & nonzero_bits (XEXP (op0, 0), mode)) == 0) return simplify_gen_binary (ASHIFTRT, mode, plus_constant (mode, XEXP (op0, 0), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c0a3b599d8ec..f4d0b6faf966 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-07-08 Jakub Jelinek + + PR rtl-optimization/57829 + * gcc.c-torture/execute/pr57829.c: New test. + 2013-07-08 Michael Zolotukhin * gcc.target/i386/memcpy-vector_loop-1.c: New. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr57829.c b/gcc/testsuite/gcc.c-torture/execute/pr57829.c new file mode 100644 index 000000000000..b5c3d185d0a9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr57829.c @@ -0,0 +1,31 @@ +/* PR rtl-optimization/57829 */ + +__attribute__((noinline, noclone)) +int +f1 (int k) +{ + return 2 | ((k - 1) >> ((int) sizeof (int) * __CHAR_BIT__ - 1)); +} + +__attribute__((noinline, noclone)) +long int +f2 (long int k) +{ + return 2L | ((k - 1L) >> ((int) sizeof (long int) * __CHAR_BIT__ - 1)); +} + +__attribute__((noinline, noclone)) +int +f3 (int k) +{ + k &= 63; + return 4 | ((k + 2) >> 5); +} + +int +main () +{ + if (f1 (1) != 2 || f2 (1L) != 2L || f3 (63) != 6 || f3 (1) != 4) + __builtin_abort (); + return 0; +}