]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: cse should treat -0.0 and 0.0 as different
authorTodd Neal <todd@tneal.org>
Thu, 3 Sep 2015 01:17:47 +0000 (20:17 -0500)
committerTodd Neal <todd@tneal.org>
Thu, 3 Sep 2015 03:05:02 +0000 (03:05 +0000)
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>
src/cmd/compile/internal/ssa/TODO
src/cmd/compile/internal/ssa/cse.go

index fbe4f56760b25477cd5702f8070ccef07ec1cf58..8feb1053ae64ce669fb71c4342238b3b30df1b62 100644 (file)
@@ -44,6 +44,7 @@ Optimizations (better compiler)
 - Reuseable slices (e.g. []int of size NumValues()) cached in Func
 - Handle signed division overflow and sign extension earlier
 - Implement 64 bit const division with high multiply, maybe in the frontend?
+- Store bool and float32/float64 in auxInt
 
 Regalloc
 --------
index 6851ca9f401b7fc48335083ccd88c2de657dc931..6469ecd72b9f096546f1e457a73fcc988b4ea178 100644 (file)
@@ -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)
                }
        }