From fff732ea2c4d3cb449c4383a6957ff80ca75c70a Mon Sep 17 00:00:00 2001 From: Jamie Gennis Date: Wed, 8 Feb 2012 10:25:13 -0500 Subject: [PATCH] 6g,8g: make constant propagation inlining-friendly. 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 | 2 +- src/cmd/8g/peep.c | 2 +- test/fixedbugs/bug409.go | 20 ++++++++++++++++++++ test/fixedbugs/bug409.out | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/fixedbugs/bug409.go create mode 100644 test/fixedbugs/bug409.out diff --git a/src/cmd/6g/peep.c b/src/cmd/6g/peep.c index 63ef3f78f0c..3710033b20d 100644 --- a/src/cmd/6g/peep.c +++ b/src/cmd/6g/peep.c @@ -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) diff --git a/src/cmd/8g/peep.c b/src/cmd/8g/peep.c index e0e44a5ef48..b8a2825e5a8 100644 --- a/src/cmd/8g/peep.c +++ b/src/cmd/8g/peep.c @@ -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 index 00000000000..884d3337087 --- /dev/null +++ b/test/fixedbugs/bug409.go @@ -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 index 00000000000..3cb40ed59a9 --- /dev/null +++ b/test/fixedbugs/bug409.out @@ -0,0 +1 @@ ++1.000000e+000 +2.000000e+000 +3.000000e+000 +4.000000e+000