From patchwork Mon Jul 31 20:36:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9873111 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 AFC5F6037D for ; Mon, 31 Jul 2017 20:36:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D1AC27F3E for ; Mon, 31 Jul 2017 20:36:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 922A3285DC; Mon, 31 Jul 2017 20:36:39 +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 3A05C27F3E for ; Mon, 31 Jul 2017 20:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751176AbdGaUgi (ORCPT ); Mon, 31 Jul 2017 16:36:38 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36314 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751046AbdGaUgh (ORCPT ); Mon, 31 Jul 2017 16:36:37 -0400 Received: by mail-wr0-f195.google.com with SMTP id y67so31687037wrb.3 for ; Mon, 31 Jul 2017 13:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pn034L95kD4vfRzRmMSP/UxjlLVYPokW/z8DEx6+MrI=; b=vYQOUo8fVTs6aEUP69HTyEwG1/TA0THKEbcCOA5SnUdkET618Mxnla4iQk9d3DtGSd q5v1PFbtltsz1Z6Krfj3HEzreRQUIit4iMa7YG3NBcoxEJRtzX8wtS2ON+MHJ6Q/j+sP mUyxZGohnMr2uScziWZDCgqdMNHiZyl2oRC7ZPY/C9LqPT0csFtVzuUFqAiRxISq+Sum XkAAuLV8uDGelOUtOJKXUM0nqkxtJersfvMj5uETs6ZB54qd+QLYgt94uYF86pn/hLL/ MrDtSh3iP5uqb218k+p/md71nvfbIPOIkmllp5mrowxOH8pk2R5x5i12urFkDRtlK2Cj DeQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pn034L95kD4vfRzRmMSP/UxjlLVYPokW/z8DEx6+MrI=; b=kBBV5seVi6nGkJIXoySuF4FhxuQzCOTsfmflM24WZijdiNN7NQs99GRje9IPaxeV7e fhR2mHQKRb3n1TH3muLqCx9rHn4vzvc4Cv8jk/aK9IUcfiTpSsq3dCIi/NBElSkL5XiU 7BegVn1ySLQRsoVCJccTKzGdv6EjNTvnfRHO6fe8xMOlqOAJGp1IkGoy6a6FIfr5OGpu ssEJlmgjR3JhcSjZ0X6vP86f+jed31zU1KvPxkqhKzmKYmZI5PbB4Pf9t7przsE3m7vs lRhHz+/cX07lAABsC/4LdqkZHDciKxMZ7bkObSzEfcF9mQKtBCl8pfqXyljDBp8dj5vL cU2g== X-Gm-Message-State: AIVw11038Jupdq0PP82EDoqXmkRazz4Rz9Q2ep2oHAg5g8QthhYT8REd YQPkORubBCznVQ== X-Received: by 10.223.145.163 with SMTP id 32mr15177345wri.224.1501533395862; Mon, 31 Jul 2017 13:36:35 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:40c4:ab00:f976:d678:e4f6:5c60]) by smtp.gmail.com with ESMTPSA id n7sm47682350wrb.37.2017.07.31.13.36.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Jul 2017 13:36:35 -0700 (PDT) From: Luc Van Oostenryck To: Christopher Li Cc: linux-sparse@vger.kernel.org, Michael Stefaniuc , Luc Van Oostenryck Subject: [PATCH v3 3/7] fix BB dependencies on phi-nodes Date: Mon, 31 Jul 2017 22:36:20 +0200 Message-Id: <20170731203624.58971-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170731203624.58971-1-luc.vanoostenryck@gmail.com> References: <20170731203624.58971-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 Simplification of BBs (via try_to_siplify_bb() or simplify_branch_branch()) can only be done under some conditions: - the removed/bypassed BB is free of side-effects - the removed/bypassed BB doesn't define some pseudos needed later. This last check is efficiently done by bb_depends_on() using liveness info. However, there is no liveness done on OP_PHI thus the dependencies involving OP_PHI are missing, resulting in illegal simplifications. Fix this by explicitly adding the missing dependencies. Supersedes: 852801f8b966407544326cd1c485f9bc7681a2e6 Signed-off-by: Luc Van Oostenryck --- flow.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/flow.c b/flow.c index 536bf257f..23fa7c21b 100644 --- a/flow.c +++ b/flow.c @@ -81,26 +81,23 @@ static int bb_depends_on(struct basic_block *target, struct basic_block *src) } /* - * This is only to be used by try_to_simplify_bb(). - * It really should be handled by bb_depends_on(), only - * that there is no liveness done on OP_PHI/OP_PHISRC. - * So we consider for now that if there is an OP_PHI - * then some block in fact depends on this one. - * The OP_PHI controling the conditional branch of this bb - * is excluded since the branch will be removed. + * This really should be handled by bb_depends_on() + * which efficiently check the dependence using the + * defines - needs liveness info. Problem is that + * there is no liveness done on OP_PHI & OP_PHISRC. + * + * This function add the missing dependency checks. */ -static int bb_defines_phi(struct basic_block *bb, struct instruction *def) +static int bb_depends_on_phi(struct basic_block *target, struct basic_block *src) { struct instruction *insn; - FOR_EACH_PTR(bb->insns, insn) { - switch (insn->opcode) { - case OP_PHI: - if (def && insn != def) - return 1; + FOR_EACH_PTR(src->insns, insn) { + if (!insn->bb) continue; - default: + if (insn->opcode != OP_PHI) continue; - } + if (pseudo_in_list(target->needs, insn->target)) + return 1; } END_FOR_EACH_PTR(insn); return 0; } @@ -153,7 +150,7 @@ static int try_to_simplify_bb(struct basic_block *bb, struct instruction *first, target = true ? second->bb_true : second->bb_false; if (bb_depends_on(target, bb)) continue; - if (bb_defines_phi(bb, first)) + if (bb_depends_on_phi(target, bb)) continue; changed |= rewrite_branch(source, &br->bb_true, bb, target); changed |= rewrite_branch(source, &br->bb_false, bb, target); @@ -224,6 +221,8 @@ static int simplify_branch_branch(struct basic_block *bb, struct instruction *br goto try_to_rewrite_target; if (bb_depends_on(final, target)) goto try_to_rewrite_target; + if (bb_depends_on_phi(final, target)) + return 0; return rewrite_branch(bb, target_p, target, final); try_to_rewrite_target: