From patchwork Thu Jun 8 07:39:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9774113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 64F846034B for ; Thu, 8 Jun 2017 07:39:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52DC91FE85 for ; Thu, 8 Jun 2017 07:39:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4764025404; Thu, 8 Jun 2017 07:39:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC5AC1FE85 for ; Thu, 8 Jun 2017 07:39:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751635AbdFHHjo (ORCPT ); Thu, 8 Jun 2017 03:39:44 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35252 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751619AbdFHHjn (ORCPT ); Thu, 8 Jun 2017 03:39:43 -0400 Received: by mail-wm0-f65.google.com with SMTP id g15so5868678wmc.2 for ; Thu, 08 Jun 2017 00:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aic42fh4H6Ckl9SwaHZDV/suC1JOxXBX942glUmmNd8=; b=AoNNw3nLVB6otcD+0wkkiou4aNam5wxewxePIj73DrFcg4ymqdxwrfXiqmnqfeUdUV gExgBRZiZIA4+UdDTTFIWcm2BEUHdjOZWJoHt5o6t43kcjrZ+s3AwjcxmY8QDYZ6p2ww ZHBvS3uPc9zu278E/OitX0JGFJAEQbXJCVYzBRyumATr07mY6CbSWCg582RE4Naszs/f VcO9Sb3snFTWrDW5soJZf5o+R7Z8KJrLAFwsG4RkGaLmIqc3eLeVNEILww0RDW4T8UeZ Rdk+8T3AnBUxZm1dm3dOvjKXfZ09e6R5TlNvbLaKpqlOYirODVUWFHW7hKbHI9oQZjMh xWkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aic42fh4H6Ckl9SwaHZDV/suC1JOxXBX942glUmmNd8=; b=ZXRwovqAYxio89gUEKoPgjnx52/jt4IeufaWpyfkW5IoOB4hUxLYgUayfCjVqOtKAG 2nCa4S+91J59Ailwbr6k+L7O+T6HDUZIxPEPMDJA29ALGa9AKjmiy1X8nVy+smWpDXe7 vXPWLzaCkrAG2AKNCzGTYONm9ylpZ7GSvahc6CIAbNJke6igjMtV7bVKqq8mFQoDcwsY puBVh/KeM/PKeSKH2YM1BvUNirCzat2ENAfrK5U3tqx+7v5weS5/906Q7XnaIQzQzwsd R2bLRwRTyfI1MabQm6ATS2xcNIkSUedFbOMRzzLJkQ0+n94Tl+zRVG6l/ND6C/y8gSKK 5EIg== X-Gm-Message-State: AODbwcBth+MwDThW6xpRzIbHaVBKmxkNReejmOXNDU+hzTB1j/2xYcaa 8aAKfgfZ9D0bG5quBec= X-Received: by 10.80.213.157 with SMTP id v29mr12924204edi.149.1496907582217; Thu, 08 Jun 2017 00:39:42 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:89c:5400:21b3:ee4b:e91a:4fb6]) by smtp.gmail.com with ESMTPSA id o30sm1765888edc.22.2017.06.08.00.39.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 00:39:41 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Chris Li , Luc Van Oostenryck Subject: [PATCH 3/3] kill dead loads Date: Thu, 8 Jun 2017 09:39:27 +0200 Message-Id: <20170608073927.55218-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170608073927.55218-1-luc.vanoostenryck@gmail.com> References: <20170608073927.55218-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Like others instructions producing a value, OP_LOADs can be dead. But currently, dead OP_LOAD are not removed, as dead_insn() do for others instructions. Fix this by checking at simplification time if OP_LOADs are dead and call kill_instruction() if it is the case. NOTE: the fix is the exact same logic than dead_insn() but dead_insn() kill without discrimination. In our case we want to keep volatiles OP_LOADs which kill_instruction() does and dead_insn() does not. Ideally, dead_insn() should use kill_instruction() but this is a bigger change which will part of another series. Signed-off-by: Luc Van Oostenryck --- simplify.c | 6 +++++- validation/optim/load-dead.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 validation/optim/load-dead.c diff --git a/simplify.c b/simplify.c index d5e219200..2c95d8b86 100644 --- a/simplify.c +++ b/simplify.c @@ -1189,7 +1189,11 @@ int simplify_instruction(struct instruction *insn) case OP_NOT: case OP_NEG: return simplify_unop(insn); - case OP_LOAD: case OP_STORE: + case OP_LOAD: + if (!has_users(insn->target)) + return kill_instruction(insn); + /* fall-through */ + case OP_STORE: return simplify_memop(insn); case OP_SYMADDR: if (dead_insn(insn, NULL, NULL, NULL)) diff --git a/validation/optim/load-dead.c b/validation/optim/load-dead.c new file mode 100644 index 000000000..52538cc2d --- /dev/null +++ b/validation/optim/load-dead.c @@ -0,0 +1,11 @@ +void foo(int *p) { *p; } + +int *p; +void bar(void) { *p; } + +/* + * check-name: load-dead + * check-command: test-linearize -Wno-decl $file + * check-output-ignore + * check-output-excludes: load\\. + */