summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2024-03-07 16:40:51 +0100
committerNguyễn Gia Phong <cnx@loang.net>2024-03-08 11:59:04 +0900
commit644b604af4b3535c1cc3208fada2a4909fca5a92 (patch)
treea305e104ffb11e199cf382fb039a71504c02716c
parent474ede369ba155f12a7b2c3b157c11fd4d58baca (diff)
downloadroux-644b604af4b3535c1cc3208fada2a4909fca5a92.tar.gz
fix bug in alias analysis
The handling of phi was incorrect
and we would sometimes miss escapes.
We now handle phis at the very end
of the pass to make sure the defs
for their arguments have all been
processed.
-rw-r--r--alias.c8
-rw-r--r--test/alias1.ssa21
2 files changed, 26 insertions, 3 deletions
diff --git a/alias.c b/alias.c
index 3885115..9b41084 100644
--- a/alias.c
+++ b/alias.c
@@ -132,7 +132,7 @@ store(Ref r, int sz, Fn *fn)
 void
 fillalias(Fn *fn)
 {
-	uint n, m;
+	uint n;
 	int t, sz;
 	int64_t x;
 	Blk *b;
@@ -146,8 +146,6 @@ fillalias(Fn *fn)
 	for (n=0; n<fn->nblk; ++n) {
 		b = fn->rpo[n];
 		for (p=b->phi; p; p=p->link) {
-			for (m=0; m<p->narg; m++)
-				esc(p->arg[m], fn);
 			assert(rtype(p->to) == RTmp);
 			a = &fn->tmp[p->to.val].alias;
 			assert(a->type == ABot);
@@ -217,4 +215,8 @@ fillalias(Fn *fn)
 		if (b->jmp.type != Jretc)
 			esc(b->jmp.arg, fn);
 	}
+	for (b=fn->start; b; b=b->link)
+		for (p=b->phi; p; p=p->link)
+			for (n=0; n<p->narg; n++)
+				esc(p->arg[n], fn);
 }
diff --git a/test/alias1.ssa b/test/alias1.ssa
new file mode 100644
index 0000000..a064fac
--- /dev/null
+++ b/test/alias1.ssa
@@ -0,0 +1,21 @@
+export function w $main() {
+@start
+	%a =l alloc4 4
+	%b =l alloc4 4
+	storew 4, %a
+	storew 5, %b
+
+@loop
+	# %mem will be %a and %b successively,
+	# but we do not know it when processing
+	# the phi because %b goes through a cpy
+	%mem =l phi @start %a, @loop %bcpy
+
+	%w =w load %mem
+	%eq5 =w ceqw %w, 5
+	%bcpy =l copy %b
+	jnz %eq5, @exit, @loop
+
+@exit
+	ret 0
+}