This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix simplify_shift_const_1 once more (PR rtl-optimization/70429)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 29 Mar 2016 19:21:29 +0200
- Subject: [PATCH] Fix simplify_shift_const_1 once more (PR rtl-optimization/70429)
- Authentication-results: sourceware.org; auth=none
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
This is a case similar to the LSHIFTRT I've fixed recently.
But, unlike LSHIFTRT, which can be handled by masking at the outer level,
ASHIFTRT would need outer sign extension, so most of the time 2 outer
operations in addition to the kept two inner shifts, which is IMHO very
unlikely to ever be successfully combined on any target nor actually
beneficial. So this patch just avoids that optimization for ASHIFTRT
if there are different modes.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2016-03-29 Jakub Jelinek <jakub@redhat.com>
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.
--- gcc/combine.c.jj 2016-03-15 17:11:17.000000000 +0100
+++ gcc/combine.c 2016-03-29 10:40:11.835477469 +0200
@@ -10533,6 +10533,11 @@ simplify_shift_const_1 (enum rtx_code co
>> orig_count, result_mode,
&complement_p))
break;
+ /* For ((int) (cstLL >> count)) >> cst2 just give up. Queing 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),
--- gcc/testsuite/gcc.c-torture/execute/pr70429.c.jj 2016-03-29 10:42:07.517901546 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr70429.c 2016-03-29 10:41:52.000000000 +0200
@@ -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;
+}
Jakub