From patchwork Sun Mar 21 12:34:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C52C3C433E0 for ; Sun, 21 Mar 2021 12:35:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AC4C6194C for ; Sun, 21 Mar 2021 12:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229815AbhCUMfW (ORCPT ); Sun, 21 Mar 2021 08:35:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbhCUMfO (ORCPT ); Sun, 21 Mar 2021 08:35:14 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5DACC061762 for ; Sun, 21 Mar 2021 05:35:13 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id bx7so16045730edb.12 for ; Sun, 21 Mar 2021 05:35:13 -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 :mime-version:content-transfer-encoding; bh=4a5yyAK7LcFKaBUbRNQBjJkBua6gs1yXslDxHJ7gCzQ=; b=u6MTFBaoRyLwkj0fNs3yBBdnZz2Fsdi2ezlIO61SJPAGfjdReR1dQkMWWjBSqLKq6w OogsmXXjRAzcpt5XyWBmfZK6XGUAcDLV1uzmM2Y7jm3lL2qaJ/vgHE2qT/q0pYfeHrbX WH6KT/kR5g9fs0mi276b7vNoVv5JxCZxgWOOlEa795bLqLWMhiR1mE9b4ky5ybqN2cbL /NUCrOW3KpT2DTpRqbLJOrxsJ4lG/+oW8wopqmotTjIWJFOGT/dieDqnFlUh/BXUcdgu xRMGoR07eDUZZ1ZxiPkJ8svnlOy4hl2JG9BLrbWK3gTf9keA7dlHf8/AUhR0syPA33NP C6sA== 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:mime-version:content-transfer-encoding; bh=4a5yyAK7LcFKaBUbRNQBjJkBua6gs1yXslDxHJ7gCzQ=; b=Ggu7JiC4dkGcK19FmMrMPxeMWruVG8CIagDJyjKI86INYGMcp7PPaWw94yHkz3SeRQ JOuOobA9lzu4r9JGe5ve7NPaD8cSfqxROcO9jGmoW5KRQyadC9T2+MOr/a2z6hSv0dKJ q+yNcGPQLmN2KMchwC146pKJOUeuiu84n7e3fbTIioMBzY4UWi6h8on1FS/wPpYvbIgI 24Ll+pprLiw7wl0Ip5ru+ENk8nQ/3f3qp3vN/BBEjw8EE4h/0rUYSoNPAhYE1/46XrMW c4UgZ2SGgUlcglMeMHaPIVaVVO77ZdkW2uWzjfXe7yvd3H6PEf0abXRJcgH8ROwq0CE3 AiSw== X-Gm-Message-State: AOAM533TCw/jGfqoO8BTNI6PmUpU2mu0mOwcjPV1zLs7P3Q64cF7woJv wXqSk/oIlPjGIeC7Nbs0oi/BlgvKA+0= X-Google-Smtp-Source: ABdhPJywj7gwzsdfjm2CRSGeybpNuW+19Znvc4Q+dAF/jhkdoIH26E4vLrkMFT0NaOgh2Kp17s3mBQ== X-Received: by 2002:a05:6402:3595:: with SMTP id y21mr20087324edc.233.1616330112554; Sun, 21 Mar 2021 05:35:12 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:12 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 01/13] Revert "simplify CBR-CBR on the same condition" Date: Sun, 21 Mar 2021 13:34:53 +0100 Message-Id: <20210321123505.27993-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org The commit 7cd2ce022575 ("simplify CBR-CBR on the same condition") added a generalization of the existing CBR-CBR simplification using the dominance tree. The problem is that as soon as a change is made to the CFG, the dominance tree become invalid and should be rebuilt (which is costly to do for each CFG changes) or updated (which is quite complex). So, for now, revert this commit. Reverts: 7cd2ce022575fbd383bb39b54f1e0fa402919da2. Signed-off-by: Luc Van Oostenryck --- flow.c | 106 --------------------------------------------------------- 1 file changed, 106 deletions(-) diff --git a/flow.c b/flow.c index c5319ae35ac4..6d77453a3554 100644 --- a/flow.c +++ b/flow.c @@ -19,7 +19,6 @@ #include "simplify.h" #include "flow.h" #include "target.h" -#include "flowgraph.h" unsigned long bb_generation; @@ -69,34 +68,6 @@ static int pseudo_truth_value(pseudo_t pseudo) } } -/// -// check if the BB is empty or only contains phi-sources -static int bb_is_trivial(struct basic_block *bb) -{ - struct instruction *insn; - int n = 0; - - FOR_EACH_PTR(bb->insns, insn) { - if (!insn->bb) - continue; - switch (insn->opcode) { - case OP_TERMINATOR ... OP_TERMINATOR_END: - return n ? -1 : 1; - case OP_NOP: - case OP_INLINED_CALL: - continue; - case OP_PHISOURCE: - n++; - continue; - default: - goto out; - } - } END_FOR_EACH_PTR(insn); - -out: - return 0; -} - /* * Does a basic block depend on the pseudos that "src" defines? */ @@ -158,81 +129,6 @@ out: return false; } -/// -// do jump threading in dominated BBs -// @dom: the BB which must dominate the modified BBs. -// @old: the old target BB -// @new: the new target BB -// @return: 0 if no chnages have been made, 1 otherwise. -// -// In all BB dominated by @dom, rewrite branches to @old into branches to @new -static int retarget_bb(struct basic_block *dom, struct basic_block *old, struct basic_block *new) -{ - struct basic_block *bb; - int changed = 0; - - if (new == old) - return 0; - -restart: - FOR_EACH_PTR(old->parents, bb) { - struct instruction *last; - struct multijmp *jmp; - - if (!domtree_dominates(dom, bb)) - continue; - last = last_instruction(bb->insns); - switch (last->opcode) { - case OP_BR: - changed |= rewrite_branch(bb, &last->bb_true, old, new); - break; - case OP_CBR: - changed |= rewrite_branch(bb, &last->bb_true, old, new); - changed |= rewrite_branch(bb, &last->bb_false, old, new); - break; - case OP_SWITCH: - case OP_COMPUTEDGOTO: - FOR_EACH_PTR(last->multijmp_list, jmp) { - changed |= rewrite_branch(bb, &jmp->target, old, new); - } END_FOR_EACH_PTR(jmp); - break; - default: - continue; - } - - // since rewrite_branch() will modify old->parents() the list - // iteration won't work correctly. Several solution exist for - // this but in this case the simplest is to restart the loop. - goto restart; - } END_FOR_EACH_PTR(bb); - return changed; -} - -static int simplify_cbr_cbr(struct instruction *insn) -{ - struct instruction *last; - struct basic_block *bot = insn->bb; - struct basic_block *top = bot->idom; - int changed = 0; - int trivial; - - if (!top) - return 0; - - trivial = bb_is_trivial(bot); - if (trivial == 0) - return 0; - if (trivial < 0) - return 0; - last = last_instruction(top->insns); - if (last->opcode != OP_CBR || last->cond != insn->cond) - return 0; - - changed |= retarget_bb(last->bb_true , bot, insn->bb_true); - changed |= retarget_bb(last->bb_false, bot, insn->bb_false); - return changed; -} - /* * When we reach here, we have: * - a basic block that ends in a conditional branch and @@ -380,8 +276,6 @@ static int simplify_one_branch(struct basic_block *bb, struct instruction *br) { if (simplify_phi_branch(bb, br)) return 1; - if (simplify_cbr_cbr(br)) - return 1; return simplify_branch_branch(bb, br, &br->bb_true, 1) | simplify_branch_branch(bb, br, &br->bb_false, 0); } From patchwork Sun Mar 21 12:34:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D477AC433C1 for ; Sun, 21 Mar 2021 12:35:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB50B6194A for ; Sun, 21 Mar 2021 12:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229870AbhCUMfZ (ORCPT ); Sun, 21 Mar 2021 08:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbhCUMfP (ORCPT ); Sun, 21 Mar 2021 08:35:15 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75C79C061763 for ; Sun, 21 Mar 2021 05:35:14 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id r12so16831689ejr.5 for ; Sun, 21 Mar 2021 05:35:14 -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 :mime-version:content-transfer-encoding; bh=38o/PQMi24YzHkakkTvVA4bD1js5KGyrIGSn37xp4H8=; b=Hw4jKyB+luH6k2vzx7HKpo7yfP9AUdwDpkFCWbC1AVGMYokbfFHmzinXHBZuOPzvS5 KHRwzMiZ1R0Soyhfs2oUR6wW230Q1lyvHfpfB5x5XtFh2/hy37o9DQF98RaL9alF9Fb5 nfBxL4vIpqXu7lCXAJ+hniJ7oA9o6DQMkTQKs53oRuk2e1UXMX4081PYk/U7Wfu+fHLp rAmCr/kbAKJBYBxcpO8/s9yHEMSz96/8FkKVzmgt8caGxbhK+XU01OUhn5Bx9YrwJb1x MJ/KCC2DYQ1pQz+4KftUIHui8RoD5Koiz4aRVUTBSDEst++82i2hL88I+w168jU+H55M QNzA== 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:mime-version:content-transfer-encoding; bh=38o/PQMi24YzHkakkTvVA4bD1js5KGyrIGSn37xp4H8=; b=Y2Sv7z5BbAzDuYXbLxpbBUd1xHb9I+y7j+s7Nrs033ZXC8ZYKgeciF1ZUmr9pHXBLj aMbv9KjNaIjpjBgfPc/bCRpLR8V4d2L3/4qMocKXANwManp3CpAj8icSStG7g8aMZL9z 5HUwV4xBKPSkl5T5//ZptDhAEM1ifMg3V7qavgj6rgy87aknLr55g91fWUL+Yl6IQKp8 GL2XHmNAEjoPXZ2tQHIxhyDG7tobdEAQDUbquqvLom0TB5niZRDG9roC1MhYxZCO/49P 7H1jp0090QDyhjPs8Ucq/qg3L8WowbPdfrVs9eXj9tx5dkMrKmVzDC9cx5c3FLqmC5wD w1Wg== X-Gm-Message-State: AOAM532Dd+p4xSCkJuGlJZf3ecjt4JcFu1qK9vix+9F3NrX9hssayPyV jnfOoP/SWi5+avXgL6mEV33rSVUhn9w= X-Google-Smtp-Source: ABdhPJzQhqjwbpTOogGBVhRdheF/YmhaxAgL0HzJ5YBkEF5Wu2TvUPTBUimsKuf2nVl2/qrJ7eXBrg== X-Received: by 2002:a17:906:f8d5:: with SMTP id lh21mr14280853ejb.64.1616330113189; Sun, 21 Mar 2021 05:35:13 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:12 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 02/13] add testcases to check if phi-sources from removed targets are removed too Date: Sun, 21 Mar 2021 13:34:54 +0100 Message-Id: <20210321123505.27993-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Signed-off-by: Luc Van Oostenryck --- validation/optim/bad-phisrc1.c | 16 ++++++++++++++++ validation/optim/bad-phisrc1a.c | 24 ++++++++++++++++++++++++ validation/optim/bad-phisrc2.c | 17 +++++++++++++++++ validation/optim/bad-phisrc3.c | 21 +++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 validation/optim/bad-phisrc1.c create mode 100644 validation/optim/bad-phisrc1a.c create mode 100644 validation/optim/bad-phisrc2.c create mode 100644 validation/optim/bad-phisrc3.c diff --git a/validation/optim/bad-phisrc1.c b/validation/optim/bad-phisrc1.c new file mode 100644 index 000000000000..59c5e4f1e66a --- /dev/null +++ b/validation/optim/bad-phisrc1.c @@ -0,0 +1,16 @@ +void foo(int a, int b) +{ + if (b) + while ((a += 5) > a) + ; +} + +/* + * check-name: bad-phisrc1 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-excludes: phi\\. + * check-output-excludes: phisource\\. + */ diff --git a/validation/optim/bad-phisrc1a.c b/validation/optim/bad-phisrc1a.c new file mode 100644 index 000000000000..cf07573b1fd3 --- /dev/null +++ b/validation/optim/bad-phisrc1a.c @@ -0,0 +1,24 @@ +int def(void); + +int fun4(struct xfrm_state *net, int cnt) +{ + int err = 0; + if (err) + goto out; + for (; net;) + err = def(); + if (cnt) +out: + return err; + return 0; +} + +/* + * check-name: bad-phisrc1a + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: select\\. + */ + diff --git a/validation/optim/bad-phisrc2.c b/validation/optim/bad-phisrc2.c new file mode 100644 index 000000000000..3eade688f768 --- /dev/null +++ b/validation/optim/bad-phisrc2.c @@ -0,0 +1,17 @@ +int bad_phisrc2(int p, int a, int r) +{ + if (p) + r = a; + else if (r) + ; + return r; +} + +/* + * check-name: bad-phisrc2 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: select\\. + */ diff --git a/validation/optim/bad-phisrc3.c b/validation/optim/bad-phisrc3.c new file mode 100644 index 000000000000..6e437771b4b8 --- /dev/null +++ b/validation/optim/bad-phisrc3.c @@ -0,0 +1,21 @@ +void foo(void) +{ + int c = 1; + switch (3) { + case 0: + do { + ; + case 3: ; + } while (c++); + } +} + +/* + * check-name: bad-phisrc3 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(2): phisrc\\. + * check-output-pattern(1): phi\\. + */ From patchwork Sun Mar 21 12:34:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21C32C433E4 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E71DA61946 for ; Sun, 21 Mar 2021 12:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229846AbhCUMfZ (ORCPT ); Sun, 21 Mar 2021 08:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbhCUMfP (ORCPT ); Sun, 21 Mar 2021 08:35:15 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17C75C061764 for ; Sun, 21 Mar 2021 05:35:15 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id u5so16831329ejn.8 for ; Sun, 21 Mar 2021 05:35:15 -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 :mime-version:content-transfer-encoding; bh=8+NYsJOnQXUgjbqubjpQl63dBFOuY021lMJSJDGajPA=; b=qhw/KA2xTpN4YNzO6mIg75KsuY3mbnK5C8gWYgph5XvCd7Cs2A+07xySDd56eygUfY YVdp48SeP4TVeZlmuYdod3d6YXhG1XEhe8PrbvYxewOMgN3EDhNzvMVuAWSU7V/sakD+ bGr8wvATeCSUwCqsAEVElgvk9ihYDlvglqM9s41tcalPCYWXLMdXgcrp7E2w0c3A5Kdt ENdwdGhQ3Qg8+Xv3Gxf0Nl6gGTF9Jfs7ewCMIo3+pDSGFSFawNfxobHl+VrqbtzZthm1 WuHiHp81X4gSKkSrZw79hpYIJtnhB5FMGqDDWYFy2p5DytMgYWTBtmxtT9b9XQ0vlKZN CZIw== 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:mime-version:content-transfer-encoding; bh=8+NYsJOnQXUgjbqubjpQl63dBFOuY021lMJSJDGajPA=; b=J/9PX6MomLEPswaSyEMEc2C0UT+bJhGKboxi+bzwM6n/OO+GeFaP1oHbIK4DQVZ6Ut OLmVcg2yfF6DWQy68339HXNyVP0CVq9K+opju6f1hFXOACH1Kwisbc9PBvqYFIb/hfVr wxHKiE4QWuyQF+y8unNJC6nFbcxtCa2ud/pnMtMPEmsuFh5E0MBF1jQLW/PwepEFHBzW COkWDJ7ObOYCvtFv8MXYRnWewHzXDMnd6+1ae+lyyfzXWGSrWovhNf5JFzpyjwm95s5z +a8h5hWEuiQhecrAZKYo0i6/pvdkPwzCz4qS3nh5XP/ZEUnqpqjXvvhNnkdEH3kxSH6F SaPw== X-Gm-Message-State: AOAM5316GID0yB7XdjejpBtyc2Qof683M0P4wqVUkkuTTEniI8uJNt1L PKX1fiB+SDzaoHwqOqyhUj64m45BpXI= X-Google-Smtp-Source: ABdhPJwudmE8obTCDoyDFaYSGhDCBMYfk2HCQTSIljE+bOaypIQrErEReCKVQLk4mvawt4C/Sch0IQ== X-Received: by 2002:a17:907:7014:: with SMTP id wr20mr14455870ejb.179.1616330113768; Sun, 21 Mar 2021 05:35:13 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:13 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 03/13] remove insert_branch() redundant arg Date: Sun, 21 Mar 2021 13:34:55 +0100 Message-Id: <20210321123505.27993-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org insert_branch()'s first argument must be the BB of the instruction given in the second argument. So, remove it from the argument and simply use insn->bb instead. Signed-off-by: Luc Van Oostenryck --- flow.c | 2 +- linearize.c | 3 ++- linearize.h | 2 +- simplify.c | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/flow.c b/flow.c index 6d77453a3554..f85c2a30c3cb 100644 --- a/flow.c +++ b/flow.c @@ -268,7 +268,7 @@ try_to_rewrite_target: */ if (bb_list_size(target->parents) != 1) return retval; - insert_branch(target, insn, final); + insert_branch(insn, final); return 1; } diff --git a/linearize.c b/linearize.c index 7248fa56b2ef..ebb03217c9d9 100644 --- a/linearize.c +++ b/linearize.c @@ -700,8 +700,9 @@ static void remove_parent(struct basic_block *child, struct basic_block *parent) } /* Change a "switch" or a conditional branch into a branch */ -void insert_branch(struct basic_block *bb, struct instruction *jmp, struct basic_block *target) +void insert_branch(struct instruction *jmp, struct basic_block *target) { + struct basic_block *bb = jmp->bb; struct instruction *br, *old; struct basic_block *child; diff --git a/linearize.h b/linearize.h index 7909b01f29c5..1bb9d77eba1f 100644 --- a/linearize.h +++ b/linearize.h @@ -319,7 +319,7 @@ struct entrypoint { }; extern void insert_select(struct basic_block *bb, struct instruction *br, struct instruction *phi, pseudo_t if_true, pseudo_t if_false); -extern void insert_branch(struct basic_block *bb, struct instruction *br, struct basic_block *target); +extern void insert_branch(struct instruction *br, struct basic_block *target); struct instruction *alloc_phisrc(pseudo_t pseudo, struct symbol *type); struct instruction *alloc_phi_node(struct basic_block *bb, struct symbol *type, struct ident *ident); diff --git a/simplify.c b/simplify.c index 207af8edf28f..930c0fa7e83f 100644 --- a/simplify.c +++ b/simplify.c @@ -2441,7 +2441,7 @@ static int simplify_branch(struct instruction *insn) /* Constant conditional */ if (constant(cond)) { - insert_branch(insn->bb, insn, cond->value ? insn->bb_true : insn->bb_false); + insert_branch(insn, cond->value ? insn->bb_true : insn->bb_false); return REPEAT_CSE; } @@ -2473,11 +2473,11 @@ static int simplify_branch(struct instruction *insn) long long val1 = def->src2->value; long long val2 = def->src3->value; if (!val1 && !val2) { - insert_branch(insn->bb, insn, insn->bb_false); + insert_branch(insn, insn->bb_false); return REPEAT_CSE; } if (val1 && val2) { - insert_branch(insn->bb, insn, insn->bb_true); + insert_branch(insn, insn->bb_true); return REPEAT_CSE; } if (val2) { @@ -2515,7 +2515,7 @@ static int simplify_switch(struct instruction *insn) return 0; found: - insert_branch(insn->bb, insn, jmp->target); + insert_branch(insn, jmp->target); return REPEAT_CSE; } From patchwork Sun Mar 21 12:34:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDBD8C433E1 for ; Sun, 21 Mar 2021 12:35:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD0606194D for ; Sun, 21 Mar 2021 12:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229834AbhCUMfX (ORCPT ); Sun, 21 Mar 2021 08:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbhCUMfQ (ORCPT ); Sun, 21 Mar 2021 08:35:16 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC19BC061765 for ; Sun, 21 Mar 2021 05:35:15 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id bf3so16078867edb.6 for ; Sun, 21 Mar 2021 05:35:15 -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 :mime-version:content-transfer-encoding; bh=kgZWRMMMccH1TaVlZWXps4EsQ2idiMl3HOLRc5102a0=; b=X98In7gC6nagS4Xy+FdFAhO8MOSXiXTFxR4LiFTudX8DDZ41LQxKJLKk5Zx5REQ/OA d+OJLQdd8cII0zD3iAfP1JvtXS3b31kEEwGYoOM811aNV1vXozNgXWOT1QX+SRc5FxxN QRu3IsdBsCpYzvOEHYvG7P+ltLUYhsBU/npqmIcXT8FAXFRi71rKbzz6FlHdsxV+kzL6 hY4rkmklXHs+2yEWBr6IdQQ7u122ZgDq0YP3NVOalLqvWi0TbeNbvKPl26mE1WlFF8u0 tHgA3FnMiEGsxvBOpdnXUq/luK1sLHQrmu2Wxo4KkBSwRZk8QghRPrs4LxVpXZFyYf5U sVbQ== 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:mime-version:content-transfer-encoding; bh=kgZWRMMMccH1TaVlZWXps4EsQ2idiMl3HOLRc5102a0=; b=trJ1HYPgSQxK3LdJyWMoop9BXGOKBVueeySm/+sHV2dp3uQcXfhqxUTcn3huXJg3yy OH38P6iTA6vbH1ENYZfCQkEZ0fhPrmBZrdD9+V42baEa3ZHeF3b1DoOIHtDrIeh3fXW6 k8FXBsalbV7YTvKUtyJJ7+LDHA3gibKVEQcTARR0wVdVFYjDTiLwvZRw3xKMhm7SuLwi wi3ym3iM90I/kPXBk8KySqxpgzD0IYT1oZ+EWdHNoKTObKuUSBFojv4db5aGnf3Yp+iq Kx2j8WB1dlUdHYXFsVUmaa2Zikqd2bqq3IHPL1F5GK8HD18PeouWQkaSVYOJb74AUFbk sK4w== X-Gm-Message-State: AOAM532ki/9bqoa1ZApOZRTHIiXzUev/+uJVJHVGVP3rWFpSpKJGl0i0 zwfYBGdrmnD/Vy0k5JmfvmqQVStH2Jo= X-Google-Smtp-Source: ABdhPJweeT2THNIeLA/w3lYDmR6JOBxfVwiUR9rOW2k8ABcH/QGmFzD/txFqZX8MPWTs9ZzZFhWafA== X-Received: by 2002:aa7:cb97:: with SMTP id r23mr20028353edt.106.1616330114469; Sun, 21 Mar 2021 05:35:14 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:14 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 04/13] simplify remove_parent() Date: Sun, 21 Mar 2021 13:34:56 +0100 Message-Id: <20210321123505.27993-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org remove_parent() is a simple wrapper around remove_bb_from_list() which also set REPEAT_CFG_CLEANUP if the list becomes empty. But its only user, insert_branch(), doesn't need REPEAT_CFG_CLEANUP to be set. So, simplify this wrapper by keeping only the call to remove_bb_from_list(). --- linearize.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/linearize.c b/linearize.c index ebb03217c9d9..6bb1287efcb0 100644 --- a/linearize.c +++ b/linearize.c @@ -695,8 +695,6 @@ static void set_activeblock(struct entrypoint *ep, struct basic_block *bb) static void remove_parent(struct basic_block *child, struct basic_block *parent) { remove_bb_from_list(&child->parents, parent, 1); - if (!child->parents) - repeat_phase |= REPEAT_CFG_CLEANUP; } /* Change a "switch" or a conditional branch into a branch */ From patchwork Sun Mar 21 12:34:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C755C433E3 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21AA46194D for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbhCUMf0 (ORCPT ); Sun, 21 Mar 2021 08:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbhCUMfR (ORCPT ); Sun, 21 Mar 2021 08:35:17 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D1DCC061574 for ; Sun, 21 Mar 2021 05:35:16 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id e7so16015528edu.10 for ; Sun, 21 Mar 2021 05:35:16 -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 :mime-version:content-transfer-encoding; bh=1o4/AAviTzjOvQEMVjDCIR9CpsSISzmi4LdFcuk+Zm4=; b=Y+eOpMH9SjhpJzAQeyKiU4A3d4n00HTehbUalNCkRnYca4rzKAjYTm6YudGOGS2nso HxWpeOG3XFPftywjTUx02TaBmpUB7cpEkNINlU1lW6QS8tU/k8PoWLzoeSk62EXB5HXw JxodhXMIzou3QO2xMoUyFlOGy8agQGu5QJfIuOPnAKV5Wn0U58JLfswghA2TGESIIICy Um2feQdH5TRsy21FayhSo2tjm4s0ctrZZEyUrW/pNQvKoREf7zJMOAv4bfAUbO1P9ZXC RItU1KKk9AU7/ufcugp0mZSGF9oap6IQ1eLWZLhPVB29zV4tFI4muisNnpoYEXaKCcNc qdvg== 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:mime-version:content-transfer-encoding; bh=1o4/AAviTzjOvQEMVjDCIR9CpsSISzmi4LdFcuk+Zm4=; b=qBYJY8dbHcsXMGTbJYzjbbaWe/xOfXRWiF1oB6deGqhzDIOHkctDN6XdwPa1WTZrJV CWy01S5rXpVkZVa8ZoseFCKp0aPWyerfokVMBM+KKSfHEu+ar1IK/XS0cy9qo6mBkDTS 6Av4MCCYkHF9WX2GtQx1l7v2xoLo9rqQJWBR/Wxyc4zYWG4bWLHLLns9zDlOwUmLf/9H HpXVNMlCzpFrRGNqCDxNt0PmdTsf5CHD+gBAiUCxbYAv9VOKZnlwO0E9J2Bc1XCQ+1Re 0nc2fVXRUzlmyc19vz0Aq6AOralZloX3Zf4zYIXqB1RITMJGiLKDWk4wTOTiMUxqBBHp tr7w== X-Gm-Message-State: AOAM531gFRS2QhPnYMC0YcqqP6FAc1kz/kNlnuiTgLxUxtoX8KZGGTvL rwqZKeB513FF5Zrg2ja9oVqNVWmhTUA= X-Google-Smtp-Source: ABdhPJz7XIB9jOhfDpKPBZ08SZuSZLBDN9db02Ll1GiqWdM7AvDDdwZiLZKXVORqlsYQIwuo+RKTFg== X-Received: by 2002:aa7:c353:: with SMTP id j19mr20193659edr.263.1616330115300; Sun, 21 Mar 2021 05:35:15 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:14 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 05/13] fold remove_parent() into insert_branch() Date: Sun, 21 Mar 2021 13:34:57 +0100 Message-Id: <20210321123505.27993-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Fold remove_parent() into its only user, insert_branch(), since it's now just a wrapper around remove_bb_from_list(). Signed-off-by: Luc Van Oostenryck --- linearize.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/linearize.c b/linearize.c index 6bb1287efcb0..2268b0951376 100644 --- a/linearize.c +++ b/linearize.c @@ -692,11 +692,6 @@ static void set_activeblock(struct entrypoint *ep, struct basic_block *bb) add_bb(&ep->bbs, bb); } -static void remove_parent(struct basic_block *child, struct basic_block *parent) -{ - remove_bb_from_list(&child->parents, parent, 1); -} - /* Change a "switch" or a conditional branch into a branch */ void insert_branch(struct instruction *jmp, struct basic_block *target) { @@ -720,7 +715,7 @@ void insert_branch(struct instruction *jmp, struct basic_block *target) continue; } DELETE_CURRENT_PTR(child); - remove_parent(child, bb); + remove_bb_from_list(&child->parents, bb, 1); } END_FOR_EACH_PTR(child); PACK_PTR_LIST(&bb->children); repeat_phase |= REPEAT_CFG_CLEANUP; From patchwork Sun Mar 21 12:34:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18AD8C433E2 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D22186194C for ; Sun, 21 Mar 2021 12:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbhCUMf0 (ORCPT ); Sun, 21 Mar 2021 08:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbhCUMfR (ORCPT ); Sun, 21 Mar 2021 08:35:17 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3815AC061762 for ; Sun, 21 Mar 2021 05:35:17 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id u5so16831429ejn.8 for ; Sun, 21 Mar 2021 05:35:17 -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 :mime-version:content-transfer-encoding; bh=zTWNAKWB/spf0KR3ml2vXOWrUdmG1XPa7riG/7CK5wY=; b=Fnd1XdAUvXANqSlg5A6iIqjKI/wjqHacInZKwafsQQX9XeJEx+OYYD9SHYs4Asz0fS zHmi1xON+ktmNOorLsVb3LXB0fvSrMyGZWpLjqU5YMBYMH1Cn4jFpcQaBRpK0C0xtOE2 Uvq1Diy+ImxBAkH7w3wy2bpoIx/NVaYL690ugDkcrnBe01doXlf9SftOjaJPecw79V5u gQbTiXaoIwP3A078JLRliJIkvXPqMBPRNAXjUPluAO8b+TCsJhtSp/bZmNtRlSWIHJEt W2Mq7/jbbr4MjT78A51oW3QNFrS6ZIK4nmVOKlitk40iJfvKqexYP9hMXuX2FcZMeowy GFig== 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:mime-version:content-transfer-encoding; bh=zTWNAKWB/spf0KR3ml2vXOWrUdmG1XPa7riG/7CK5wY=; b=l+PXBBcf1C2a2eUfuaVmk/O+wSZ+k++tp+iVJm9hURP5W4jYur7tyyVieUbofR9q1z qnA3wXu1jREA/b2bIigVgkzf2m7BkCDo+HtNnXX80NMBF1zTDMroSnaB/nH+tGp0h9Zm nuDx0ZVMjMzGyi9GkuHlWu5+Xh+oe2dGesPL3e7whaIs+zS39C0g41bAsd0Hq2Zv+XkO YlHbhqcLSkN7T27rQHSwgjJ2gRuIeJFK+bK4vjH3h54nhQ6wkUIOu4W6Bzo/DDUgME9i d8RQsHDLzlyInfXZKxX0Hgm1sPKKm5WdcW9o8LxT8ifDNS7Ib0LNTNVSKmfNk+fUOqjG X3nA== X-Gm-Message-State: AOAM5328MZx1wLdeMx01k0HIpJ7MKHcdhBJAG+Ft3jr0gl3k8LGH0sUj QV7gBIZ2Szi3KNhF8Uy6PsfAIoEgnXI= X-Google-Smtp-Source: ABdhPJyfElXcMKWmo7QZf7L2p0vtzgtRsnsHQW8aBe1B1u+XN+4WL0TEGi5BEvqperhm68B1bR4y7g== X-Received: by 2002:a17:906:f9cc:: with SMTP id lj12mr13935725ejb.544.1616330116009; Sun, 21 Mar 2021 05:35:16 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:15 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 06/13] let insert_branch() reuse the terminating instruction Date: Sun, 21 Mar 2021 13:34:58 +0100 Message-Id: <20210321123505.27993-7-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org insert_branch() changes a switch or a conditional branch into a jump. This is implemented by deleting the old instruction and allocating the new one. This is not needed here since no reference to the old instruction is kept. So, simply reuse the terminating instruction and change it. Signed-off-by: Luc Van Oostenryck --- linearize.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/linearize.c b/linearize.c index 2268b0951376..1d85cf2ba208 100644 --- a/linearize.c +++ b/linearize.c @@ -696,18 +696,14 @@ static void set_activeblock(struct entrypoint *ep, struct basic_block *bb) void insert_branch(struct instruction *jmp, struct basic_block *target) { struct basic_block *bb = jmp->bb; - struct instruction *br, *old; struct basic_block *child; - /* Remove the switch */ - old = delete_last_instruction(&bb->insns); - assert(old == jmp); - kill_instruction(old); - - br = alloc_instruction(OP_BR, 0); - br->bb = bb; - br->bb_true = target; - add_instruction(&bb->insns, br); + kill_use(&jmp->cond); + jmp->bb_true = target; + jmp->bb_false = NULL; + jmp->cond = NULL; + jmp->size = 0; + jmp->opcode = OP_BR; FOR_EACH_PTR(bb->children, child) { if (child == target) { From patchwork Sun Mar 21 12:34:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A8CBC433E8 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FB996194C for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229871AbhCUMf1 (ORCPT ); Sun, 21 Mar 2021 08:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbhCUMfS (ORCPT ); Sun, 21 Mar 2021 08:35:18 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1070C061574 for ; Sun, 21 Mar 2021 05:35:17 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id b9so16837918ejc.11 for ; Sun, 21 Mar 2021 05:35:17 -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 :mime-version:content-transfer-encoding; bh=uhHrSsFLQ8zGT4n2tnQ0BNI4MYw/+5QJZ+BU/ZQoXKQ=; b=ngW9wWgGxGhD2zXfPXj0dpsgTJn4X9pSCj4m+eEc50BQQMpuxCc/Cw0o7BaCRFjswK 2nocK/YcFMHN6Pl/2EeqVXUj+qGIKDA03iP7htjmVWbYY0qHTPukhIQ4juerBE5Vwc7z j42U3UgqShX8vmAquRlatrGNYqqt0K40n/qWP2t50C57Bnlkbs8g9CvXSL7AZDhc+s9c 8pfUd4jLXrwTA+ojxV2loddiZX4YJapt+mZul5Sl/mq8feI7MA8cBLJkoN7wD4LMkzwB 1h1B+AR925YMSOZIw9/OjNislTrYyZgNbbppgF/4zFfbyrOI9+BoUsSB8gQ9T87Y8qHN Mmzw== 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:mime-version:content-transfer-encoding; bh=uhHrSsFLQ8zGT4n2tnQ0BNI4MYw/+5QJZ+BU/ZQoXKQ=; b=KWpRuoSUaRIYiFyt1LX5s7Z25Sqk7DzzTEvj640eVXq2/cPIsyBOZVqX7ZgCPrPPYC xfmeie0nxhAPiOT0WLwVM60Y2mbyHa62jWSAK+Oi4olSn2+Zcblp9Xrn+nDL6GmJAGko KAp1LtlTBXePFA20yj0GG/L9EyZhnn+wIgj7X5+JZw1QDEcEXSd7+WmvL8LioaELlfNj AkztjTXtsG7e5kpbNoGQEOM7HFSaiAL5cOzO56GA5eE+0ZHmPKFVYkida7wteaEyrJbR iNYOc/oaxbTeVukE36IPMQ7JEd50d5ercZPXCv7u6vRQ7aigNepugirAFFjZiY0jT/p+ 7LaQ== X-Gm-Message-State: AOAM53124wnQvZ5gA5Xn6ceC8mJqsgPpTZzGbd/bTFIGzNl/kx8NTgl6 gWKcJkrKxU6epIw28Jms8EWkBvrqyYg= X-Google-Smtp-Source: ABdhPJzDyeBDEPIqLuJvJvHxWs/ZX2Ef0enoqPFK9lHzcysy0oc1aoOG+f7VXZ34uYPfq2Gum4CUOw== X-Received: by 2002:a17:906:7842:: with SMTP id p2mr14913389ejm.87.1616330116665; Sun, 21 Mar 2021 05:35:16 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:16 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 07/13] move insert_branch() to flow.c Date: Sun, 21 Mar 2021 13:34:59 +0100 Message-Id: <20210321123505.27993-8-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Now that insert_branch() doesn't need to allocate a new instruction, there is no more reasons to have it defined in linearize.c So move it to flow.c which is more concerned with CFG changes. Signed-off-by: Luc Van Oostenryck --- flow.c | 26 ++++++++++++++++++++++++++ flow.h | 1 + linearize.c | 26 -------------------------- linearize.h | 1 - 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/flow.c b/flow.c index f85c2a30c3cb..1f4b4ff08151 100644 --- a/flow.c +++ b/flow.c @@ -709,6 +709,32 @@ void vrfy_flow(struct entrypoint *ep) assert(!entry); } +/// +// change a switch or a conditional branch into a branch +void insert_branch(struct instruction *insn, struct basic_block *target) +{ + struct basic_block *bb = insn->bb; + struct basic_block *child; + + kill_use(&insn->cond); + insn->bb_true = target; + insn->bb_false = NULL; + insn->cond = NULL; + insn->size = 0; + insn->opcode = OP_BR; + + FOR_EACH_PTR(bb->children, child) { + if (child == target) { + target = NULL; // leave first occurence + continue; + } + DELETE_CURRENT_PTR(child); + remove_bb_from_list(&child->parents, bb, 1); + } END_FOR_EACH_PTR(child); + PACK_PTR_LIST(&bb->children); + repeat_phase |= REPEAT_CFG_CLEANUP; +} + static int retarget_parents(struct basic_block *bb, struct basic_block *target) { struct basic_block *parent; diff --git a/flow.h b/flow.h index 46d76a780484..f9213306dfd6 100644 --- a/flow.h +++ b/flow.h @@ -18,6 +18,7 @@ extern void simplify_symbol_usage(struct entrypoint *ep); extern void simplify_memops(struct entrypoint *ep); extern void pack_basic_blocks(struct entrypoint *ep); extern int simplify_cfg_early(struct entrypoint *ep); +extern void insert_branch(struct instruction *insn, struct basic_block *target); extern void convert_instruction_target(struct instruction *insn, pseudo_t src); extern void remove_dead_insns(struct entrypoint *); diff --git a/linearize.c b/linearize.c index 1d85cf2ba208..e6aa01f1b9fe 100644 --- a/linearize.c +++ b/linearize.c @@ -692,32 +692,6 @@ static void set_activeblock(struct entrypoint *ep, struct basic_block *bb) add_bb(&ep->bbs, bb); } -/* Change a "switch" or a conditional branch into a branch */ -void insert_branch(struct instruction *jmp, struct basic_block *target) -{ - struct basic_block *bb = jmp->bb; - struct basic_block *child; - - kill_use(&jmp->cond); - jmp->bb_true = target; - jmp->bb_false = NULL; - jmp->cond = NULL; - jmp->size = 0; - jmp->opcode = OP_BR; - - FOR_EACH_PTR(bb->children, child) { - if (child == target) { - target = NULL; /* Trigger just once */ - continue; - } - DELETE_CURRENT_PTR(child); - remove_bb_from_list(&child->parents, bb, 1); - } END_FOR_EACH_PTR(child); - PACK_PTR_LIST(&bb->children); - repeat_phase |= REPEAT_CFG_CLEANUP; -} - - void insert_select(struct basic_block *bb, struct instruction *br, struct instruction *phi_node, pseudo_t if_true, pseudo_t if_false) { pseudo_t target; diff --git a/linearize.h b/linearize.h index 1bb9d77eba1f..b6c8bf134065 100644 --- a/linearize.h +++ b/linearize.h @@ -319,7 +319,6 @@ struct entrypoint { }; extern void insert_select(struct basic_block *bb, struct instruction *br, struct instruction *phi, pseudo_t if_true, pseudo_t if_false); -extern void insert_branch(struct instruction *br, struct basic_block *target); struct instruction *alloc_phisrc(pseudo_t pseudo, struct symbol *type); struct instruction *alloc_phi_node(struct basic_block *bb, struct symbol *type, struct ident *ident); From patchwork Sun Mar 21 12:35:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B872C433EB for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71D316194C for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbhCUMf2 (ORCPT ); Sun, 21 Mar 2021 08:35:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbhCUMfS (ORCPT ); Sun, 21 Mar 2021 08:35:18 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7385CC061762 for ; Sun, 21 Mar 2021 05:35:18 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id r12so16831851ejr.5 for ; Sun, 21 Mar 2021 05:35:18 -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 :mime-version:content-transfer-encoding; bh=qdCvsHh96rDSYiMxCeNGHa83d2TUkZ2fHdWdWFmKug0=; b=g/RbVzwBKzAATT/imme5OnK9/76UFiDzgDikA6e0u5IUoTM+ckD6c5OtGMh1yvnJVI 1kBnBS2SRypsHVl2DiPpvVpCzwsZRvfGRy2jei++T7dIIPu4hV1nKIEmjXxsUjfdgpN+ BP5AmROVDrXZtNDWiLjEIPJR1ci1mOHD+0OON/k+NL2JuIQ6FIQFBiEuAAFnwedBc9oC VPn+b1EzWxFutlmfhRUeTcSPDcK9hCnCm6x1URgLXnVkuzbk9mJ5MHnOOtYy7NX6bjMP 0rVBDrbw1Ta9jInpam9g8tTTaHgwyK4qyoCuvUJshLBPeVjtfmCyhC9Oim06UZd+683+ AkTA== 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:mime-version:content-transfer-encoding; bh=qdCvsHh96rDSYiMxCeNGHa83d2TUkZ2fHdWdWFmKug0=; b=RntVzn4ttrIBttwYz4jyH6FHCjBGfUVCh7JC3+xWK0uDvB7JU+k3v2HmQcKk/jLYu7 FNLLhc9GPkTLpTp+8CqI3kfC54O6asMf/Cp6K47Pb4Ts5ad4GPAmH5im8AaPegMLOpfe 8aGg8cqaMa6aToBJ4CEoaZvaRWO0oBVhrpiqzEjtaJj1CRH0lfQlK4IxQyXU1mjsK2Ve YdiMMyXGzte/qXmNE3IcsK/vF0pFnqTccNKxLrKugTVvDnTWiD6ZyK6V1DPsJHpZ1qs+ jMD7NbGdrQmqIu/LcHhw8az6lrhBvJmZURNJMkkE/QyhSLlJobPf4uEEA9whP19lvlAB kkNA== X-Gm-Message-State: AOAM533fk0GoXUXkD5AcoojHyO0AZKpspCkPFLbK7ZXfJ74rwjRogaIx FDG0kFvxBDDXV4NDkdv8GSTPsg08grA= X-Google-Smtp-Source: ABdhPJwOGgN6JdLA+0bBF1g6GYdIJOjlmHyOrr6gMm9LNJBatgiyBR0PXSxEEZE+iBYRKz7Jw1038Q== X-Received: by 2002:a17:907:20e4:: with SMTP id rh4mr14399630ejb.369.1616330117291; Sun, 21 Mar 2021 05:35:17 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:16 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 08/13] let insert_branch() return a status Date: Sun, 21 Mar 2021 13:35:00 +0100 Message-Id: <20210321123505.27993-9-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org insert_branch() modifies the CFG and the usage of pseudos so these changes must be, in a way or another, notify to the upper layers. Currently this is done by setting 'repeat_phase' in the function itself. Let this function to also report the changes via its return value since this is usually useful for the caller to know and tend to leaner code too. Signed-off-by: Luc Van Oostenryck --- flow.c | 7 +++++-- flow.h | 2 +- simplify.c | 21 +++++++-------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/flow.c b/flow.c index 1f4b4ff08151..38e0ccade722 100644 --- a/flow.c +++ b/flow.c @@ -711,10 +711,11 @@ void vrfy_flow(struct entrypoint *ep) /// // change a switch or a conditional branch into a branch -void insert_branch(struct instruction *insn, struct basic_block *target) +int insert_branch(struct instruction *insn, struct basic_block *target) { struct basic_block *bb = insn->bb; struct basic_block *child; + int changed = REPEAT_CSE; kill_use(&insn->cond); insn->bb_true = target; @@ -730,9 +731,11 @@ void insert_branch(struct instruction *insn, struct basic_block *target) } DELETE_CURRENT_PTR(child); remove_bb_from_list(&child->parents, bb, 1); + changed |= REPEAT_CFG_CLEANUP; } END_FOR_EACH_PTR(child); PACK_PTR_LIST(&bb->children); - repeat_phase |= REPEAT_CFG_CLEANUP; + repeat_phase |= changed; + return changed; } static int retarget_parents(struct basic_block *bb, struct basic_block *target) diff --git a/flow.h b/flow.h index f9213306dfd6..cad1de7723d5 100644 --- a/flow.h +++ b/flow.h @@ -18,7 +18,7 @@ extern void simplify_symbol_usage(struct entrypoint *ep); extern void simplify_memops(struct entrypoint *ep); extern void pack_basic_blocks(struct entrypoint *ep); extern int simplify_cfg_early(struct entrypoint *ep); -extern void insert_branch(struct instruction *insn, struct basic_block *target); +extern int insert_branch(struct instruction *insn, struct basic_block *target); extern void convert_instruction_target(struct instruction *insn, pseudo_t src); extern void remove_dead_insns(struct entrypoint *); diff --git a/simplify.c b/simplify.c index 930c0fa7e83f..0bc201e84313 100644 --- a/simplify.c +++ b/simplify.c @@ -2440,10 +2440,8 @@ static int simplify_branch(struct instruction *insn) pseudo_t cond = insn->cond; /* Constant conditional */ - if (constant(cond)) { - insert_branch(insn, cond->value ? insn->bb_true : insn->bb_false); - return REPEAT_CSE; - } + if (constant(cond)) + return insert_branch(insn, cond->value ? insn->bb_true : insn->bb_false); /* Same target? */ if (insn->bb_true == insn->bb_false) { @@ -2472,14 +2470,10 @@ static int simplify_branch(struct instruction *insn) if (constant(def->src2) && constant(def->src3)) { long long val1 = def->src2->value; long long val2 = def->src3->value; - if (!val1 && !val2) { - insert_branch(insn, insn->bb_false); - return REPEAT_CSE; - } - if (val1 && val2) { - insert_branch(insn, insn->bb_true); - return REPEAT_CSE; - } + if (!val1 && !val2) + return insert_branch(insn, insn->bb_false); + if (val1 && val2) + return insert_branch(insn, insn->bb_true); if (val2) { struct basic_block *tmp = insn->bb_true; insn->bb_true = insn->bb_false; @@ -2515,8 +2509,7 @@ static int simplify_switch(struct instruction *insn) return 0; found: - insert_branch(insn, jmp->target); - return REPEAT_CSE; + return insert_branch(insn, jmp->target); } static struct basic_block *is_label(pseudo_t pseudo) From patchwork Sun Mar 21 12:35:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4965AC433E6 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 317E26194A for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbhCUMf2 (ORCPT ); Sun, 21 Mar 2021 08:35:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbhCUMfT (ORCPT ); Sun, 21 Mar 2021 08:35:19 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F544C061574 for ; Sun, 21 Mar 2021 05:35:19 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id z1so16088558edb.8 for ; Sun, 21 Mar 2021 05:35:18 -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 :mime-version:content-transfer-encoding; bh=Ncp3Ty72khzW9ORl77uMF4OR2IBlzkrexTvb+n75fEw=; b=XmfILwb9oGNSE8jlsSIRjjWUVppOJYMlQIWAzdEJIA/lPpShv+rr/U/NtzqQH5aMph nUbcmRgMkb3epaOpUvbNwKQ5BbShoeZcNjT6UWXOed1UIYwIUhxx9bGvfT15gKop9cCh CJgZsnfwmX8hCnsaqa/JZGwojbqms6u3dE65h0tyPO/osfk0CUfhql0BU/5UutvhrwU8 M0LHndIpZGyQYV12lsHrZZn4pXIXO6De8AlAnLH/HGt+oG7wFbdbjoLmfp7tWq8ACV3s tQjj9syYJM5w30Kn32XqBHyVSWoGiU/jjs8KwwurDhQaV0f4rcIsqIGH05TZwEADsQDV Zxbg== 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:mime-version:content-transfer-encoding; bh=Ncp3Ty72khzW9ORl77uMF4OR2IBlzkrexTvb+n75fEw=; b=uCLMBYTBn+HNwBKZMjwIqKFTnQHOqE6es3wppiUWudWPuZnLnnE5hx1agWBy3bTysD sps55zFkPxU+9sLUTCjpp9Vh4b+CK89GL5x3M4GucDesrRDwqwbk35QJh8WDDwUHpsMo W5CyG6u51EOzQMEFayMxiz6nbcFxUwbxX1fGeblc6vDFObDhQqHr8TZSRFlwAfDbD+XC bqH8903TIvaar7NQqgrtjRxK3fU/naY1uLQoCKz2FKpyHxsykp2G1A4wv1/uvmttDQh6 77q9Zuo2UPT1zs8d0djExne6u+ZRIx+xhYkojMo5yfUPz52V7K0oI+4bK1Cc6ebzV2+D /tNw== X-Gm-Message-State: AOAM530388JO44AyGTA2qh8VjP4WT+c+IYnuZ5ExPCn4wQ2NBhJsEzow gFrHXHBVlTxpBPLQYPnv0YD/SgnX3E8= X-Google-Smtp-Source: ABdhPJzYHFNBJ/dLPkzSgfpPEFHVugy3qiUdv4iunLQl6TSjwesdL8unMDUDqJjRfxPHnv44jbNs/Q== X-Received: by 2002:aa7:c0c7:: with SMTP id j7mr20350705edp.298.1616330117845; Sun, 21 Mar 2021 05:35:17 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:17 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 09/13] rename insert_branch() to convert_to_jump() Date: Sun, 21 Mar 2021 13:35:01 +0100 Message-Id: <20210321123505.27993-10-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Since the existing branch is now reused, nothing is inserted anymore. So, rename this function to the more explanatory: convert_to_jump(). Signed-off-by: Luc Van Oostenryck --- flow.c | 4 ++-- flow.h | 2 +- simplify.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/flow.c b/flow.c index 38e0ccade722..8106cfc0d10b 100644 --- a/flow.c +++ b/flow.c @@ -268,7 +268,7 @@ try_to_rewrite_target: */ if (bb_list_size(target->parents) != 1) return retval; - insert_branch(insn, final); + convert_to_jump(insn, final); return 1; } @@ -711,7 +711,7 @@ void vrfy_flow(struct entrypoint *ep) /// // change a switch or a conditional branch into a branch -int insert_branch(struct instruction *insn, struct basic_block *target) +int convert_to_jump(struct instruction *insn, struct basic_block *target) { struct basic_block *bb = insn->bb; struct basic_block *child; diff --git a/flow.h b/flow.h index cad1de7723d5..2103a10fe428 100644 --- a/flow.h +++ b/flow.h @@ -18,7 +18,7 @@ extern void simplify_symbol_usage(struct entrypoint *ep); extern void simplify_memops(struct entrypoint *ep); extern void pack_basic_blocks(struct entrypoint *ep); extern int simplify_cfg_early(struct entrypoint *ep); -extern int insert_branch(struct instruction *insn, struct basic_block *target); +extern int convert_to_jump(struct instruction *insn, struct basic_block *target); extern void convert_instruction_target(struct instruction *insn, pseudo_t src); extern void remove_dead_insns(struct entrypoint *); diff --git a/simplify.c b/simplify.c index 0bc201e84313..7171bd564e63 100644 --- a/simplify.c +++ b/simplify.c @@ -2441,7 +2441,7 @@ static int simplify_branch(struct instruction *insn) /* Constant conditional */ if (constant(cond)) - return insert_branch(insn, cond->value ? insn->bb_true : insn->bb_false); + return convert_to_jump(insn, cond->value ? insn->bb_true : insn->bb_false); /* Same target? */ if (insn->bb_true == insn->bb_false) { @@ -2471,9 +2471,9 @@ static int simplify_branch(struct instruction *insn) long long val1 = def->src2->value; long long val2 = def->src3->value; if (!val1 && !val2) - return insert_branch(insn, insn->bb_false); + return convert_to_jump(insn, insn->bb_false); if (val1 && val2) - return insert_branch(insn, insn->bb_true); + return convert_to_jump(insn, insn->bb_true); if (val2) { struct basic_block *tmp = insn->bb_true; insn->bb_true = insn->bb_false; @@ -2509,7 +2509,7 @@ static int simplify_switch(struct instruction *insn) return 0; found: - return insert_branch(insn, jmp->target); + return convert_to_jump(insn, jmp->target); } static struct basic_block *is_label(pseudo_t pseudo) From patchwork Sun Mar 21 12:35:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 683D6C433E5 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 505C461946 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbhCUMf3 (ORCPT ); Sun, 21 Mar 2021 08:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbhCUMfU (ORCPT ); Sun, 21 Mar 2021 08:35:20 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A44AEC061762 for ; Sun, 21 Mar 2021 05:35:19 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id b7so16848366ejv.1 for ; Sun, 21 Mar 2021 05:35:19 -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 :mime-version:content-transfer-encoding; bh=HrT5JwJ4a/A3XHo1/pfX52BDzwc1WHWNFxARYbZ+WVE=; b=vRr04TiivGVHaxQJ4lWtB1icjCx7k79eQ7byY1i1zeYsKnVyrjhp1/ftdvFU2qL/Ke M8U8nscM56L0F/CgbBFdIHz274EYRYRIaVAter/yChv/iMHdrKAwUMNJHcs7TdjjRkW4 jkjvaLC52S5afKivVylyinLMnAJHpIj2qxZVPCVZUCiVuNRUvqcZhqlrtczT7SrxnmRM bRiJ9XhkbklUUA6TYqZQOc8r84At5KyGHuWKLp14iLpMW/iTasVlMfZicbbBfjdcoOCD Tg/U+QaGUWqLg8Z5trhIZovNoE4qau38wmdkqMrwR2Hh5R8hjiGMv0Hbmg7cUBugJNlz duGg== 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:mime-version:content-transfer-encoding; bh=HrT5JwJ4a/A3XHo1/pfX52BDzwc1WHWNFxARYbZ+WVE=; b=BdUIdR4BImTs8WieCFMtiWien4hmwvcBCR7RlPwnL6gyPCu0UyCzfp/2UoAcI9Hhv+ 21aBLig733gT/9h8iQSpiyIcgeNdE7jfP+uqmFOQwSPhbT0M4mCr5gqbRFwjzFSi9zoK tjb/wVSuE6j01j55yn/6kDlypS48rxNP0RFca2aeh0Dq2PuvdpAEdFbjmIvSVIGzIoZ2 jrtvmd2hk6+Mr65Y7vMO1eH77t9iIx8S8M3uGma9VXz17hlXlT1ugKjtspTdYK1kRH59 OYy9znItOzV+Ujzu6fUQondSnIXfWv0/qLl4Alae6d9rsWthNM5tOJ/Ta18tRcFUuIIq PRSA== X-Gm-Message-State: AOAM532lawG9nKYLymyhGrqlsgglEV57myHHkTMZzodbYSKLPWPwIjKa 0xPm47OXp0a1MEtzhKvWGPtqCmlDTMo= X-Google-Smtp-Source: ABdhPJxguhR8z0P3nakWnbx8yGCXDT0lXQnkTTjFhoog8mTUNswPYIkNbV1aAOzNcvcaxtzPBO+ABg== X-Received: by 2002:a17:906:9509:: with SMTP id u9mr14280172ejx.225.1616330118402; Sun, 21 Mar 2021 05:35:18 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:18 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 10/13] add remove_phisources() Date: Sun, 21 Mar 2021 13:35:02 +0100 Message-Id: <20210321123505.27993-11-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org When a parent is removed from a BB containing one or several phi-nodes, the corresponding phi-sources become irrelevant and need to be removed from the phi-nodes. Add an helper for doing this: remove_phisources(). Signed-off-by: Luc Van Oostenryck --- flow.c | 43 +++++++++++++++++++++++++++++++++++++++++++ flow.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/flow.c b/flow.c index 8106cfc0d10b..4952562a373d 100644 --- a/flow.c +++ b/flow.c @@ -22,6 +22,49 @@ unsigned long bb_generation; +/// +// remove phi-sources from a removed edge +// +// :note: It's possible to have several edges between the same BBs. +// It's common with switches but it's also possible with branches. +// This function will only remove a single phi-source per edge. +int remove_phisources(struct basic_block *par, struct basic_block *old) +{ + struct instruction *insn; + int changed = 0; + + FOR_EACH_PTR(old->insns, insn) { + pseudo_t phi; + + if (!insn->bb) + continue; + if (insn->opcode != OP_PHI) + return changed; + + // found a phi-node in the target BB, + // now look after its phi-sources. + FOR_EACH_PTR(insn->phi_list, phi) { + struct instruction *phisrc = phi->def; + + if (phi == VOID) + continue; + assert(phisrc->phi_node == insn); + if (phisrc->bb != par) + continue; + // found a phi-source corresponding to this edge: + // remove it but avoid the recursive killing. + REPLACE_CURRENT_PTR(phi, VOID); + remove_use(&phisrc->src); + phisrc->bb = NULL; + changed |= REPEAT_CSE; + // Only the first one must be removed. + goto next; + } END_FOR_EACH_PTR(phi); +next: ; + } END_FOR_EACH_PTR(insn); + return changed; +} + /* * Dammit, if we have a phi-node followed by a conditional * branch on that phi-node, we should damn well be able to diff --git a/flow.h b/flow.h index 2103a10fe428..c489ebe03034 100644 --- a/flow.h +++ b/flow.h @@ -11,6 +11,8 @@ extern unsigned long bb_generation; struct entrypoint; struct instruction; +extern int remove_phisources(struct basic_block *par, struct basic_block *old); + extern int simplify_flow(struct entrypoint *ep); extern void kill_dead_stores(struct entrypoint *ep, pseudo_t addr, int local); From patchwork Sun Mar 21 12:35:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75E87C433E9 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 613976194D for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229884AbhCUMf2 (ORCPT ); Sun, 21 Mar 2021 08:35:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbhCUMfU (ORCPT ); Sun, 21 Mar 2021 08:35:20 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D9E3C061574 for ; Sun, 21 Mar 2021 05:35:20 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id j3so16028560edp.11 for ; Sun, 21 Mar 2021 05:35:20 -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 :mime-version:content-transfer-encoding; bh=gb/WVZ1THkivgKLK4xRh0ywfmgqDYSFXZFQyeEHJhos=; b=GcHMio2ZAjadcHnwvoLstBumWAlrYV6HyGub2FKtaxNPDIich8Uj7K3wi5jgv4E8AZ cMA0CYsWqnMSbpbiWUCX+/U3oqtmkNpEbVjdok5uVrWs9H0GcUbaYj+V2/dBeFOo9ARZ MdOvb5sJRs80ieh2s9Hl1x0vrNsI0ZaDaNvPM8Cv3djq8t31YCCtzRiOnfkYlUj8NjQv 9jLy4vEEE1EFQLqEQbZkpJValVAtDul1w4zOTVREmpQHF7pbUWYDi8fkqWvb5IB/0Cmr hEO4TsoFhjZ0DT7AQKX1lM23xDg9PiVZzlX3e3YmJMZ2CaGQYI2VseXJBRiajzw1Wcc7 Ni5w== 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:mime-version:content-transfer-encoding; bh=gb/WVZ1THkivgKLK4xRh0ywfmgqDYSFXZFQyeEHJhos=; b=k5Ymm0oxm/U7BQ+eukL0BU7DBpPYVtO7K4PobvoH08VlE6Pko+PQ8f7EYjOjiZOc4z p6tAOC1jYeXP0MfTB7jEjaefbgvkHxorb8Akebv4BFrOlrjGLhVbpjtWgIabHC350+As x0OYw1lOxb0rPDPXQhWkRWdqiN0VAF99PbTSp77In9t+5xcdjIl+XKaR0LGOyKEDIzwx PCloDBF5tLJ1OHHkhg8PXqrBLmztCrZq4dV1BjYBGrUmaYEHoB/V+/RWlgpJJMJ88PPj tlW9/DXWiWU1Lw38jO0M1d/ZLzAsI5wAbMAEc5bO2vRWEpRYS+IUg1Zp0R4t7Vq80kPl ntXA== X-Gm-Message-State: AOAM533eWltlR4MJwPETomXFxmT1naxO/bjVJKAc6Gbyk0q6gFy+1gT+ k8GX0aPxSVdUhdv9ylxcme1mW3ebiFw= X-Google-Smtp-Source: ABdhPJwItPAR/mfBTbdhYqksnRIdlbdifPYgomihuzWk9sszn4ia1ABAow4XpiCpsqLhofobuwyiJQ== X-Received: by 2002:a05:6402:447:: with SMTP id p7mr20378196edw.89.1616330119097; Sun, 21 Mar 2021 05:35:19 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:18 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 11/13] fix phisources during CBR-BR conversion Date: Sun, 21 Mar 2021 13:35:03 +0100 Message-Id: <20210321123505.27993-12-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org When a parent is removed from a BB containing one or several phi-nodes, the corresponding phi-sources must be removed from the phi-node. However this is not done and consequentially: * it becomes impossibly to correctly reason about the flow of values through these phi-nodes. * simplifications are missed (e.g. if-conversion). Signed-off-by: Luc Van Oostenryck --- flow.c | 5 +++++ validation/optim/bad-phisrc1.c | 1 - validation/optim/bad-phisrc1a.c | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/flow.c b/flow.c index 4952562a373d..69d95a98a512 100644 --- a/flow.c +++ b/flow.c @@ -760,6 +760,11 @@ int convert_to_jump(struct instruction *insn, struct basic_block *target) struct basic_block *child; int changed = REPEAT_CSE; + switch (insn->opcode) { + case OP_CBR: + changed |= remove_phisources(insn->bb, insn->bb_true == target ? insn->bb_false : insn->bb_true); + break; + } kill_use(&insn->cond); insn->bb_true = target; insn->bb_false = NULL; diff --git a/validation/optim/bad-phisrc1.c b/validation/optim/bad-phisrc1.c index 59c5e4f1e66a..aa12dd0ae542 100644 --- a/validation/optim/bad-phisrc1.c +++ b/validation/optim/bad-phisrc1.c @@ -8,7 +8,6 @@ void foo(int a, int b) /* * check-name: bad-phisrc1 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: phi\\. diff --git a/validation/optim/bad-phisrc1a.c b/validation/optim/bad-phisrc1a.c index cf07573b1fd3..b7519ee7cf5d 100644 --- a/validation/optim/bad-phisrc1a.c +++ b/validation/optim/bad-phisrc1a.c @@ -16,7 +16,6 @@ out: /* * check-name: bad-phisrc1a * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: select\\. From patchwork Sun Mar 21 12:35:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99693C433EA for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81C4361946 for ; Sun, 21 Mar 2021 12:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229900AbhCUMf3 (ORCPT ); Sun, 21 Mar 2021 08:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbhCUMfV (ORCPT ); Sun, 21 Mar 2021 08:35:21 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08045C061574 for ; Sun, 21 Mar 2021 05:35:21 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id bf3so16078985edb.6 for ; Sun, 21 Mar 2021 05:35:20 -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 :mime-version:content-transfer-encoding; bh=yogb3xLL1K4x00FKimazPH2zLp4VAS/QnZoB6MtsZTQ=; b=r78ZNuBcWzDoTc8fg1kcM63xJg9xVCK4/hOVei2VapP5yCCXFyXU8rcRaGD0SBqDbf JO942PEvTgpW10eKs/r9HRfwrBYSoiZKyxa1IijZEjgtenkm9XkgI/P8YgGe9EkZZJ/5 OHiKRoOSM9m3Fabme+1+fRis63fGT78mB03FqETA+9Dc1ZlK0dYb4XmenpPRyiNHUMDI XYICVbyJe1uCmVzcRqD9XmTIBeB7VdnUQq4MDtmwVbbwPxrc+mHJuKDH++Ofsp7oZZqg iHwEzxUSx76Bczc9W5LS0xq4/I3CQ90hqP0CvFCIiFNbhQ1ghSpejWIh3G01Mr4zvqIE /gUQ== 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:mime-version:content-transfer-encoding; bh=yogb3xLL1K4x00FKimazPH2zLp4VAS/QnZoB6MtsZTQ=; b=rST888udS2/PdNH801SDGnN24o7mASLXFPWesNLiN9Hy2K5ILcHp/89uiCxORQSvLL H70g3AV1+EAzdwDP5vA/3xfeVaHOBNDYCX4fumxuT2NI7cuhWWNJSUylEICl2ZeOfZhg Xv8UeDt1i83fZE/mjmqnFomvsnCKf4xXSSVAqFWiwVkGan+b7/7W2Xn38ma51UIGPwvx hD5Q0bLtreGUXU1hEdP31UslpPt/RgQOLdL1VCqmLGm57IVK4jW5gUWOd/UejDjtLmvu sHRDq8KArm10kyiMT+YcYnN0/jGS1oOTzCjrdy1FHOIcJhXtiXtrZFoZQzbR4oLB5yDC 2NbQ== X-Gm-Message-State: AOAM533dHHd/1JP6A8bruH4YMcFt/26yLa0/6HDIG6rQ1pQ+V2kZEDtK x2Mhzfu73yc+KHbxgI7prq+sOugEQCc= X-Google-Smtp-Source: ABdhPJzyoQJUU98QlqPlAz9Y3zkUqnb4V9rheeE8PcnxypgHHqrpMLCwRbAPaCSzj+QHLX1888H9NQ== X-Received: by 2002:aa7:cf90:: with SMTP id z16mr20348799edx.273.1616330119837; Sun, 21 Mar 2021 05:35:19 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:19 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 12/13] use convert_to_jump() when converting a CBR with same targets Date: Sun, 21 Mar 2021 13:35:04 +0100 Message-Id: <20210321123505.27993-13-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org If a conditional branch has identical targets, it should be converted to a simple jump. This is done but using its own code. Change this by using the existing convert_to_jump() instead. This also allows any redundant phi-sources to be removed. Signed-off-by: Luc Van Oostenryck --- simplify.c | 13 ++----------- validation/optim/bad-phisrc2.c | 1 - 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/simplify.c b/simplify.c index 7171bd564e63..90db041af823 100644 --- a/simplify.c +++ b/simplify.c @@ -2444,17 +2444,8 @@ static int simplify_branch(struct instruction *insn) return convert_to_jump(insn, cond->value ? insn->bb_true : insn->bb_false); /* Same target? */ - if (insn->bb_true == insn->bb_false) { - struct basic_block *bb = insn->bb; - struct basic_block *target = insn->bb_false; - remove_bb_from_list(&target->parents, bb, 1); - remove_bb_from_list(&bb->children, target, 1); - insn->bb_false = NULL; - kill_use(&insn->cond); - insn->cond = NULL; - insn->opcode = OP_BR; - return REPEAT_CSE|REPEAT_CFG_CLEANUP; - } + if (insn->bb_true == insn->bb_false) + return convert_to_jump(insn, insn->bb_true); /* Conditional on a SETNE $0 or SETEQ $0 */ if (cond->type == PSEUDO_REG) { diff --git a/validation/optim/bad-phisrc2.c b/validation/optim/bad-phisrc2.c index 3eade688f768..78eae28856fd 100644 --- a/validation/optim/bad-phisrc2.c +++ b/validation/optim/bad-phisrc2.c @@ -10,7 +10,6 @@ int bad_phisrc2(int p, int a, int r) /* * check-name: bad-phisrc2 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: select\\. From patchwork Sun Mar 21 12:35:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 12153043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A16D6C433DB for ; Sun, 21 Mar 2021 12:36:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75F4A61946 for ; Sun, 21 Mar 2021 12:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbhCUMf4 (ORCPT ); Sun, 21 Mar 2021 08:35:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbhCUMfW (ORCPT ); Sun, 21 Mar 2021 08:35:22 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB736C061574 for ; Sun, 21 Mar 2021 05:35:21 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id w18so16117757edc.0 for ; Sun, 21 Mar 2021 05:35:21 -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 :mime-version:content-transfer-encoding; bh=EI+5XLOO0hisJjiz4RuWRMzTbKvIHVxn7TndTRh0yYE=; b=lGg2vZxH/fHpcbQnX2HdnHZGs9/kTeiw7DR7R0lViyNDqCdAritnI3M3ojAaLo3JHn RVNPtSDEyB2hIfqnUd85aKdBICOFXN3W8W+Ibvi2luDksFT7c79BwjUlPGRRFFhCETEV FMO3GjXk2QiE/aPG0b6vu8iycNfJJymNF7nQqHXK+eFwIBbE6WctLmNothssyuZ70THs TuEQbT4cEKeOn4P1tpVNZkhnhAH3csTExR8VgIUKGVFAsA4XUOKiZKgcIx2dqnzmNMi9 L2Mrgg7vU5m8fFXy1rhUHg7ElAYFfqSLD2pnXCBPBLQp6DaAlUaQzFrJDtoa4mp3L+Yf HFyA== 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:mime-version:content-transfer-encoding; bh=EI+5XLOO0hisJjiz4RuWRMzTbKvIHVxn7TndTRh0yYE=; b=t457x2KAnoWrJS1xVrisUw8rH68cOZo71+jtTvR8T7iE4tyRvXBAAbY8NmhQBGlRYf wGxL18XRQ/KtQyQ2s0V0d2jkYtv9RC9STuAxE1tEhAYnnc9v0b1gnoD//qwLkMFpZGtx Qw7XteFFm39i+lh+RRTesLbHoUe9tQCTCUAinx4yHtbBQ+PirjQ+MxqDL5SB63I8u8j2 IOQ/Qkh41mBIP1QSIVsX5hXg9sqeWXxl7Oa4PXK5hLiIaK5mVkFFwoxJA//Po+OMb7d9 uLfOd3lEWI3j21qySjcJr0ncUQIfCEokpYjllTIkqoVoNte21Lk2kCGTJ9g0G3o9wzrz isrQ== X-Gm-Message-State: AOAM532rGO5j+nV+LtXD9Zqoy8iA56p4C7Vnm/pJC5u8IJu1wqs/fg/j QsXrb0yokThYL7iA+zPv3elZN3xN/es= X-Google-Smtp-Source: ABdhPJyfuWzMJV0LQrCbdOS4sJPTcZa8Zf5Dwzr7MITo+BH57blaHOkWWtWk6B5MVzcTlSG3PhjZWQ== X-Received: by 2002:aa7:c709:: with SMTP id i9mr20533593edq.319.1616330120683; Sun, 21 Mar 2021 05:35:20 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:b090:4406:df97:c155]) by smtp.gmail.com with ESMTPSA id jv19sm6998641ejc.74.2021.03.21.05.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 05:35:20 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 13/13] fix phisources during SWITCH-BR conversion Date: Sun, 21 Mar 2021 13:35:05 +0100 Message-Id: <20210321123505.27993-14-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> References: <20210321123505.27993-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Like for CBR-BR conversion, when a target BB containing one or several phi-nodes is removed from an OP_SWITCH, the corresponding phi-source must be removed from the phi-node. However this is not done yet. Changing this by adding some code to convert_to_jump() to remove all phi-sources from the discarded targets if the converted instruction is an OP_SWITCH. Signed-off-by: Luc Van Oostenryck --- flow.c | 20 ++++++++++++++++++++ validation/optim/bad-phisrc3.c | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/flow.c b/flow.c index 69d95a98a512..cb94fcf20834 100644 --- a/flow.c +++ b/flow.c @@ -65,6 +65,23 @@ next: ; return changed; } +/// +// remove all phisources but the one corresponding to the given target +static int remove_other_phisources(struct basic_block *bb, struct multijmp_list *list, struct basic_block *target) +{ + struct multijmp *jmp; + int changed = 0; + + FOR_EACH_PTR(list, jmp) { + if (jmp->target == target) { + target = NULL; + continue; + } + changed |= remove_phisources(bb, jmp->target); + } END_FOR_EACH_PTR(jmp); + return changed; +} + /* * Dammit, if we have a phi-node followed by a conditional * branch on that phi-node, we should damn well be able to @@ -764,6 +781,9 @@ int convert_to_jump(struct instruction *insn, struct basic_block *target) case OP_CBR: changed |= remove_phisources(insn->bb, insn->bb_true == target ? insn->bb_false : insn->bb_true); break; + case OP_SWITCH: + changed |= remove_other_phisources(insn->bb, insn->multijmp_list, target); + break; } kill_use(&insn->cond); insn->bb_true = target; diff --git a/validation/optim/bad-phisrc3.c b/validation/optim/bad-phisrc3.c index 6e437771b4b8..41537420d6fa 100644 --- a/validation/optim/bad-phisrc3.c +++ b/validation/optim/bad-phisrc3.c @@ -13,7 +13,6 @@ void foo(void) /* * check-name: bad-phisrc3 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(2): phisrc\\.