]> Cypherpunks repositories - gostls13.git/commitdiff
6g,8g: make constant propagation inlining-friendly.
authorJamie Gennis <jgennis@google.com>
Wed, 8 Feb 2012 15:25:13 +0000 (10:25 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 8 Feb 2012 15:25:13 +0000 (10:25 -0500)
This changes makes constant propagation compare 'from' values using node
pointers rather than symbol names when checking to see whether a set
operation is redundant. When a function is inlined multiple times in a
calling function its arguments will share symbol names even though the values
are different. Prior to this fix the bug409 test would hit a case with 6g
where an LEAQ instruction was incorrectly eliminated from the second inlined
function call. 8g appears to have had the same bug, but the test did not fail
there.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5646044

src/cmd/6g/peep.c
src/cmd/8g/peep.c
test/fixedbugs/bug409.go [new file with mode: 0644]
test/fixedbugs/bug409.out [new file with mode: 0644]

index 63ef3f78f0c270a9ae37b5552c6ae9640be39eb6..3710033b20dcd273b6d8a3709a4aa0bcbf22679c 100644 (file)
@@ -987,7 +987,7 @@ loop:
        case 3: // set
                if(p->as == p0->as)
                if(p->from.type == p0->from.type)
-               if(p->from.sym == p0->from.sym)
+               if(p->from.node == p0->from.node)
                if(p->from.offset == p0->from.offset)
                if(p->from.scale == p0->from.scale)
                if(p->from.dval == p0->from.dval)
index e0e44a5ef4847229f4157bdf0ec2416e758ff0f5..b8a2825e5a8fc7a82c05e6cfc9bc11da725efb20 100644 (file)
@@ -878,7 +878,7 @@ loop:
        case 3: // set
                if(p->as == p0->as)
                if(p->from.type == p0->from.type)
-               if(p->from.sym == p0->from.sym)
+               if(p->from.node == p0->from.node)
                if(p->from.offset == p0->from.offset)
                if(p->from.scale == p0->from.scale)
                if(p->from.dval == p0->from.dval)
diff --git a/test/fixedbugs/bug409.go b/test/fixedbugs/bug409.go
new file mode 100644 (file)
index 0000000..884d333
--- /dev/null
@@ -0,0 +1,20 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out
+
+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Multiple inlined calls to a function that causes
+// redundant address loads.
+
+package main
+
+func F(v [2]float64) [2]float64 {
+       return [2]float64{v[0], v[1]}
+}
+
+func main() {
+       a := F([2]float64{1, 2})
+       b := F([2]float64{3, 4})
+       println(a[0], a[1], b[0], b[1])
+}
diff --git a/test/fixedbugs/bug409.out b/test/fixedbugs/bug409.out
new file mode 100644 (file)
index 0000000..3cb40ed
--- /dev/null
@@ -0,0 +1 @@
++1.000000e+000 +2.000000e+000 +3.000000e+000 +4.000000e+000