From patchwork Thu Apr 13 16:55:48 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: 9679739 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 4191D60381 for ; Thu, 13 Apr 2017 16:56:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3275C2869B for ; Thu, 13 Apr 2017 16:56:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27629286A7; Thu, 13 Apr 2017 16:56:07 +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 AE0FD2869B for ; Thu, 13 Apr 2017 16:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753395AbdDMQ4F (ORCPT ); Thu, 13 Apr 2017 12:56:05 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35601 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754073AbdDMQ4E (ORCPT ); Thu, 13 Apr 2017 12:56:04 -0400 Received: by mail-wm0-f68.google.com with SMTP id d79so13692668wmi.2 for ; Thu, 13 Apr 2017 09:56:03 -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=qLLPILJc4RP8/qgUfCwUZFl36N7m8E+HS8vMEwq4e3M=; b=CzUHDI8dVi2Et2a0fQuUcAKTlprx4VIS17KXYIfjPz3NrapR2L3eveolw6/PMYTlvq cYEj/Rg5Q4Rky7iQY4m6ppc9SOHhi942Y8talXX8ep8zVsZB/apvZ5ZQC0gQh0KOaiRL bljsEaaDaiqwvDJMO/B4IK16r2ReQCq4aRT7C8of5DLfqL2r4bxeoTeUOen7oCWsEPR8 zJ6WATA5sf5iTNa5u90KD7kQAtLk4qV+0J8vqwYIzwvzeWZwe3jToREYvC7RyQP4xLTF ZpUjBaNqOlLfKlXsrBM9y3WiC8arW7EDtguN8+9P+a/AH1WWUbfTJlCncSshwDdE/oY0 MlIg== 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=qLLPILJc4RP8/qgUfCwUZFl36N7m8E+HS8vMEwq4e3M=; b=YOdCMSO6OtC98OmxdLZHlBRIvMbqbpLWfmQ6ttalvVQo1yENYZ2rSUXGDKTAJa0koj D5mSiyNsifkC6bhIHVj4xY2IHPpbCyyB8M/vgnH7uNr5wrM0+h3fgS7KX3KXaomS3FiK 2/+Qp7LpyPsmo+pOldCw9aoXbV/PTK8/fPIOhPZKtzGf1SfjcAEDQUvI8ktPY1FHh3xR Bo8ke9PG2pQY4NN8Artwe5UEIEdk+iUl9GkwkTNGu8ge2pHBEerMLrGvN9Wl2/Dd9IvP H4kIfMpU7s8RTDOq4jDW7TtmlDr70C9c0nNTE+aij+l0mfInYHv0NzB/V6MvIbY/RwMg pyrg== X-Gm-Message-State: AN3rC/4t46WNOSv5pdfpR2zSSRS9F9jio4q/E5zWBOoUhTjwVt+ncZuQ 9+SxOnYrCmvqCEc68mE= X-Received: by 10.28.14.138 with SMTP id 132mr4210616wmo.141.1492102562392; Thu, 13 Apr 2017 09:56:02 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:8b2:dc00:a909:829c:fd:bc60]) by smtp.gmail.com with ESMTPSA id q129sm13297803wmg.1.2017.04.13.09.56.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Apr 2017 09:56:01 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH 5/8] avoid phisrc orphaned by find_dominating_stores() Date: Thu, 13 Apr 2017 18:55:48 +0200 Message-Id: <20170413165551.2785-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170413165551.2785-1-luc.vanoostenryck@gmail.com> References: <20170413165551.2785-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 Note: this is the dual of the preceding patch, only for stores instead of loads. find_dominating_stores() call find_dominating_parents() which can add an OP_PHISRC in each BB it visits and the corresponding %phi are collected in a list. Then, depending on the returned value, an OP_PHI is created with this list as phi_list. However, it could that because of the returned value, no such OP_PHI is created and thus the newly created OP_PHISRC stay there but are of no use. It seems also (but I can't strictly confirm this) that this can sometimes happen at each CSE-simplification cycle, creating one more such OP_PHISRC at each cycle, into each concerned BB. Not good. Change this by not creating these OP_PHISRC but instead just collecting their source pseudo. And then only created them together with the corresponding OP_PHI, or simply discarding the list, depending on the returned value. The situation can clearly be seen with the following code: extern void abort(void); extern int bar; int foo(void) { if (bar) abort(); return bar; } which was linearized as: foo: load.32 %r1 <- 0[bar] > phisrc.32 %phi2(bar) <- %r1 cbr %r1, .L1, .L2 .L1: call abort br .L2 .L2: load.32 %r2 <- 0[bar] ret.32 %r2 and is now linearized as: foo: load.32 %r1 <- 0[bar] cbr %r1, .L1, .L2 .L1: call abort br .L2 .L2: load.32 %r2 <- 0[bar] ret.32 %r2 Signed-off-by: Luc Van Oostenryck --- flow.c | 20 +++++++++++--------- validation/linear/phisrc-orphan-st.c | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 validation/linear/phisrc-orphan-st.c diff --git a/flow.c b/flow.c index aa7a6586f..678f9ba86 100644 --- a/flow.c +++ b/flow.c @@ -352,19 +352,19 @@ int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom return 1; } -static int phisrc_in_bb(struct pseudo_list *list, struct basic_block *bb) +static int phisrc_in_bb(struct instruction_list *list, struct basic_block *bb) { - pseudo_t p; - FOR_EACH_PTR(list, p) { - if (p->def->bb == bb) + struct instruction *def; + FOR_EACH_PTR(list, def) { + if (def->bb == bb) return 1; - } END_FOR_EACH_PTR(p); + } END_FOR_EACH_PTR(def); return 0; } static int find_dominating_parents(pseudo_t pseudo, struct instruction *insn, - struct basic_block *bb, unsigned long generation, struct pseudo_list **dominators, + struct basic_block *bb, unsigned long generation, struct instruction_list **dominators, int local) { struct basic_block *parent; @@ -401,7 +401,7 @@ no_dominance: found_dominator: if (dominators && phisrc_in_bb(*dominators, parent)) continue; - add_dominator(dominators, insn, one, pseudo->ident); + add_instruction(dominators, one); } END_FOR_EACH_PTR(parent); return 1; } @@ -472,7 +472,8 @@ static int find_dominating_stores(pseudo_t pseudo, struct instruction *insn, { struct basic_block *bb = insn->bb; struct instruction *one, *dom = NULL; - struct pseudo_list *dominators; + struct instruction_list *dominators; + struct pseudo_list *phi_list; int partial; /* Unreachable load? Undo it */ @@ -534,7 +535,8 @@ found: * have to turn the load into a phi-node of the * dominators. */ - rewrite_load_instruction(insn, dominators); + phi_list = add_load_dominators(insn, dominators, pseudo->ident); + rewrite_load_instruction(insn, phi_list); return 1; } diff --git a/validation/linear/phisrc-orphan-st.c b/validation/linear/phisrc-orphan-st.c new file mode 100644 index 000000000..e5b3a3a46 --- /dev/null +++ b/validation/linear/phisrc-orphan-st.c @@ -0,0 +1,17 @@ +extern void abort(void); +extern int bar; + +int foo(void) +{ + if (bar) + abort(); + return bar; +} + +/* + * check-name: phisrc orphaned (stores) + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: phisrc + */