From patchwork Wed Dec 24 17:05:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 423975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 380751400DD for ; Thu, 25 Dec 2014 04:05:31 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=CI9KD6N0B4LJ ZUht9mpC0BcQ7THaRNrfSIdMMTB0jeZK3y3bgrPd+iMJkcXAIA+BbkIPBnOACnCB ynEZXdA5+gkf8AwlNdaFUndhapCUt/4wFiJe/7BAYeT9xwADeLCwFQJJf0kMmYSf 2jwwz5ppCYTUSZIhUvoxoe0zn0u9i8s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=jZBI6VGaabKNjLdVdJ LpauDBPBI=; b=FHKmKgTmspK62kNfzTqjfxuzWaKOLjSm6Isat1HGB21ARTOc7R OHzpiWVOsv74WHMUYFi7ldq6AqwHY20IWG+lE7yOyRWx8di2nEuVteMhfE1riSUu oC3ycIkzwnTuTG1pWKo7hoiiPSDDXHERqBQjjC+yNSx0aH4ToDeA5zq8s= Received: (qmail 30141 invoked by alias); 24 Dec 2014 17:05:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 30128 invoked by uid 89); 24 Dec 2014 17:05:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD autolearn=ham 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 24 Dec 2014 17:05:22 +0000 Received: from gcc1-power7.osuosl.org (localhost [127.0.0.1]) by gcc1-power7.osuosl.org (8.14.6/8.14.6) with ESMTP id sBOH5Ka2063222; Wed, 24 Dec 2014 09:05:20 -0800 Received: (from segher@localhost) by gcc1-power7.osuosl.org (8.14.6/8.14.6/Submit) id sBOH5Kn1063219; Wed, 24 Dec 2014 09:05:20 -0800 From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH] simplify-rtx: Generalize (and X (ior (not X) Y) -> (and X Y) Date: Wed, 24 Dec 2014 09:05:17 -0800 Message-Id: <704e01715eeb6663365be6b169d6792b4622b1bb.1419439883.git.segher@kernel.crashing.org> X-IsSubscribed: yes The existing transform (and X (ior (not X) Y) -> (and X Y) has two shortcomings: it only handles identical RTX for X, i.e. registers, not e.g. subregs of registers; and it only handles the case where the NOT is the first arm of the IOR (it can be the second arm e.g. if the first arm is a NOT as well). Fix both. This fixes gcc.dg/and-1.c on powerpc64. Bootstrapped and tested on powerpc64-linux; okay for mainline? Segher 2014-12-24 Segher Boessenkool gcc/ * simplify-rtx.c (simplify_binary_operation_1): Handle more cases for the "(and X (ior (not X) Y) -> (and X Y)" transform. --- gcc/simplify-rtx.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 277288a..ae0b49d 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2933,15 +2933,27 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, /* (and X (ior (not X) Y) -> (and X Y) */ if (GET_CODE (op1) == IOR && GET_CODE (XEXP (op1, 0)) == NOT - && op0 == XEXP (XEXP (op1, 0), 0)) + && rtx_equal_p (op0, XEXP (XEXP (op1, 0), 0))) return simplify_gen_binary (AND, mode, op0, XEXP (op1, 1)); /* (and (ior (not X) Y) X) -> (and X Y) */ if (GET_CODE (op0) == IOR && GET_CODE (XEXP (op0, 0)) == NOT - && op1 == XEXP (XEXP (op0, 0), 0)) + && rtx_equal_p (op1, XEXP (XEXP (op0, 0), 0))) return simplify_gen_binary (AND, mode, op1, XEXP (op0, 1)); + /* (and X (ior Y (not X)) -> (and X Y) */ + if (GET_CODE (op1) == IOR + && GET_CODE (XEXP (op1, 1)) == NOT + && rtx_equal_p (op0, XEXP (XEXP (op1, 1), 0))) + return simplify_gen_binary (AND, mode, op0, XEXP (op1, 0)); + + /* (and (ior Y (not X)) X) -> (and X Y) */ + if (GET_CODE (op0) == IOR + && GET_CODE (XEXP (op0, 1)) == NOT + && rtx_equal_p (op1, XEXP (XEXP (op0, 1), 0))) + return simplify_gen_binary (AND, mode, op1, XEXP (op0, 0)); + tem = simplify_byte_swapping_operation (code, mode, op0, op1); if (tem) return tem;