public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][combine] PR rtl-optimization/68381: Only restrict pure simplification in mult-extend subst case, allow other substitutions
@ 2015-11-19 10:26 Kyrill Tkachov
  2015-11-19 10:57 ` Segher Boessenkool
  2015-11-26 13:32 ` Segher Boessenkool
  0 siblings, 2 replies; 10+ messages in thread
From: Kyrill Tkachov @ 2015-11-19 10:26 UTC (permalink / raw)
  To: GCC Patches; +Cc: Segher Boessenkool

[-- Attachment #1: Type: text/plain, Size: 1060 bytes --]

Hi all,

In this PR we end up removing a widening multiplication. I suspect it's some path in combine
that doesn't handle the case where we return clobber of 0 properly. This started with my recent
combine patch r230326.
Changing the subst hunk from that patch to just return x when handling a no-op substitution
fixes the testcase for me and doesn't regress the widening-mult cases that r230326 improved.
In fact, with this patch I'm seeing improved codegen for aarch64 with some widening multiplications
combined with constant operands and ending up in bitfield move/insert instructions.

Bootstrapped and tested on aarch64, arm, x86_64.

Ok for trunk?

Thanks,
Kyrill

2015-11-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

     PR rtl-optimization/68381
     * combine.c (subst): Do not return clobber of zero in widening mult
     case.  Just return x unchanged if it is a no-op substitution.

2015-11-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

     PR rtl-optimization/68381
     * gcc.c-torture/execute/pr68381.c: New test.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: combine-fix.patch --]
[-- Type: text/x-patch; name=combine-fix.patch, Size: 2011 bytes --]

commit 58ec17169da2bb864d2bcaeb34a33e8c5a93348f
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date:   Tue Nov 17 15:33:58 2015 +0000

    [combine] PR rtl-optimization/68381: Only restrict pure simplification in mult-extend subst case, allow other substitutions

diff --git a/gcc/combine.c b/gcc/combine.c
index 26b14bf..3791abf 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -5286,7 +5286,7 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy)
 	      || GET_CODE (SET_DEST (x)) == PC))
 	fmt = "ie";
 
-      /* Substituting into the operands of a widening MULT is not likely
+      /* Trying to simplify the operands of a widening MULT is not likely
 	 to create RTL matching a machine insn.  */
       if (code == MULT
 	  && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
@@ -5294,13 +5294,10 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy)
 	  && (GET_CODE (XEXP (x, 1)) == ZERO_EXTEND
 	      || GET_CODE (XEXP (x, 1)) == SIGN_EXTEND)
 	  && REG_P (XEXP (XEXP (x, 0), 0))
-	  && REG_P (XEXP (XEXP (x, 1), 0)))
-	{
-	  if (from == to)
-	    return x;
-	  else
-	    return gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
-	}
+	  && REG_P (XEXP (XEXP (x, 1), 0))
+	  && from == to)
+	return x;
+
 
       /* Get the mode of operand 0 in case X is now a SIGN_EXTEND of a
 	 constant.  */
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68381.c b/gcc/testsuite/gcc.c-torture/execute/pr68381.c
new file mode 100644
index 0000000..33012a3
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr68381.c
@@ -0,0 +1,22 @@
+/* { dg-options "-fexpensive-optimizations -fno-tree-bit-ccp" } */
+
+__attribute__ ((noinline, noclone))
+int
+foo (unsigned short x, unsigned short y)
+{
+  int r;
+  if (__builtin_mul_overflow (x, y, &r))
+    __builtin_abort ();
+  return r;
+}
+
+int
+main (void)
+{
+  int x = 1;
+  int y = 2;
+  if (foo (x, y) != x * y)
+    __builtin_abort ();
+  return 0;
+}
+

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-11-26 13:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-19 10:26 [PATCH][combine] PR rtl-optimization/68381: Only restrict pure simplification in mult-extend subst case, allow other substitutions Kyrill Tkachov
2015-11-19 10:57 ` Segher Boessenkool
2015-11-19 13:39   ` Kyrill Tkachov
2015-11-19 14:41     ` Segher Boessenkool
2015-11-19 15:00       ` Kyrill Tkachov
2015-11-19 15:20         ` Kyrill Tkachov
2015-11-24  0:40           ` Segher Boessenkool
2015-11-26  9:55             ` Kyrill Tkachov
2015-11-26 13:02               ` Segher Boessenkool
2015-11-26 13:32 ` Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).