public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Do not simplify "(and (reg) (const bit))" to if_then_else.
@ 2016-10-31 19:56 Dominik Vogt
  2016-11-07 15:57 ` [PING, PATCH] " Dominik Vogt
  2016-11-07 20:29 ` [PATCH] " Bernd Schmidt
  0 siblings, 2 replies; 18+ messages in thread
From: Dominik Vogt @ 2016-10-31 19:56 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andreas Krebbel, Ulrich Weigand

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

The attached patch does a little change in
combine.c:combine_simplify_rtx() to prevent a "simplification"
where the rtl code gets more complex in reality.  The complete
description of the change can be found in the commit comment in
the attached patch.

The patch reduces the number of patterns in the s390 backend and
slightly reduces the size of the compiled SPEC2006 code.  (Code
size or runtime only tested on s390x with -m64.)  It is
theoretically possible that this patch leads to somewhat worse
code on some target if that only has a pattern for the formerly replaced
rtl expression but not for the original one.

The patch has passed the testsuite on s390, s390x biarch, x86_64
and Power biarch.

--

(I'm not sure whether the const_int expression can appear in both
operands or only as the second.  If the latter is the case, the
conditions can be simplified a bit.)

What do you think about this patch?

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0001-ChangeLog --]
[-- Type: text/plain, Size: 125 bytes --]

gcc/ChangeLog

	* combine.c (if_then_else_cond): Suppress replacement of
	"(and (reg) (const_int bit))" with "if_then_else".

[-- Attachment #3: 0001-Do-not-simplify-and-reg-const-bit-to-if_then_else.patch --]
[-- Type: text/plain, Size: 2145 bytes --]

From bfa15721c760fa4cd9003050c3137cba3165139f Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Mon, 31 Oct 2016 09:00:31 +0100
Subject: [PATCH] Do not simplify "(and (reg) (const bit))" to if_then_else.

combine_simplify_rtx() tries to replace rtx expressions with just two
possible values with an experession that uses if_then_else:

  (if_then_else (condition) (value1) (value2))

If the original expression is e.g.

  (and (reg) (const_int 2))

where the constant is the mask for a single bit, the replacement results
in a more complex expression than before:

  (if_then_else (ne (zero_extract (reg) (1) (31))) (2) (0))

Similar replacements are done for

  (signextend (and ...))
  (zeroextend (and ...))

Suppress the replacement this special case in if_then_else_cond().
---
 gcc/combine.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/combine.c b/gcc/combine.c
index b22a274..244669d 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -9103,9 +9103,25 @@ if_then_else_cond (rtx x, rtx *ptrue, rtx *pfalse)
       return x;
     }
 
-  /* Likewise for 0 or a single bit.  */
+  /* Likewise for 0 or a single bit.
+     If the operation is an AND (possibly wrapped in a SIGN_EXTEND or
+     ZERO_EXTEND) with either operand being just a constant single bit value,
+     do nothing since IF_THEN_ELSE is likely to increase the expression's
+     complexity.  */
   else if (HWI_COMPUTABLE_MODE_P (mode)
-	   && pow2p_hwi (nz = nonzero_bits (x, mode)))
+	   && pow2p_hwi (nz = nonzero_bits (x, mode))
+	   && ! (code == AND
+		 && ((CONST_INT_P (XEXP (x, 0))
+		      && UINTVAL (XEXP (x, 0)) == nz)
+		     || (CONST_INT_P (XEXP (x, 1))
+			 && UINTVAL (XEXP (x, 1)) == nz)))
+	   && ! ((code == SIGN_EXTEND || code == ZERO_EXTEND)
+		 && GET_CODE (XEXP (x, 0)) == AND
+		 && ((CONST_INT_P (XEXP (XEXP (x, 0), 0))
+		      && UINTVAL (XEXP (XEXP (x, 0), 0)) == nz)
+		     || (CONST_INT_P (XEXP (XEXP (x, 0), 1))
+			 && UINTVAL (XEXP (XEXP (x, 0), 1)) == nz)))
+	  )
     {
       *ptrue = gen_int_mode (nz, mode), *pfalse = const0_rtx;
       return x;
-- 
2.3.0


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

end of thread, other threads:[~2016-12-05 14:00 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-31 19:56 [PATCH] Do not simplify "(and (reg) (const bit))" to if_then_else Dominik Vogt
2016-11-07 15:57 ` [PING, PATCH] " Dominik Vogt
2016-11-07 20:29 ` [PATCH] " Bernd Schmidt
2016-11-11 11:10   ` Dominik Vogt
2016-11-21 12:36     ` Dominik Vogt
2016-12-01 12:19       ` [PING] " Dominik Vogt
2016-12-01 12:33       ` [PATCH] " Bernd Schmidt
2016-12-01 15:30         ` [PATCH v3] " Dominik Vogt
2016-12-02  8:36           ` Andreas Krebbel
2016-12-03 16:35           ` Andreas Schwab
2016-12-04  1:19           ` Segher Boessenkool
2016-12-05  9:22             ` Dominik Vogt
2016-12-05 10:01               ` Segher Boessenkool
2016-12-05 10:50                 ` Dominik Vogt
2016-12-05 13:31                 ` Oleg Endo
2016-12-05 13:57               ` Segher Boessenkool
2016-12-05 14:00                 ` Dominik Vogt
2016-12-01 23:49       ` [PATCH] " Jeff Law

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).