From patchwork Fri Jun 16 19:18:43 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: 9793427 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 0329F60231 for ; Fri, 16 Jun 2017 19:19:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E63262841D for ; Fri, 16 Jun 2017 19:18:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9C0A2855C; Fri, 16 Jun 2017 19:18:59 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 7D6CD2841D for ; Fri, 16 Jun 2017 19:18:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751763AbdFPTS7 (ORCPT ); Fri, 16 Jun 2017 15:18:59 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33638 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751012AbdFPTS5 (ORCPT ); Fri, 16 Jun 2017 15:18:57 -0400 Received: by mail-wm0-f66.google.com with SMTP id f90so6629709wmh.0 for ; Fri, 16 Jun 2017 12:18:57 -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=+P1QrMTOcNCrx/CBwjA9CoUNOoVV0zoLnKxxLpERb8Q=; b=m2Xxp/2L+79h9pZM9Vcw2zp5W2KqPighnMfXJL7kt6O6G/diWQLj5CA9Kw+4TRphuf TL2miHtb00AQfUM5Tla+CLNKySTGFuauT7q37ba2REJ1EEPJ5GV+yks4cZeax9mSHo/l i/mJTrw8osJEBWpG7p8n+qE04A7tpjlEWtUIvLJoxLl9WdlL8eB7n8/ZmbQMOEwRG8RL lgIh1+vcSoMnZti83rw7M/uxpodzzIhJCJx6pG+u9CQ7MCg7/b4SyVho1NQXtZT6Nt8d QTM5CAdBEHwoDyVvuOyYXsVyjMBGCJOJA+bn1pWS8qIytSX9NGxFV5MQ86qWfCXHokeP qrxA== 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=+P1QrMTOcNCrx/CBwjA9CoUNOoVV0zoLnKxxLpERb8Q=; b=aO0SD3ElNzp2yGzAaRSHpikekbCvvGR9DgVIx9i6pOLzbwTgTKtMX6szX+JRFzSQFB nsfm0jMfqdTMCPtCToMyYMAnwpIR0t4gf2VUFXwrAbG6p8pA2bNPt8VtR4J3ETajaK+q TOjqs62SpqE9KZCx+0qUmu5xtYqnAxmRb4xE+eH1iEz3mA4tqFqcsRqwkHsfN1PSb+P+ F5Yubd1as1QLKR/YnN7a8C4AMxgF2jtxg0nUz2KLxJPEe6Lae7YORmVxavKcBZDJsvHr 7/I8jeOf+CHS3eOn3fCYHZ1OXhtPERTb9+6Bi9yEddo2UT9g7yWPiyLK9Tf5BqQFcLw4 UAjg== X-Gm-Message-State: AKS2vOxMR3AkeQTj71D3ZH5xlxt1fplj8tIahA27RMDvZWcD+3+Sgdm3 BclYrpf6W08AZp3JziI= X-Received: by 10.80.173.24 with SMTP id y24mr8100902edc.16.1497640736141; Fri, 16 Jun 2017 12:18:56 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:89c:5400:a531:3442:3c25:b1bd]) by smtp.gmail.com with ESMTPSA id r28sm1598048edd.33.2017.06.16.12.18.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2017 12:18:55 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Chris Li , Ramsay Jones , Luc Van Oostenryck Subject: [PATCH 1/2] fix OP_PHI usage in try_to_simplify_bb() only when non-bogus Date: Fri, 16 Jun 2017 21:18:43 +0200 Message-Id: <20170616191844.86256-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170616191844.86256-1-luc.vanoostenryck@gmail.com> References: <20170616191844.86256-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 Currently, sparse method of conversion to SSA form, doesn't place phi-nodes at the dominance frontier but often place them 'lower' where the corresponding 'value' is needed. This, in itself create all sort of problems. One of these problems is that it is then quite common for an OP_PHI to contains less 'sources' than it has parents. This is wrong has phi-nodes represent the 'join' a value can have from each of the incoming paths/parents. This situation can't be given a sensible semantic and any attempt to try some optimization involving the phi-nodes and their sources are bound to fail. Temporary workaround this in try_to_simplify_bb() by simply checking if the number of parents and the number of phi-sources match and avoid to make this simplification if they don't. Signed-off-by: Luc Van Oostenryck --- flow.c | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/flow.c b/flow.c index e0932edb4..8a9005aa6 100644 --- a/flow.c +++ b/flow.c @@ -79,34 +79,6 @@ 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 @@ -122,6 +94,14 @@ static int try_to_simplify_bb(struct basic_block *bb, struct instruction *first, { int changed = 0; pseudo_t phi; + int bogus; + + /* + * This a due to improper dominance tracking during + * simplify_symbol_usage()/conversion to SSA form. + * No sane simplification can be done when we have this. + */ + bogus = bb_list_size(bb->parents) != pseudo_list_size(first->phi_list); FOR_EACH_PTR(first->phi_list, phi) { struct instruction *def = phi->def; @@ -149,7 +129,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 && !needed_phisrc(first, source, ++bb_generation)) + if (changed && !bogus) kill_use(THIS_ADDRESS(phi)); } END_FOR_EACH_PTR(phi); return changed;