aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/cse.go
diff options
context:
space:
mode:
authorTodd Neal <todd@tneal.org>2015-09-02 20:17:47 -0500
committerTodd Neal <todd@tneal.org>2015-09-03 03:05:02 +0000
commitce4317266c160953aacf46cbe9d8341f86158776 (patch)
tree6ab0d3287658f357034170a66ab198c64561b659 /src/cmd/compile/internal/ssa/cse.go
parent19285efaed7b08535e1b3ba921f584ed8bde6e49 (diff)
downloadgo-ce4317266c160953aacf46cbe9d8341f86158776.tar.gz
go-ce4317266c160953aacf46cbe9d8341f86158776.zip
[dev.ssa] cmd/compile: cse should treat -0.0 and 0.0 as different
cse was incorrectly classifying -0.0 and 0.0 as equivalent. This lead to invalid code as ssa uses PXOR -0.0, reg to negate a floating point. Fixes math. Change-Id: Id7eb10c71749eaed897f29b02c33891cf5820acf Reviewed-on: https://go-review.googlesource.com/14205 Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/cse.go')
-rw-r--r--src/cmd/compile/internal/ssa/cse.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/ssa/cse.go b/src/cmd/compile/internal/ssa/cse.go
index 6851ca9f40..6469ecd72b 100644
--- a/src/cmd/compile/internal/ssa/cse.go
+++ b/src/cmd/compile/internal/ssa/cse.go
@@ -4,7 +4,10 @@
package ssa
-import "sort"
+import (
+ "math"
+ "sort"
+)
// cse does common-subexpression elimination on the Function.
// Values are just relinked, nothing is deleted. A subsequent deadcode
@@ -51,7 +54,19 @@ func cse(f *Func) {
if len(v.Args) > 1 {
arg1op = v.Args[1].Op
}
- k := key{v.Op, v.Type.String(), v.Aux, v.AuxInt, len(v.Args), bid, arg0op, arg1op}
+
+ aux := v.Aux
+ auxInt := v.AuxInt
+ // -0 == 0, but aren't equivalent values so we use
+ // Float64bits to distinguish
+ if f, ok := aux.(float64); ok {
+ aux = nil
+ if auxInt != 0 {
+ v.Fatalf("float would clobber v.auxInt")
+ }
+ auxInt = int64(math.Float64bits(f))
+ }
+ k := key{v.Op, v.Type.String(), aux, auxInt, len(v.Args), bid, arg0op, arg1op}
m[k] = append(m[k], v)
}
}