From patchwork Thu Apr 13 16:55:47 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: 9679737 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 8ABB860381 for ; Thu, 13 Apr 2017 16:56:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CF732869B for ; Thu, 13 Apr 2017 16:56:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71934286A7; Thu, 13 Apr 2017 16:56:05 +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 0AC612869B for ; Thu, 13 Apr 2017 16:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754049AbdDMQ4E (ORCPT ); Thu, 13 Apr 2017 12:56:04 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33407 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754032AbdDMQ4D (ORCPT ); Thu, 13 Apr 2017 12:56:03 -0400 Received: by mail-wr0-f196.google.com with SMTP id l28so9400371wre.0 for ; Thu, 13 Apr 2017 09:56:02 -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=jUix89fqLmsRYoQEFOduAkmx+OVVh2/UXAaxhJZVMXY=; b=KnPjgB0scQm5N57hnPWl8Y0qNh9j7yjM5DkFxE2MRCoCSochn6XFNxh4r9cv0+Gm35 y05MlSRl3ZVvmwJUsQ7zRkisJFwP4kZht6gsQ5kFFM2k/+oMRLBHmPlGhy+WDXirApuq QHWRqAGPL/BC4ebug9pAv0ArnZ7Psy9YDc1eOiOY6OGgQiCjhk8iCwVhw0yiCAz7Y3ra 0kJzV6lpDcVBrdbwH8HV2S/Hi6DvKX3q/+33ctNrYDuRgieCH4IWwkd+zOVP2hvPsKle ghu7Xhh8l+4uErzZTu+DKIU4ynaHUZRzyGralkJJRyJrYSlto6AiTCwqXKjYvNH9Z1ZG nPeg== 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=jUix89fqLmsRYoQEFOduAkmx+OVVh2/UXAaxhJZVMXY=; b=JU3QYtROv2xS2F7C2dp7nweCrkCZU/AiK/iU7KThKV5x+IQ8RNG9PO8XpP3d+v1p5m oNLo7qScaQpk5AdgK1Ks0xNYDVUQ4DCtiVZqvzj40QXsKAEBj7vEMu+MmrMLdJ9ruiX4 CikAdI0BRnGSua239/PCBP4IHKwdpQCANLXJQwB5H6NZbCODVxhsYhi/zfe/FLXhaMAX svm4p0+kV0qoZpjVzEERBy+TvnYbiXR3hbZmkr9sRXkMSUOtRmjtDZhzsYyK3LC/Yy8c e983YcoyW4nRWOQu1O4GVI6ysRTyvcu/0dSv3/7wypd/1S0ufWYtNrqa/gBoYX1/GUry HmMw== X-Gm-Message-State: AN3rC/6e4Gu+OOuwRX9EYkp7HTziHL+Q/evBqWosxWDKqEbzwtQpsc4/ 0CX6sKl8gffz+Q== X-Received: by 10.223.148.97 with SMTP id 88mr3999105wrq.174.1492102561443; Thu, 13 Apr 2017 09:56:01 -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.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Apr 2017 09:56:00 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH 4/8] avoid phisrc orphaned by simplify_loads() Date: Thu, 13 Apr 2017 18:55:47 +0200 Message-Id: <20170413165551.2785-5-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 simplify_loads() calls 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 find_dominating_parents()'s returned value, either an OP_PHI is created with this list as phi_list, or no such OP_PHI is created and the phi_list is discarded. In the later case, the added OP_PHISRCs are of no use but are left there nevertheless. These orphaned OP_PHISRCs can only bring confusion later. 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: struct s { void *x, *z; }; extern void use(struct s *); void *foo(struct s *s) { if (s->x == s->z) use(s); return s->x; } which was linearized as: foo: load.64 %r2 <- 0[%arg1] load.64 %r4 <- 8[%arg1] seteq.32 %r5 <- %r4, %r2 -> phisrc.64 %phi2 <- %r2 -> phisrc.64 %phi3 <- %r2 cbr %r5, .L1, .L2 .L1: push.64 %arg1 call use br .L2 .L2: load.64 %r8 <- 0[%arg1] ret.64 %r8 and is now simply linearized as: foo: load.64 %r2 <- 0[%arg1] load.64 %r4 <- 8[%arg1] seteq.32 %r5 <- %r4, %r2 cbr %r5, .L1, .L2 .L1: push.64 %arg1 call use br .L2 .L2: load.64 %r8 <- 0[%arg1] ret.64 %r8 Note: this situation seems to have existed since a long time but have been made worse by the patch: (5636cd5cb "missing load simplification") Fixes: 5636cd5cbf816f30ee57d580ec4debd8e0bd7581 Signed-off-by: Luc Van Oostenryck --- memops.c | 10 ++++++---- validation/linear/phisrc-orphan-ld.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 validation/linear/phisrc-orphan-ld.c diff --git a/memops.c b/memops.c index ac43b6a0a..39469e260 100644 --- a/memops.c +++ b/memops.c @@ -17,7 +17,7 @@ #include "flow.h" 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; @@ -49,7 +49,7 @@ no_dominance: continue; found_dominator: - add_dominator(dominators, insn, one, NULL); + add_instruction(dominators, one); } END_FOR_EACH_PTR(parent); return 1; } @@ -83,7 +83,7 @@ static void simplify_loads(struct basic_block *bb) struct instruction *dom; pseudo_t pseudo = insn->src; int local = local_pseudo(pseudo); - struct pseudo_list *dominators; + struct instruction_list *dominators; unsigned long generation; /* Check for illegal offsets.. */ @@ -115,6 +115,7 @@ static void simplify_loads(struct basic_block *bb) bb->generation = generation; dominators = NULL; if (find_dominating_parents(pseudo, insn, bb, generation, &dominators, local)) { + struct pseudo_list *phi_list; /* This happens with initial assignments to structures etc.. */ if (!dominators) { if (local) { @@ -123,7 +124,8 @@ static void simplify_loads(struct basic_block *bb) } goto next_load; } - rewrite_load_instruction(insn, dominators); + phi_list = add_load_dominators(insn, dominators, NULL); + rewrite_load_instruction(insn, phi_list); } } next_load: diff --git a/validation/linear/phisrc-orphan-ld.c b/validation/linear/phisrc-orphan-ld.c new file mode 100644 index 000000000..a10aedba6 --- /dev/null +++ b/validation/linear/phisrc-orphan-ld.c @@ -0,0 +1,22 @@ +struct s { + void *x; + void *z; +}; + +extern void use(struct s *); + +void *foo(struct s *s) +{ + if (s->x == s->z) + use(s); + + return s->x; +} + +/* + * check-name: phisrc orphaned (loads) + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: phisrc + */