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
gcc/ChangeLog * combine.c (if_then_else_cond): Suppress replacement of "(and (reg) (const_int bit))" with "if_then_else".
>From bfa15721c760fa4cd9003050c3137cba3165139f Mon Sep 17 00:00:00 2001 From: Dominik Vogt <v...@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