From patchwork Wed Nov 6 15:00:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1190511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512612-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="rx43XIYX"; dkim-atps=neutral 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 477VK3060tz9sR3 for ; Thu, 7 Nov 2019 02:07:32 +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=gAO9QLvjt8uu rpdspYBV8+bMXrMX/SX5bmtXTbwJNQwLrR+YbE5aLB6fO452Ue157vD3Zwi8s9LQ QP0jNbOCaOMvAysOmoJnZuYlQFPRzMoMdB2zPTUBWpfIcQoXk9l9xIKFr3yr9dhQ JtUqoWo3mE26PQZj0TsCSobGKZqHP9M= 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=n8PyY9m4sQyaXw783m HrviTd9xM=; b=rx43XIYXbI4DEiMmZeT2g+u9kZ4QoeCD2CTfMbiRvP6UCDcoJZ uENyUTtUxCJS1su4yU4jb+wlep6Xj6Ro3wWNldVvU0PJTgiwsALZbrjRfOv7QBZY j4POSvY/oIVy+LT8B+Ww4stOnqNQFT6E99ZGLp4eiK0wGjJ1Id9o3OxU8= Received: (qmail 98530 invoked by alias); 6 Nov 2019 15:00:47 -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 98196 invoked by uid 89); 6 Nov 2019 15:00:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=LEU, gtu, LTU, uneq 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; Wed, 06 Nov 2019 15:00:24 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 2C5AA1240898; Wed, 6 Nov 2019 15:00:21 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH] simplify-rtx: simplify_logical_relational_operation Date: Wed, 6 Nov 2019 15:00:19 +0000 Message-Id: <41f35fcfc6a223396c9183019e981a302192576d.1573051916.git.segher@kernel.crashing.org> X-IsSubscribed: yes This introduces simplify_logical_relational_operation. Currently the only thing implemented it can simplify is the IOR of two CONDs of the same arguments. Tested on powerpc64-linux {-m32,-m64}. Is this okay for trunk? Segher 2018-11-06 Segher Boessenkool * simplify-rtx.c (comparison_to_mask): New function. (mask_to_comparison): New function. (simplify_logical_relational_operation): New function. (simplify_binary_operation_1): Call simplify_logical_relational_operation. --- gcc/simplify-rtx.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 9a70720..b2ba922 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2125,6 +2125,132 @@ simplify_associative_operation (enum rtx_code code, machine_mode mode, return 0; } +/* Return a mask describing the COMPARISON. */ +static int +comparison_to_mask (enum rtx_code comparison) +{ + switch (comparison) + { + case LT: + return 8; + case GT: + return 4; + case EQ: + return 2; + case UNORDERED: + return 1; + + case LTGT: + return 12; + case LE: + return 10; + case GE: + return 6; + case UNLT: + return 9; + case UNGT: + return 5; + case UNEQ: + return 3; + + case ORDERED: + return 14; + case NE: + return 13; + case UNLE: + return 11; + case UNGE: + return 7; + + default: + gcc_unreachable (); + } +} + +/* Return a comparison corresponding to the MASK. */ +static enum rtx_code +mask_to_comparison (int mask) +{ + switch (mask) + { + case 8: + return LT; + case 4: + return GT; + case 2: + return EQ; + case 1: + return UNORDERED; + + case 12: + return LTGT; + case 10: + return LE; + case 6: + return GE; + case 9: + return UNLT; + case 5: + return UNGT; + case 3: + return UNEQ; + + case 14: + return ORDERED; + case 13: + return NE; + case 11: + return UNLE; + case 7: + return UNGE; + + default: + gcc_unreachable (); + } +} + +/* Simplify a logical operation CODE with result mode MODE, operating on OP0 + and OP1, which should be both relational operations. Return 0 if no such + simplification is possible. */ +rtx +simplify_logical_relational_operation (enum rtx_code code, machine_mode mode, + rtx op0, rtx op1) +{ + /* We only handle IOR of two relational operations. */ + if (code != IOR) + return 0; + + if (!(COMPARISON_P (op0) && COMPARISON_P (op1))) + return 0; + + if (!(rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0)) + && rtx_equal_p (XEXP (op0, 1), XEXP (op1, 1)))) + return 0; + + enum rtx_code code0 = GET_CODE (op0); + enum rtx_code code1 = GET_CODE (op1); + + /* We don't handle unsigned comparisons currently. */ + if (code0 == LTU || code0 == GTU || code0 == LEU || code0 == GEU) + return 0; + if (code1 == LTU || code1 == GTU || code1 == LEU || code1 == GEU) + return 0; + + int mask0 = comparison_to_mask (code0); + int mask1 = comparison_to_mask (code1); + + int mask = mask0 | mask1; + + if (mask == 15) + return const_true_rtx; + + code = mask_to_comparison (mask); + + op0 = XEXP (op1, 0); + op1 = XEXP (op1, 1); + + return simplify_gen_relational (code, mode, VOIDmode, op0, op1); +} /* Simplify a binary operation CODE with result mode MODE, operating on OP0 and OP1. Return 0 if no simplification is possible. @@ -2888,6 +3014,10 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, tem = simplify_associative_operation (code, mode, op0, op1); if (tem) return tem; + + tem = simplify_logical_relational_operation (code, mode, op0, op1); + if (tem) + return tem; break; case XOR: