From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 39994 invoked by alias); 9 Nov 2015 07:33:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 39974 invoked by uid 89); 9 Nov 2015 07:33:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Nov 2015 07:33:29 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id EF4BF1C072E; Mon, 9 Nov 2015 07:33:25 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: dje.gcc@gmail.com, Segher Boessenkool Subject: [PATCH 1/2] simplify-rtx: Simplify trunc of and of shiftrt Date: Mon, 09 Nov 2015 07:33:00 -0000 Message-Id: <1d3e9ff999e20e4eb13a5825ac084074bd05a397.1447053652.git.segher@kernel.crashing.org> X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg00900.txt.bz2 If we have (truncate:M1 (and:M2 (lshiftrt:M2 (x:M2) C) C2)) we can write it instead as (and:M1 (lshiftrt:M1 (truncate:M1 (x:M2)) C) C2) (if that is valid, of course), which has smaller modes for the binary ops, and the truncate can often simplify further (if "x" is a register, for example). This fixes gcc.target/powerpc/20050603-3.c for -m32 -mpowerpc64; also that test is currently restricted to ilp32, but we can run it with lp64 just fine, in which case it fixes that, too. Bootstrapped and tested on powerpc64-linux (-m32,-m32/-mpowerpc64,-m64). Is this okay for trunk? Segher 2015-11-09 Segher Boessenkool * gcc/simplify-rtx.c (simplify_truncation): Simplify TRUNCATE of AND of [LA]SHIFTRT. --- gcc/simplify-rtx.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 17568ba..1adb393 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -714,6 +714,31 @@ simplify_truncation (machine_mode mode, rtx op, return simplify_gen_binary (ASHIFT, mode, XEXP (XEXP (op, 0), 0), XEXP (op, 1)); + /* Likewise (truncate:QI (and:SI (lshiftrt:SI (x:SI) C) C2)) into + (and:QI (lshiftrt:QI (truncate:QI (x:SI)) C) C2) for suitable C + and C2. */ + if (GET_CODE (op) == AND + && (GET_CODE (XEXP (op, 0)) == LSHIFTRT + || GET_CODE (XEXP (op, 0)) == ASHIFTRT) + && CONST_INT_P (XEXP (XEXP (op, 0), 1)) + && CONST_INT_P (XEXP (op, 1)) + && UINTVAL (XEXP (XEXP (op, 0), 1)) < precision + && ((GET_MODE_MASK (mode) >> UINTVAL (XEXP (XEXP (op, 0), 1))) + & UINTVAL (XEXP (op, 1))) + == ((GET_MODE_MASK (op_mode) >> UINTVAL (XEXP (XEXP (op, 0), 1))) + & UINTVAL (XEXP (op, 1)))) + { + rtx op0 = simplify_gen_unary (TRUNCATE, mode, XEXP (XEXP (op, 0), 0), + op_mode); + if (op0) + { + op0 = simplify_gen_binary (LSHIFTRT, mode, op0, + XEXP (XEXP (op, 0), 1)); + if (op0) + return simplify_gen_binary (AND, mode, op0, XEXP (op, 1)); + } + } + /* Recognize a word extraction from a multi-word subreg. */ if ((GET_CODE (op) == LSHIFTRT || GET_CODE (op) == ASHIFTRT) -- 1.9.3