From patchwork Sat Nov 16 23:09:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1196224 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-513809-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="MqobAh4t"; 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 47FrXf4qYhz9sPK for ; Sun, 17 Nov 2019 10:10:08 +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=g2+PgEgdNK7S retKVU7pOJN0to+ybzoqHG4eAU47qkQ+5oxxcJx53ycvs/HpQvc0AlZyjiB4z4Zq ojYwhpbI+tYBjT/RoewRiVq6lcmRjdWns30Dg0udAKPleiuqnGRSVGqISzWPxSzq DkoPvRV2ZbBxfOm1UgINHkWD3QGC0W0= 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=YDoCrcM8ME9TbxTEYa qN5EYXe3M=; b=MqobAh4tAh66bNWQjIAjydnbsRz9iC5Dqe+qRm+v/SZsX/Dv5u 513QzOh1AQdAIl5xA4YFNPNJOI7+fIr69QbVsbKAZJF3qMEnEV7Y56k8cWgi+oFR h/NofgiLdzNt8pRtEB/6YmAp9obnhtvK5VGclxivH5+/L5o6+8cjJrjpM= Received: (qmail 82874 invoked by alias); 16 Nov 2019 23:10:01 -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 82863 invoked by uid 89); 16 Nov 2019 23:10:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.9 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=REG_DEAD, *i0, reg_dead 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; Sat, 16 Nov 2019 23:09:59 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 13F7412408C8; Sat, 16 Nov 2019 23:09:57 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH] combine: Don't set the same thing twice in one parallel Date: Sat, 16 Nov 2019 23:09:56 +0000 Message-Id: <3837b7a2706c832a5f406ee2be064b6e67fcec78.1573945436.git.segher@kernel.crashing.org> X-IsSubscribed: yes Instead, make the second arm copy from the dest of the first set. Most of the time this copy will be optimized away later. I am still testing this across many archs; will commit later if that works out well. Segher 2019-11-16 Segher Boessenkool * combine.c (try_combine): If we get a parallel setting the same value to two locations, only set it once and copy that. --- gcc/combine.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gcc/combine.c b/gcc/combine.c index fdfa587..dec3c01 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -4122,6 +4122,22 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, rtx set0 = XVECEXP (newpat, 0, 0); rtx set1 = XVECEXP (newpat, 0, 1); + /* If both set the same value, do it once and copy it; the copy + can usually be optimised away later. */ + if (rtx_equal_p (SET_SRC (set0), SET_SRC (set1)) + && !modified_between_p (SET_SRC (set0), i2, i3) + && !(REG_P (SET_DEST (set0)) + && find_reg_note (i2, REG_DEAD, SET_DEST (set0))) + && !(GET_CODE (SET_DEST (set0)) == SUBREG + && find_reg_note (i2, REG_DEAD, SUBREG_REG (SET_DEST (set0)))) + && !modified_between_p (SET_DEST (set0), i2, i3) + && (!HAVE_cc0 || !reg_referenced_p (cc0_rtx, set1))) + { + newi2pat = set0; + newpat = set1; + SUBST (SET_SRC (newpat), SET_DEST (newi2pat)); + } + else /* Normally, it doesn't matter which of the two is done first, but the one that references cc0 can't be the second, and one which uses any regs/memory set in between i2 and i3 can't