From patchwork Thu Dec 1 15:07:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9456351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A09B60585 for ; Thu, 1 Dec 2016 15:07:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5B9284EA for ; Thu, 1 Dec 2016 15:07:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51702284EC; Thu, 1 Dec 2016 15:07:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE456284F1 for ; Thu, 1 Dec 2016 15:07:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932836AbcLAPHY (ORCPT ); Thu, 1 Dec 2016 10:07:24 -0500 Received: from mail-wj0-f196.google.com ([209.85.210.196]:35855 "EHLO mail-wj0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932322AbcLAPHX (ORCPT ); Thu, 1 Dec 2016 10:07:23 -0500 Received: by mail-wj0-f196.google.com with SMTP id jb2so26719867wjb.3 for ; Thu, 01 Dec 2016 07:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IyEa/XDIQ429PD9Ur9Jn3a/aa9xxFpuv2Aw39JFJnwU=; b=aZiUFzA5Fj/6HnWSiVMD0g8v9vqsqj4Q0Q6eF1wjGHX69gNddm6yY2Pr4bhuA1dBDJ 0VdAI230/PQj/b0pe2JjW8z3fz5L4JFoJzBss8Lq4dVRluCK0tIpDkdJRewGK9Y2pvkG I7kI5gvEeVMvGieBg7VFBUAMO1PqObbtsrkzOAYfV+Oc13iaKfYN077semYB9WmPX5Qe cwJXEWCv7TVYYA1Ioo0NjNgTaW8N2B9SzHf8xt7OV3ppaLJeynL9ms3jnndtehshrGxD z8CG4lBNwyuxWFPM5w+9k6erUr1wSW2yXIw+VOFHkfsAb2KrT1ZcEI4rny6utgfVE/pf 9lTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IyEa/XDIQ429PD9Ur9Jn3a/aa9xxFpuv2Aw39JFJnwU=; b=TBYm0n941/HkdzDGa4qv8eDFIt4pkFEdj6ZTqbvimcY8eD3WxqmVozPl/grsH1z5qg clyyFdVdjYD1XR9Xsbv0AC7jBBD1DLo835/p2AT8KAkAjPRFNRgZvbE1+gViHB2il8Rj JNp9a1H0VV/73pAklCo+GNuepvffqQku7f8M+mkQSseUeVQwL6zMCkiiujKJ/4p+1AQq MuL/slFVd5r/1mjCYQKikDW67pE9HpOTNuUgm3E7xYtOhQnRJWmspgIKbsmYfWV0c0xc spS+Zil/n0uxDOPit4GWU+JUX3oU115TXPKfxz5OYbQ7Ud0125Vu17TdkY7Rjv3kxlQ1 eXzg== X-Gm-Message-State: AKaTC01yS0hyQ/gI+2maWicWEGZfyPEq+de3gC9mTyp0ASXFO7FHZjM7sKxDwfa/fOPSJg== X-Received: by 10.194.222.169 with SMTP id qn9mr33634510wjc.62.1480604841773; Thu, 01 Dec 2016 07:07:21 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:8c1:fd00:d92:cbe2:6224:4294]) by smtp.gmail.com with ESMTPSA id f76sm1337234wmd.15.2016.12.01.07.07.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Dec 2016 07:07:21 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 3/5] unssa: try to avoid some OP_PHI copies Date: Thu, 1 Dec 2016 16:07:03 +0100 Message-Id: <20161201150705.31590-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161201150705.31590-1-luc.vanoostenryck@gmail.com> References: <20161201150705.31590-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP OP_PHI's target can interfer with it's own source swhen defined in the same basic block. Such interference can create problem like the 'swap problem' (which only exist if the phi-node are 'processed' sequentially if they're processed in parallel such problems don't exist) when phi-nodes are destructed. To avoid such problems OP_PHI are rewritten as OP_COPY. if an OP_PHI and it's OP_PHISOURCE are in different basic blocks no such interference is possible and the copy is not needed. This patch detect such situation and eliminate these unneeded copies. Signed-off-by: Luc Van Oostenryck --- unssa.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/unssa.c b/unssa.c index 2660e94c..397130e3 100644 --- a/unssa.c +++ b/unssa.c @@ -30,6 +30,32 @@ #include +static int simplify_phi_node(struct instruction *phi, pseudo_t tmp) +{ + pseudo_t target = phi->target; + struct pseudo_user *pu; + pseudo_t src; + + // verify if this phi can be simplified + FOR_EACH_PTR(phi->phi_list, src) { + struct instruction *def = src->def; + + if (!def) + continue; + if (def->bb == phi->bb) + return 0; + } END_FOR_EACH_PTR(src); + + // no need to make a copy of this one + // -> replace the target pseudo by the tmp + FOR_EACH_PTR(target->users, pu) { + use_pseudo(pu->insn, tmp, pu->userp); + } END_FOR_EACH_PTR(pu); + + kill_instruction(phi); + return 1; +} + static void replace_phi_node(struct instruction *phi) { pseudo_t tmp; @@ -40,6 +66,9 @@ static void replace_phi_node(struct instruction *phi) tmp->ident = phi->target->ident; tmp->def = NULL; // defined by all the phisrc + // can we avoid to make of copy? + simplify_phi_node(phi, tmp); + // rewrite all it's phi_src to copy to a new tmp FOR_EACH_PTR(phi->phi_list, p) { struct instruction *def = p->def; @@ -53,6 +82,9 @@ static void replace_phi_node(struct instruction *phi) def->target = tmp; } END_FOR_EACH_PTR(p); + if (!phi->bb) + return; + // rewrite the phi node: // phi %rt, ... // to: