From 1f89c16b4a91e3d155f1daa4ec473835d83d4b45 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 30 Mar 2016 12:45:39 +0000 Subject: Backported from mainline 2016-03-29 Jakub Jelinek PR rtl-optimization/70429 * combine.c (simplify_shift_const_1): For ASHIFTRT don't optimize (cst1 >> count) >> cst2 into (cst1 >> cst2) >> count if mode != result_mode. * gcc.c-torture/execute/pr70429.c: New test. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-5-branch@234567 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++++ gcc/combine.c | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/execute/pr70429.c | 17 +++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr70429.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b0a3ab652eb..6422560b461 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,13 @@ 2016-03-30 Jakub Jelinek Backported from mainline + 2016-03-29 Jakub Jelinek + + PR rtl-optimization/70429 + * combine.c (simplify_shift_const_1): For ASHIFTRT don't optimize + (cst1 >> count) >> cst2 into (cst1 >> cst2) >> count if + mode != result_mode. + 2016-03-22 Jakub Jelinek PR target/70329 diff --git a/gcc/combine.c b/gcc/combine.c index 912b0eab1f0..16048bf3557 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -10485,6 +10485,11 @@ simplify_shift_const_1 (enum rtx_code code, machine_mode result_mode, >> orig_count, result_mode, &complement_p)) break; + /* For ((int) (cstLL >> count)) >> cst2 just give up. Queuing + up outer sign extension (often left and right shift) is + hardly more efficient than the original. See PR70429. */ + if (code == ASHIFTRT && mode != result_mode) + break; rtx new_rtx = simplify_const_binary_operation (code, mode, XEXP (varop, 0), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a19d0a1df81..e6eaa279d10 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2016-03-30 Jakub Jelinek Backported from mainline + 2016-03-29 Jakub Jelinek + + PR rtl-optimization/70429 + * gcc.c-torture/execute/pr70429.c: New test. + 2016-03-22 Jakub Jelinek PR target/70329 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr70429.c b/gcc/testsuite/gcc.c-torture/execute/pr70429.c new file mode 100644 index 00000000000..6b08c8ead08 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr70429.c @@ -0,0 +1,17 @@ +/* PR rtl-optimization/70429 */ + +__attribute__((noinline, noclone)) int +foo (int a) +{ + return (int) (0x14ff6e2207db5d1fLL >> a) >> 4; +} + +int +main () +{ + if (sizeof (int) != 4 || sizeof (long long) != 8 || __CHAR_BIT__ != 8) + return 0; + if (foo (1) != 0x3edae8 || foo (2) != -132158092) + __builtin_abort (); + return 0; +} -- cgit v1.2.3