All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Dibyendu Majumdar <mobile@majumdar.org.uk>,
	Pekka Enberg <penberg@kernel.org>, Jeff Garzik <jeff@garzik.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v2 14/27] keep OP_SYMADDR instructions
Date: Sat, 11 Mar 2017 10:06:53 +0100	[thread overview]
Message-ID: <20170311090706.17171-15-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170311090706.17171-1-luc.vanoostenryck@gmail.com>

OP_SYMADDR instructions are systematically eliminated during
simplification phase, their target address being simply replaced
by the symbol itself.

While it's not 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.

OP_SYMADDRs allow to make a clear separation between a symbol
(a name with a type and info for storage & linkage) and its address
(which can be stored in memory or in a register and on which
arithmetic operations can then be done on it). Once these addresses
are replaced by the symbol itself, those symbols can appears almost
everywhere in the linearized code:
- in calls' arguments,
- in adds and subs (while doing pointer arithmetic),
- in casts,
- in load & stores,
- ...
and they complicate things considerably once you begin to be
interested concretly in things after linearization & simplification
since soon or later you will need the address anyway.

Change this by removing the 'simplification' of OP_SYMADDR.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c           |  2 +-
 validation/symaddr.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 validation/symaddr.c

diff --git a/simplify.c b/simplify.c
index 5d00937f1..a84e4787f 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1159,7 +1159,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/symaddr.c b/validation/symaddr.c
new file mode 100644
index 000000000..4fe776c21
--- /dev/null
+++ b/validation/symaddr.c
@@ -0,0 +1,35 @@
+int g;
+int a[3];
+int b[3];
+
+void usep(int*);
+
+int foo(void)
+{
+	int r = 0;
+	usep(&g);
+	usep(a);
+	usep(b + 1);
+	return r;
+}
+
+/*
+ * check-name: symaddr
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+foo:
+.L0:
+	<entry-point>
+	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
+
+
+ * check-output-end
+ */
-- 
2.11.1


  parent reply	other threads:[~2017-03-11  9:07 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-11  9:06 [PATCH v2 00/27] LLVM fixes Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 01/27] give a type to OP_PHISOURCE Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 02/27] give a type to OP_SEL, always Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 03/27] give a type to OP_SYMADDR Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 04/27] give a type to PSEUDO_ARGs Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 05/27] llvm: fix translation of PSEUDO_VALs into a ValueRefs Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 06/27] llvm: fix output_op_store() which modify its operand Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 07/27] llvm: fix output_op_[ptr]cast() Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 08/27] llvm: give a name to call return values Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 09/27] llvm: add test cases for the type of constants Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 10/27] add ptr_list_nth_entry() Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 11/27] llvm: fix type of literal integer passed as arguments Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 12/27] llvm: fix output OP_ADD mixed with pointers Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 13/27] llvm: add support for OP_SYMADDR Luc Van Oostenryck
2017-03-11  9:06 ` Luc Van Oostenryck [this message]
2017-03-11  9:06 ` [PATCH v2 15/27] llvm: add test cases for symbol's address Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 16/27] llvm: add test cases for pointers passed as argument Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 17/27] llvm: add test cases for arrays " Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 18/27] llvm: add test cases for degenerated pointers Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 19/27] llvm: add support for OP_NEG Luc Van Oostenryck
2017-03-11  9:06 ` [PATCH v2 20/27] llvm: fix pointer/float mixup in comparisons Luc Van Oostenryck
2017-03-11  9:07 ` [PATCH v2 21/27] llvm: use pseudo_list_size() instead of open coding it Luc Van Oostenryck
2017-03-11  9:07 ` [PATCH v2 22/27] llvm: give arguments a name Luc Van Oostenryck
2017-03-11  9:07 ` [PATCH v2 23/27] llvm: remove unneeded arg 'module' Luc Van Oostenryck
2017-03-11  9:07 ` [PATCH v2 24/27] llvm: remove unneeded arg 'fn' Luc Van Oostenryck
2017-03-11  9:07 ` [PATCH v2 25/27] llvm: remove unneeded 'generation' Luc Van Oostenryck
2017-03-11  9:07 ` [PATCH v2 26/27] llvm: remove unneeded function::type Luc Van Oostenryck
2017-03-11  9:07 ` [PATCH v2 27/27] llvm: reduce scope of 'bb_nr' Luc Van Oostenryck
2017-03-11 11:12 ` [PATCH v2 00/27] LLVM fixes Dibyendu Majumdar
2017-03-11 11:49   ` Luc Van Oostenryck
2017-03-11 11:54     ` Dibyendu Majumdar
2017-03-11 12:30       ` Luc Van Oostenryck
2017-03-11 13:36         ` Dibyendu Majumdar
2017-03-11 14:12           ` Luc Van Oostenryck
2017-03-11 14:16             ` Dibyendu Majumdar
2017-03-11 14:28               ` Luc Van Oostenryck
2017-03-11 15:10               ` Jeff Garzik
2017-03-11 15:51                 ` Luc Van Oostenryck
2017-03-11 18:08                   ` Dibyendu Majumdar
2017-03-11 20:44                     ` Luc Van Oostenryck
2017-03-11 21:21                       ` Dibyendu Majumdar
2017-03-11 22:30                         ` Luc Van Oostenryck
2017-03-11 22:57                           ` Dibyendu Majumdar
2017-03-11 23:02                             ` Linus Torvalds
2017-03-11 23:04                               ` Dibyendu Majumdar
2017-03-11 23:12                                 ` Luc Van Oostenryck
2017-03-12  2:35     ` Dibyendu Majumdar
2017-03-14  6:18 ` Christopher Li
2017-03-16 16:41   ` Luc Van Oostenryck
2017-03-17 14:06     ` Dibyendu Majumdar
2017-03-17 17:04     ` Christopher Li
2017-03-17 17:41       ` Luc Van Oostenryck
2017-03-17 18:05         ` Christopher Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170311090706.17171-15-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=jeff@garzik.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=mobile@majumdar.org.uk \
    --cc=penberg@kernel.org \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.