From patchwork Sat Apr 1 10:16:55 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: 9657665 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 57A1360351 for ; Sat, 1 Apr 2017 10:17:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35A0E27317 for ; Sat, 1 Apr 2017 10:17:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 290D028179; Sat, 1 Apr 2017 10:17:06 +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 33FE627317 for ; Sat, 1 Apr 2017 10:17:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751417AbdDAKRD (ORCPT ); Sat, 1 Apr 2017 06:17:03 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33195 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751399AbdDAKRC (ORCPT ); Sat, 1 Apr 2017 06:17:02 -0400 Received: by mail-wm0-f66.google.com with SMTP id o81so3158214wmb.0 for ; Sat, 01 Apr 2017 03:17: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; bh=914ByqWfix7ETsx3XS4JjjceRB66PxArfYO4wVg81/s=; b=c0gdhiASB7MIWxGj3HUdL79jfFddf3uLxj4bX0euhT/G6aNZBBDMH6sf0mhEOeD9+1 r6Vn9N09dgZrHXMiK5xb9Hc14cBtBomnMUgueLD6tK+ZYpfDMEyewJXKI1NogG4QonYE Yj8VTgxU/wwFE8x2QSt5JITqG3JFmoCiIVgXrF8ztyqfMBvK+7d5jzu89jvz93pnKEvC 7q6H24D+uExjH/K0jsDsu7kr5TDhkcN3V2mq+URXym1yvsZPX4bI/Rwuz7xCDjL7JqQi hzxQa9InWARgRrLfyHOSue1HOsawuDuEPEIHAD+nujJgUx95nwNDVKRyaNgBWoQMC6FF UIyQ== 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; bh=914ByqWfix7ETsx3XS4JjjceRB66PxArfYO4wVg81/s=; b=GKcKPLagJT7WqT5jJvUIOnhqxDt7nrJew/smIZJa0wAio+ToLNwtTXDnU+SaVqTM29 wxeBuYKng8kZFvaFiY588ZD1WkZKPXkbub3DV+vaw94CLMLXWtCkuAtd1qzJgUCzlq+c ONguWDmtcMvxbsHkx4IrngaBaf2IRhoT5hUXuwCx6zJF31hLt0UVosKQ3CwjLx9aot5i 9zphia0u2pcbC5hbyIJado/Lgf1x0tTbTL9cB9MGcNrDdCiEBnke4RJecR4+McMiA3qI SIxpG0ROSc6YYsDa6SaBO5Exezmug9f6cxVSTO4QvIsU+A5GYcscnwNKQbuFc5I9ps34 yhpA== X-Gm-Message-State: AFeK/H3Q41Gqlxp2QIWVEWDQ6/GRAnvq3cdqDdmJjR4Ws4JGPlaXjumH W3oS2ZU+IEksnFZg/1M= X-Received: by 10.28.19.6 with SMTP id 6mr1808660wmt.96.1491041820917; Sat, 01 Apr 2017 03:17:00 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:88d:1900:f53c:1d3e:2f68:e05]) by smtp.gmail.com with ESMTPSA id k203sm6187068wmk.4.2017.04.01.03.16.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Apr 2017 03:17:00 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH v2] fix OP_PHI usage in try_to_simplify_bb(), correctly Date: Sat, 1 Apr 2017 12:16:55 +0200 Message-Id: <20170401101655.28237-1-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 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 Patch 11b1a83b1 solved an issue with dangling PSEUDO_PHI by killing it's use after a branch rewrite. However, the change didn't took in account the fact that, even after the branch rewrite, some other paths may exist where this pseudo was needed. Fix this by cheking that no such path exist before killing the (usage of the) pseudo. Fixes: 11b1a83b1 "fix OP_PHI usage in try_to_simplify_bb()" Reported-by: Dibyendu Majumdar Signed-off-by: Luc Van Oostenryck --- Changes since v1: - code cleanup as asked during code review This patch can also be pulled at: git://github.com/lucvoo/sparse.git fix-kill-ttsb-v2 from commit: 97ebb345943918a0688b62cbc9bf878de01ccba4 (sparse-next-2017-03-07) up to commit: 7a0eaa532f289c6a252f30023581f58bae7a446a flow.c | 30 +++++++++++++++++++++++++++++- validation/kill-phi-ttsbb2.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 validation/kill-phi-ttsbb2.c diff --git a/flow.c b/flow.c index a5332203f..ff0b598f0 100644 --- a/flow.c +++ b/flow.c @@ -79,6 +79,34 @@ static int bb_depends_on(struct basic_block *target, struct basic_block *src) return 0; } +/* + * Return 1 if 'pseudo' is needed in some parent of 'bb'. + * Need liveness info. + */ +static int needed_phisrc(struct instruction *phi, struct basic_block *curr, unsigned long generation) +{ + pseudo_t target = phi->target; + struct basic_block *bb; + + curr->generation = generation; + FOR_EACH_PTR(curr->children, bb) { + if (bb->generation == generation) + continue; + if (bb == phi->bb) + continue; + if (pseudo_in_list(bb->defines, target)) { + continue; + } + if (pseudo_in_list(bb->needs, target)) + return 1; + if (needed_phisrc(phi, bb, generation)) + return 1; + + } END_FOR_EACH_PTR(bb); + + return 0; +} + /* * When we reach here, we have: * - a basic block that ends in a conditional branch and @@ -121,7 +149,7 @@ static int try_to_simplify_bb(struct basic_block *bb, struct instruction *first, continue; changed |= rewrite_branch(source, &br->bb_true, bb, target); changed |= rewrite_branch(source, &br->bb_false, bb, target); - if (changed) + if (changed && !needed_phisrc(first, source, ++bb_generation)) kill_use(THIS_ADDRESS(phi)); } END_FOR_EACH_PTR(phi); return changed; diff --git a/validation/kill-phi-ttsbb2.c b/validation/kill-phi-ttsbb2.c new file mode 100644 index 000000000..c7d89aa0e --- /dev/null +++ b/validation/kill-phi-ttsbb2.c @@ -0,0 +1,40 @@ +extern int error(int); + +int foo(int perr); +int foo(int perr) +{ + int err = 0; + int rc = 0; + int j = 0; + int i = 1; + + i && j++; + + i-- && j; + + i && j--; + + if (j != 1) { + err = 1; + if (perr) + error(1); + } + + if (err != 0) + rc = 1; + + return rc; +} + +/* + * check-name: kill-phi-ttsbb2 + * check-description: + * Verify if OP_PHI usage is adjusted after successful try_to_simplify_bb() + * check-warning: this test is sensitive to details of code generation + * with proper bb packing (taking care of phi-nodes) it + * will be optimized away and test nothing. You have been warned. + * check-command: test-linearize $file + * check-output-ignore + * + * check-output-excludes: VOID + */