From patchwork Sat Apr 10 22:30:40 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: 12195961 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.7 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 BD1B9C433ED for ; Sat, 10 Apr 2021 22:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8274A61106 for ; Sat, 10 Apr 2021 22:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232659AbhDJWbP (ORCPT ); Sat, 10 Apr 2021 18:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235102AbhDJWbO (ORCPT ); Sat, 10 Apr 2021 18:31:14 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B545C06138B for ; Sat, 10 Apr 2021 15:30:58 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id w3so14189489ejc.4 for ; Sat, 10 Apr 2021 15:30: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 :mime-version:content-transfer-encoding; bh=5oxTn68I0PL9raL5wwogcYdhxb94zet/WC/d5B/Uq/8=; b=c5fIbPtxQFBCIelUn/rqMETyQHNhQSrZhD4z/t02/wO11/OYPeLf/UTLQSsf2zbQES /iEqqFJIR8DyRF6ft7ofmlJcswRo/Dx+pdt7Jh87QuX7gtuXPeU5LZ2B6U//5gQrzcI+ dqBmcCbN68Xe4en3+iawXfQBy3zq6OszxgNxZMUTeFUzmZwAyO8iT6WWr7pstA/pH4yO 9OpdgY07dscxcqeN17jrf1fEH3lCETPa5Jo8/pX2ZppYWLq5EZH+5o24pXfBKzloeHK7 Vu1TiVIoWM8kQZuUFMsgY5z8oolZ5G3DN89CboYu2Hw8NXXs1H/2pWLde3EhqiMbBUXE 4fjQ== 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=5oxTn68I0PL9raL5wwogcYdhxb94zet/WC/d5B/Uq/8=; b=PG39BoVG/Doszzr+p5ihf/5AmyYX1CHVkiU8KOn2Y1hmS/KdA3+IczgjOFhul3p1S6 5yOJTdg3sXgOPLYYEuPI5qIBxD/IStYbyp5HDXdAKglv4+/fUAJN5PvQo6ugUBU9UGyD crwhbKcSeVEFvA2DOlxsGVWTVS6XkiA291AMa/obb2Fndt1Yg8ZWzV/mV/ydVPGmZ8YF fq+n+p+nKVriMsSllhhrWPe8CBqY4vJzS0VaQj7+8nHhlf5LMUc77eur70kNi9iEDOrS o9/PLDWGuGMpRqOR1E0Ohsi9/heRLMFMjddga3nTbFOY2QVqyxOC8HmQD17BvI+Jg/uR m1fA== X-Gm-Message-State: AOAM5300oGIUMOiSgLg8cAcLLHh7sXx5LVRn7V1y+CKyyGofp01KPNwV 2SA8Fe8C5sy95C44JYYOrRAQqxarwYw= X-Google-Smtp-Source: ABdhPJyjk8KGchJlP7PFDMmimsmoo8Y23oEw/7jiiwffH31miTmHsFqhcvk/o2ebBnHfRWt7EV5PKA== X-Received: by 2002:a17:906:48c4:: with SMTP id d4mr1812818ejt.548.1618093856842; Sat, 10 Apr 2021 15:30:56 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:9597:4a1:b5b6:4666]) by smtp.gmail.com with ESMTPSA id q18sm3701372edr.26.2021.04.10.15.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 15:30:56 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 1/5] add testcases for stores simplifications Date: Sun, 11 Apr 2021 00:30:40 +0200 Message-Id: <20210410223044.86100-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> References: <20210410223044.86100-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/memops/kill-dead-store-parent0.c | 15 ++++++++++++ validation/memops/kill-dead-store-parent2.c | 26 +++++++++++++++++++++ validation/memops/kill-redundant-store0.c | 14 +++++++++++ 3 files changed, 55 insertions(+) create mode 100644 validation/memops/kill-dead-store-parent0.c create mode 100644 validation/memops/kill-dead-store-parent2.c create mode 100644 validation/memops/kill-redundant-store0.c diff --git a/validation/memops/kill-dead-store-parent0.c b/validation/memops/kill-dead-store-parent0.c new file mode 100644 index 000000000000..1413134b8c23 --- /dev/null +++ b/validation/memops/kill-dead-store-parent0.c @@ -0,0 +1,15 @@ +void foo(int *ptr, int p) +{ + if (p) + *ptr = 1; + *ptr = 0; +} + +/* + * check-name: kill-dead-store-parent0 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(1): store + */ diff --git a/validation/memops/kill-dead-store-parent2.c b/validation/memops/kill-dead-store-parent2.c new file mode 100644 index 000000000000..b563fd31b669 --- /dev/null +++ b/validation/memops/kill-dead-store-parent2.c @@ -0,0 +1,26 @@ +int ladder02(int *ptr, int p, int x) +{ + *ptr = x++; + if (p) + goto l11; + else + goto l12; +l11: + *ptr = x++; + goto l20; +l12: + *ptr = x++; + goto l20; +l20: + *ptr = x++; + return *ptr; +} + +/* + * check-name: kill-dead-store-parent2 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(1): store + */ diff --git a/validation/memops/kill-redundant-store0.c b/validation/memops/kill-redundant-store0.c new file mode 100644 index 000000000000..e911166dd953 --- /dev/null +++ b/validation/memops/kill-redundant-store0.c @@ -0,0 +1,14 @@ +void foo(int *ptr) +{ + int i = *ptr; + *ptr = i; +} + +/* + * check-name: kill-redundant-store0 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-excludes: store + */ From patchwork Sat Apr 10 22:30:41 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: 12195965 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.7 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 7BBABC43462 for ; Sat, 10 Apr 2021 22:31:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C63C61106 for ; Sat, 10 Apr 2021 22:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235147AbhDJWbP (ORCPT ); Sat, 10 Apr 2021 18:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235102AbhDJWbP (ORCPT ); Sat, 10 Apr 2021 18:31:15 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFCE6C06138A for ; Sat, 10 Apr 2021 15:30:58 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id g17so9879896edm.6 for ; Sat, 10 Apr 2021 15:30:58 -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=zNjbWbULEADIj5i8KD6Ye7x71IlUG+wu/DFWWrEALHE=; b=MU5PmpVbMptQ98SDMtn4tFwA/2Gx+8mlvumx+HR1keobAQEAoyxSAHkJa0TKsjwRIG vmbEMwJ27GTVG6F+whDbtH2WQNI74woZgQE3lTiOXf61PlWscJg4LeNlvVczdVwb9uOy 1CP6SdtZcTGwqfvxq25+NjA+VzoAbgH9fPobTj3upwjt/N0jNNq1qzpD24goG67Eg7RW wY4Xu3rRsYGN0T7ouA+Rjw1u27DgwldRWUoDQODkYQj5ViO0BLY4IuGFLM1GbQfxpTLt SMNTCuspzJ5a4dYn6Ek2aWcsuXnJ/XveQBegsARCdyazRg72ijHqnHowIaWoAJb7NYGD FCNw== 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=zNjbWbULEADIj5i8KD6Ye7x71IlUG+wu/DFWWrEALHE=; b=GBA1E1mXjIhwWiVsnw/r6QJKOdI37+wE1wHnZaGt9DR68H4akTMBjBhLRAHJI1h9RB 9znRc0oTDChdQBUKfL4efW3FBu0Eb9ucAZrwadTVf5gRyF2uH44k0iYLODSy8M9aOg5B eRndsk4RIkkFsMKR0YiPx7+dzJZ9Wj+5BlUrgW8L67Ji0UgwiYn94aan2++yWHDF9GMf Hrxa2aSMFKGDBiFqRdLdEtRC9WJf8p+Jx3A07Nyi8ucQhY3GEn1bCwEES2XDPIA45AEf y2/EKtq3P5LnVVvkQwNELLebxgMlu/KywFtMTNZP20STCuCamkaZCJbhKKPVDKKTOFtb JCQQ== X-Gm-Message-State: AOAM530JazEsqx0VIo8CR32ZbK7AYUpcrJgoJHubk8idOeQx2eUZvua3 JO1ktP9R3B7zIxWe3HI9Nz2fRZD/dv0= X-Google-Smtp-Source: ABdhPJw6lO2F0dlMxq8NVR6FNsksA3RD5fjtQperoIT6rOajfFMBiVrWRE+oSKPi8JEtFAvp4P0t/g== X-Received: by 2002:aa7:d2cc:: with SMTP id k12mr22734610edr.374.1618093857456; Sat, 10 Apr 2021 15:30:57 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:9597:4a1:b5b6:4666]) by smtp.gmail.com with ESMTPSA id q18sm3701372edr.26.2021.04.10.15.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 15:30:57 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 2/5] extract try_to_kill_store() from kill_dominated_stores() Date: Sun, 11 Apr 2021 00:30:41 +0200 Message-Id: <20210410223044.86100-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> References: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Move the test/replace part of the store simplification in a separate function so that it can be reused. Signed-off-by: Luc Van Oostenryck --- memops.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/memops.c b/memops.c index ff54208e2d54..31fd2d3eaffc 100644 --- a/memops.c +++ b/memops.c @@ -204,6 +204,23 @@ next_load: } END_FOR_EACH_PTR_REVERSE(insn); } +static bool try_to_kill_store(pseudo_t pseudo, struct instruction *insn, + struct instruction *dom, int local) +{ + int dominance = dominates(pseudo, insn, dom, local); + + if (dominance) { + /* possible partial dominance? */ + if (dominance < 0) + return false; + if (dom->opcode == OP_LOAD) + return false; + /* Yeehaa! Found one! */ + kill_instruction_force(dom); + } + return true; +} + static void kill_dominated_stores(struct basic_block *bb) { struct instruction *insn; @@ -223,19 +240,10 @@ static void kill_dominated_stores(struct basic_block *bb) local = local_pseudo(pseudo); RECURSE_PTR_REVERSE(insn, dom) { - int dominance; if (!dom->bb) continue; - dominance = dominates(pseudo, insn, dom, local); - if (dominance) { - /* possible partial dominance? */ - if (dominance < 0) - goto next_store; - if (dom->opcode == OP_LOAD) - goto next_store; - /* Yeehaa! Found one! */ - kill_instruction_force(dom); - } + if (!try_to_kill_store(pseudo, insn, dom, local)) + goto next_store; } END_FOR_EACH_PTR_REVERSE(dom); /* OK, we should check the parents now */ From patchwork Sat Apr 10 22:30:42 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: 12195959 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.7 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 8E164C43460 for ; Sat, 10 Apr 2021 22:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DCD961027 for ; Sat, 10 Apr 2021 22:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235145AbhDJWbO (ORCPT ); Sat, 10 Apr 2021 18:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232659AbhDJWbO (ORCPT ); Sat, 10 Apr 2021 18:31:14 -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 45161C06138C for ; Sat, 10 Apr 2021 15:30:59 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id r12so14196546ejr.5 for ; Sat, 10 Apr 2021 15:30:59 -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=DFiL5Q/NJtXHul7Bsk79dXVlUhHS1d6847PbaJPfV/M=; b=qnO0PzneN2RnKG5caAMxpvH4HKUDVFRRA7XW1gFsSoMFRIODnGG59bGZL9H60p42ib yQpY1+ShDxppINglm1VrMwrhB6Lp2s0qyl9zJvqLCa4WMxRWfadRafq9MPrgAord3wFi nsGvggo+CB2udldZoonQWj5sRt1sL4I9QFdPQDM3PfA91khs0AM71UJRydOL8yTAVj7R MgQ/vErfFNt8QGpeufoWy1sBcoQfYwiHXJtDvIBH7lsPDQN2bpGBOcPUsdG5xEilJ8RC 7NqRVfgXXh/Hz5PbwgSIMEmnyV05PAiOpaP2CiWRlgio29HFadK10Qi+MHYQZeHc1EyF NCgg== 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=DFiL5Q/NJtXHul7Bsk79dXVlUhHS1d6847PbaJPfV/M=; b=J/fYxunMKCwRXtoJzbJOLQjbW/wRctSIVNcXnb36Dr7TnTuoopn7wAsSy2oai3x5Cz a24fYoLYbWQsQlkM73fXX0W1rviolL8q2GQiKJeqzIYf+28w30lVfXjyugnmPXH8M0rO TiY4SdA9O+iPattOyd0Q5+hSKiQQg5BXWSVfpSz4HNlnTeFB0Obzn2PYkCgS5NOsUi91 vUAoZBn3BwFnqVcDpl0mxLIZ/dNk2eJlDMQ4BZUrdUYrfJvhCQc9V6vHflgEshabKOyG tYbcoI/RejYk/WI3juKZ/SDQRQ9oH+MUk5AH5EeckjVG3yBY8K1DC+UxU9nTt9hMbrbU 9NIQ== X-Gm-Message-State: AOAM532osG/o2oyN0MQLWefXfRFFgjy8ptvfgiyjIYWF5d74QJQZPks+ M09mjFHftTfcmwZRnBKkqKwjVvlHD6k= X-Google-Smtp-Source: ABdhPJz+rBSDGe3t5ZNSOhwT6sBt4lN+k1lPHlZgzqpRb9p/PeFZltgOOcNMLBzOI41Yjgnrh/dMCQ== X-Received: by 2002:a17:907:110f:: with SMTP id qu15mr21307880ejb.336.1618093858068; Sat, 10 Apr 2021 15:30:58 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:9597:4a1:b5b6:4666]) by smtp.gmail.com with ESMTPSA id q18sm3701372edr.26.2021.04.10.15.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 15:30:57 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 3/5] volatile stores are never dead Date: Sun, 11 Apr 2021 00:30:42 +0200 Message-Id: <20210410223044.86100-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> References: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org so they shouldn't be killed. Signed-off-by: Luc Van Oostenryck --- memops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/memops.c b/memops.c index 31fd2d3eaffc..8020f2e6cf03 100644 --- a/memops.c +++ b/memops.c @@ -215,6 +215,8 @@ static bool try_to_kill_store(pseudo_t pseudo, struct instruction *insn, return false; if (dom->opcode == OP_LOAD) return false; + if (dom->is_volatile) + return false; /* Yeehaa! Found one! */ kill_instruction_force(dom); } From patchwork Sat Apr 10 22:30:43 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: 12195963 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.7 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 5FF6FC433B4 for ; Sat, 10 Apr 2021 22:31:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 343C5610F9 for ; Sat, 10 Apr 2021 22:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235148AbhDJWbP (ORCPT ); Sat, 10 Apr 2021 18:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235147AbhDJWbP (ORCPT ); Sat, 10 Apr 2021 18:31:15 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0088C06138B for ; Sat, 10 Apr 2021 15:30:59 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id hq27so14152278ejc.9 for ; Sat, 10 Apr 2021 15:30:59 -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=ZJxSWNJXLP4Klq0CxC6W/eeVgYRJ+EWbn2Ev/1pbFlk=; b=PPkvztYQaUzmQnOdKYBnHTa8AKANf/QgzP1D3o3hAZZWjXksibF1GlDyDU/oZVh9og IaDgFVYvMoKkCcrpaZ3iSJNriNT9r08F8jvDxeeFeVBItK7L9Z/Yuabf7PNSbbV+fque qd075wy1ke3+i65C1BnolXJHuZ1qP8nyxP6ijlsdlF0UBsIHQnCXn7T6nFd2nUCGuc9Y zeG5KojdZQdsTl6m3tIATV/RvN2lqMPbRMJu4lEs9DsPRm3h7nR28Asf3BkgnhfQnuM+ nSRIF0Din4Mp0i2zfYunDreROE80ptK1dlPiw9tnN605ZUUyrkSC+3nDef3khUe5wkwE ep0g== 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=ZJxSWNJXLP4Klq0CxC6W/eeVgYRJ+EWbn2Ev/1pbFlk=; b=XKenM4z5FxABDzd1QqVtAzhIEOkglSRBj1vlawbJOPRu6Xh88mPQUjxA9GAIX+2zuI nUfkzxNeWMQ1gtG9lCzKVIqm2pBWRk6Jnca7lB52cmsNEvG0rqo7KlLoXlynAmIishYK heaWTYzBJ9QKAFGvj7WgGkGBenJuDOaj1/JjiBmzQwzvArUoZj5B2uL6hCUzJj39ydxO gyqs4/J0/IOPGLO6UPJWXUAqv2KqdzyA9/cqmV6jta1eeLCEGinBiaa2Qtr9+Wol6nh0 MfFI9CHrXcSNpVApp5BG76hUwk3/OScdHUf0v2Y5HJaDjc0ITKCRVcFpWRxkiCotYM44 Dw3Q== X-Gm-Message-State: AOAM532ncxCWp2NmeMoC/+496iihDCcAzMBW66xYiKnhoblm6pWwg4ro g7C4I3oLZZD8depTDbyUNiC1AVr3Kfk= X-Google-Smtp-Source: ABdhPJzMF0HONG2MGZLaEyHDs6PdsM9E0XDI0etqp3Sz0cIPPp2reRFykHo9pbWLLtC5eXaCF+ZIbQ== X-Received: by 2002:a17:906:4017:: with SMTP id v23mr15316086ejj.421.1618093858740; Sat, 10 Apr 2021 15:30:58 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:9597:4a1:b5b6:4666]) by smtp.gmail.com with ESMTPSA id q18sm3701372edr.26.2021.04.10.15.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 15:30:58 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 4/5] kill parent's dead stores too Date: Sun, 11 Apr 2021 00:30:43 +0200 Message-Id: <20210410223044.86100-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> References: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org kill_dominated_stores() identify and remove dead stores (stores unneeded because the same location is overwritten later by another store) only when both stores are in the same basic block. Slightly improve this by also handling the case when the dead store is in a parent BB of the "live" store. Signed-off-by: Luc Van Oostenryck --- memops.c | 16 ++++++++++++++++ validation/memops/kill-dead-store-parent0.c | 1 - validation/memops/kill-dead-store-parent2.c | 1 - 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/memops.c b/memops.c index 8020f2e6cf03..44d90754d279 100644 --- a/memops.c +++ b/memops.c @@ -231,6 +231,7 @@ static void kill_dominated_stores(struct basic_block *bb) if (!insn->bb) continue; if (insn->opcode == OP_STORE) { + struct basic_block *par; struct instruction *dom; pseudo_t pseudo = insn->src; int local; @@ -249,6 +250,21 @@ static void kill_dominated_stores(struct basic_block *bb) } END_FOR_EACH_PTR_REVERSE(dom); /* OK, we should check the parents now */ + FOR_EACH_PTR(bb->parents, par) { + + if (bb_list_size(par->children) != 1) + goto next_parent; + FOR_EACH_PTR(par->insns, dom) { + if (!dom->bb) + continue; + if (dom == insn) + goto next_parent; + if (!try_to_kill_store(pseudo, insn, dom, local)) + goto next_parent; + } END_FOR_EACH_PTR(dom); +next_parent: + ; + } END_FOR_EACH_PTR(par); } next_store: /* Do the next one */; diff --git a/validation/memops/kill-dead-store-parent0.c b/validation/memops/kill-dead-store-parent0.c index 1413134b8c23..c1b2466ca450 100644 --- a/validation/memops/kill-dead-store-parent0.c +++ b/validation/memops/kill-dead-store-parent0.c @@ -8,7 +8,6 @@ void foo(int *ptr, int p) /* * check-name: kill-dead-store-parent0 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(1): store diff --git a/validation/memops/kill-dead-store-parent2.c b/validation/memops/kill-dead-store-parent2.c index b563fd31b669..4f7b9dd901d9 100644 --- a/validation/memops/kill-dead-store-parent2.c +++ b/validation/memops/kill-dead-store-parent2.c @@ -19,7 +19,6 @@ l20: /* * check-name: kill-dead-store-parent2 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(1): store From patchwork Sat Apr 10 22:30:44 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: 12195967 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.7 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 C9E6BC433ED for ; Sat, 10 Apr 2021 22:31:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F61861027 for ; Sat, 10 Apr 2021 22:31:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235151AbhDJWbR (ORCPT ); Sat, 10 Apr 2021 18:31:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235102AbhDJWbQ (ORCPT ); Sat, 10 Apr 2021 18:31:16 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C620C06138B for ; Sat, 10 Apr 2021 15:31:00 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id w3so14189592ejc.4 for ; Sat, 10 Apr 2021 15:31:00 -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=4CotMeQ5qPPDYqW9tfxhbyxy84tUItExmb2zJwdXgv8=; b=ocJhGLjVP+DiyyESfBdwlPjp+aqeScWSV01m8A8PBLe1jqlbYT96jXpXRB2mzeXum7 4i3XlfrlQy5adg5oGuhOlyHHYEQko0ShqlLDe1NxVNJecpGI/dEU7DL+zFUiBFYW3Vp3 JVZHtE5wvepRH/gMo9CvsT3p/eovs74MAi+PZqxR86F/0B79vtA9k+9reikuiHRwlHF9 hcd1y5hTPSJrUITyDzz+49pD0Yfn4LEkak2SlLl9qzlBx9HvK8rQBcH06pipl2roS+Rl EZIwsX2xuW48mcZC/2cWWbJhRfd0SXdSqLpvHEeC9BXVONWAVuy/XK+q/DRoCGHcEs92 kTBQ== 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=4CotMeQ5qPPDYqW9tfxhbyxy84tUItExmb2zJwdXgv8=; b=ljdJLKAnzMzzmytxsTFP5FGXFTpRQTQtfJG4pFxT4KjUPrU1kw0TySgSaZNZSxBSAr zFmJ2PRmnpBHYza5y3lTlZ1LJ/p0/smBoW+Xjv2Q5jwW1sQmSKAhRihik8ysPE17wWxF 62+YJvEI/vEhsm+4UdB5AS3oJsQhIp7NMNhmahmS24WOBL1RL+/M/7Hk+dD9fXduERbl EaSbcWwc6nEO+5RW5wYe4x8Qw5IZsTDDuvV43LDhMXmrAwHFGWUN7gQV/u+apIeAl3J5 2Sd7ik+nMDzvvoHgv5nr3r8zxxGw3UtrrP6MXdXDiExcOhcNBOprNkaMC+8YUsJOq7cx UIoQ== X-Gm-Message-State: AOAM531QyY/VEuQ+O+w6GbJbDVtWC3UnhicFFD7vKmllAbhJsSJLq+hn f8x8MHdMm6n4PCcbNsNFDs18sJ14wVQ= X-Google-Smtp-Source: ABdhPJwYfQ12zUeXfHLiMAGCfmtLXXVuqYlqgKQi9LVeyCiTgSHx6ZOKcFl0H1o9RgjtBt8D5+Y2Xg== X-Received: by 2002:a17:906:3643:: with SMTP id r3mr21010921ejb.527.1618093859458; Sat, 10 Apr 2021 15:30:59 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:9597:4a1:b5b6:4666]) by smtp.gmail.com with ESMTPSA id q18sm3701372edr.26.2021.04.10.15.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 15:30:59 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 5/5] kill redundant stores (local) Date: Sun, 11 Apr 2021 00:30:44 +0200 Message-Id: <20210410223044.86100-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> References: <20210410223044.86100-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org A store is called 'redundant' when the corresponding location already contains the value that will be stored. This patch removes such stores in the case where the memops which make them redundant is in the same basic block. Signed-off-by: Luc Van Oostenryck --- memops.c | 5 +++++ validation/memops/kill-redundant-store0.c | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/memops.c b/memops.c index 44d90754d279..f734f6eb7398 100644 --- a/memops.c +++ b/memops.c @@ -213,6 +213,11 @@ static bool try_to_kill_store(pseudo_t pseudo, struct instruction *insn, /* possible partial dominance? */ if (dominance < 0) return false; + if (insn->target == dom->target && insn->bb == dom->bb) { + // found a memop which makes the store redundant + kill_instruction_force(insn); + return false; + } if (dom->opcode == OP_LOAD) return false; if (dom->is_volatile) diff --git a/validation/memops/kill-redundant-store0.c b/validation/memops/kill-redundant-store0.c index e911166dd953..8819938fe763 100644 --- a/validation/memops/kill-redundant-store0.c +++ b/validation/memops/kill-redundant-store0.c @@ -7,7 +7,6 @@ void foo(int *ptr) /* * check-name: kill-redundant-store0 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: store