From patchwork Fri Mar 9 02:30:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 10269563 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 7AB476016D for ; Fri, 9 Mar 2018 02:30:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AEF929BB9 for ; Fri, 9 Mar 2018 02:30:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69C1B29BBA; Fri, 9 Mar 2018 02:30:37 +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 3114029BED for ; Fri, 9 Mar 2018 02:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750953AbeCICad (ORCPT ); Thu, 8 Mar 2018 21:30:33 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35029 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750885AbeCICa0 (ORCPT ); Thu, 8 Mar 2018 21:30:26 -0500 Received: by mail-wm0-f66.google.com with SMTP id x7so1321751wmc.0 for ; Thu, 08 Mar 2018 18:30:26 -0800 (PST) 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=ArSlesQBHj/u2pA/yQCYrDgMSm4TjS+X28mpyQvsGkQ=; b=TuISDjpv+kzOog+f+2hoYPwqo4qNfUEKGEzsuk3WIEzr+sL9AGldteH5rOLM1PoFMM ThYo4ZRFDbu09eB33km/Ythvk1rDIY8vLfEC6pdu0CqCDx4psghBPod/HhEOVJ7KOGRv /EsbngaJC+F712XDuuU/cnTFY8Wyi7yWWhBzkQuGdH7pcBpggVnhvLAP9SX9VIxxG84K wGYyxJ78MU0Zy6wrNF+yuIQYh2W8B4WRh+GQROZ8T8ja4O0YWJOJTfxsg0kcHdW6JPi/ qv3Iyhs7LmIqvkW7WJhxCGjr5ZfnZ2icPpMVJW5ehXvHrIy1dVo49VTrT65fkHkUOYVh /a/g== 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=ArSlesQBHj/u2pA/yQCYrDgMSm4TjS+X28mpyQvsGkQ=; b=EGILD7KBNMx+CXXn1mnDux6GaBcXrisWBLmb+6GnUIYCYwCnQagdki+cjO1fAs+Y// Ffcd+iexXWMZ5gpQcHPQ9JcP1+Oc71fKyisJWVTf/CNYIGEJTVbSJQbIkAhYzW0fMjWg FwWvjpdqBd7EkG1x/OZMQVMjw9nrARV2Spj3Y5S+EdjGaxP+dnkq8CVeWdD50oWRn9tS zAVqBr8TSLLwVm98uWUYGPSM3BxVFY7P0N/0oCkf8gKq0JlaL68YXlyWqnhZT/ymt6kY 1CUHst6T0xyyvB2gabybguOn5Oyeb0sSSGJhLg4OuCSAfXJEXxOkDl+Egkw4ToiGgqan RWkQ== X-Gm-Message-State: APf1xPBua++Yu2zNgO1Lu0Q0WA8Fu5LD2a0eUvLO+CHDRZM/iJDY5Qav UBnyMq+brl2a8Z2wUbt/SexJZMQT X-Google-Smtp-Source: AG47ELuLwfGbr0+O5O2ZrNNtskYb+Vg3FLv3fmSh4oJlqR54ZgZB6j1PWnJPtEnaRkZ+n8KN3pYmHQ== X-Received: by 10.80.177.86 with SMTP id l22mr35364326edd.88.1520562625239; Thu, 08 Mar 2018 18:30:25 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:402a:9e00:b509:133b:1e4b:f083]) by smtp.gmail.com with ESMTPSA id y58sm163915edd.81.2018.03.08.18.30.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 18:30:24 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 5/5] symaddr: keep OP_SYMADDR instructions Date: Fri, 9 Mar 2018 03:30:10 +0100 Message-Id: <20180309023010.94475-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180309023010.94475-1-luc.vanoostenryck@gmail.com> References: <20180309023010.94475-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 OP_SYMADDR instructions are systematically eliminated during simplification phase, their target address being simply replaced by the symbol itself. While at first sight, it doesn't look wrong per se (as it all depends to the semantic we want to give to pseudos and the instructions and how high- or low-level we want the IR to be), it's not clear if this simplification was really intentional and don't seems to have any advantages. A deeper look show that it is a problem to remove OP_SYMADDRS as they presence inhibit memops simplification that would otherwise be illegal. The only places we're it is correct to replace the result of an OP_SYMADDR by the symbol itself is for the address of OP_LOAD or OP_STORE because the addressability is handled directely for these instructions. Change this by removing the 'simplification' of OP_SYMADDR. Signed-off-by: Luc Van Oostenryck --- simplify.c | 2 +- validation/call-inlined.c | 6 ++++-- validation/call-variadic.c | 3 ++- validation/linear/degen-array.c | 9 ++++++--- validation/mem2reg/address-used00.c | 1 - validation/symaddr-op.c | 1 - validation/symaddr.c | 9 ++++++--- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/simplify.c b/simplify.c index b3cd76e3d..1593fed79 100644 --- a/simplify.c +++ b/simplify.c @@ -1207,7 +1207,7 @@ int simplify_instruction(struct instruction *insn) case OP_SYMADDR: if (dead_insn(insn, NULL, NULL, NULL)) return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP; - return replace_with_pseudo(insn, insn->symbol); + return 0; case OP_CAST: case OP_SCAST: case OP_FPCAST: diff --git a/validation/call-inlined.c b/validation/call-inlined.c index b907ded60..a5b8b89e5 100644 --- a/validation/call-inlined.c +++ b/validation/call-inlined.c @@ -39,14 +39,16 @@ bar: bas: .L6: - add.64 %r16 <- "abc", $1 + symaddr.64 %r14 <- "abc" + add.64 %r16 <- %r14, $1 ret.64 %r16 qus: .L9: - add.64 %r21 <- messg, $1 + symaddr.64 %r19 <- messg + add.64 %r21 <- %r19, $1 ret.64 %r21 diff --git a/validation/call-variadic.c b/validation/call-variadic.c index 8c9815621..7f62eb191 100644 --- a/validation/call-variadic.c +++ b/validation/call-variadic.c @@ -15,7 +15,8 @@ int foo(const char *fmt, int a, long l, int *p) foo: .L0: - call.32 %r5 <- print, "msg %c: %d %d/%ld %ld/%p %p\n", $120, %arg2, $7, %arg3, $0, %arg4, $0 + symaddr.64 %r1 <- "msg %c: %d %d/%ld %ld/%p %p\n" + call.32 %r5 <- print, %r1, $120, %arg2, $7, %arg3, $0, %arg4, $0 ret.32 %r5 diff --git a/validation/linear/degen-array.c b/validation/linear/degen-array.c index b8a6f4f66..a8a267633 100644 --- a/validation/linear/degen-array.c +++ b/validation/linear/degen-array.c @@ -12,19 +12,22 @@ int *fd(int i) { return a; } fa: .L0: - ret.64 a + symaddr.64 %r1 <- a + ret.64 %r1 f0: .L2: - ret.64 a + symaddr.64 %r3 <- a + ret.64 %r3 fd: .L4: - ret.64 a + symaddr.64 %r6 <- a + ret.64 %r6 * check-output-end diff --git a/validation/mem2reg/address-used00.c b/validation/mem2reg/address-used00.c index a41f05c25..e9198ee7b 100644 --- a/validation/mem2reg/address-used00.c +++ b/validation/mem2reg/address-used00.c @@ -13,7 +13,6 @@ int foo(int **g, int j) /* * check-name: address-used00 * check-command: test-linearize -Wno-decl -fdump-ir=final $file - * check-known-to-fail * check-output-ignore * check-output-excludes: ret\\..* \\$1 * check-output-contains: ret\\..* \\$0 diff --git a/validation/symaddr-op.c b/validation/symaddr-op.c index c17c328f8..8a836fb36 100644 --- a/validation/symaddr-op.c +++ b/validation/symaddr-op.c @@ -11,7 +11,6 @@ char foo(int *ptr, long i) /* * check-name: symaddr-op * check-command: test-linearize -m64 -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: add.64 .* <- s, diff --git a/validation/symaddr.c b/validation/symaddr.c index 97f640f91..4fe776c21 100644 --- a/validation/symaddr.c +++ b/validation/symaddr.c @@ -21,9 +21,12 @@ int foo(void) foo: .L0: - call usep, g - call usep, a - add.64 %r4 <- b, $4 + symaddr.64 %r1 <- g + call usep, %r1 + symaddr.64 %r2 <- a + call usep, %r2 + symaddr.64 %r3 <- b + add.64 %r4 <- %r3, $4 call usep, %r4 ret.32 $0