]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: get rid of nil checks before float loads/stores
authorKeith Randall <khr@golang.org>
Thu, 25 Feb 2016 21:45:22 +0000 (13:45 -0800)
committerKeith Randall <khr@golang.org>
Fri, 26 Feb 2016 04:33:46 +0000 (04:33 +0000)
Just like we do for integer loads/stores.

Update #14511

Change-Id: Ic6ca6b54301438a5701ea5fb0be755451cb24d45
Reviewed-on: https://go-review.googlesource.com/19923
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Keith Randall <khr@golang.org>

src/cmd/compile/internal/gc/ssa.go
test/nilptr3.go
test/nilptr3_ssa.go

index a463f9dfc50404ce7071d7fb48f0575578f6b0f8..a64bdd07bd770ece768b361c88b6713d883be8e3 100644 (file)
@@ -4588,7 +4588,9 @@ func (s *genState) genValue(v *ssa.Value) {
                        case ssa.OpAMD64MOVQload, ssa.OpAMD64MOVLload, ssa.OpAMD64MOVWload, ssa.OpAMD64MOVBload,
                                ssa.OpAMD64MOVQstore, ssa.OpAMD64MOVLstore, ssa.OpAMD64MOVWstore, ssa.OpAMD64MOVBstore,
                                ssa.OpAMD64MOVBQSXload, ssa.OpAMD64MOVBQZXload, ssa.OpAMD64MOVWQSXload,
-                               ssa.OpAMD64MOVWQZXload, ssa.OpAMD64MOVLQSXload, ssa.OpAMD64MOVLQZXload:
+                               ssa.OpAMD64MOVWQZXload, ssa.OpAMD64MOVLQSXload, ssa.OpAMD64MOVLQZXload,
+                               ssa.OpAMD64MOVSSload, ssa.OpAMD64MOVSDload, ssa.OpAMD64MOVOload,
+                               ssa.OpAMD64MOVSSstore, ssa.OpAMD64MOVSDstore, ssa.OpAMD64MOVOstore:
                                if w.Args[0] == v.Args[0] && w.Aux == nil && w.AuxInt >= 0 && w.AuxInt < minZeroPage {
                                        if Debug_checknil != 0 && int(v.Line) > 1 {
                                                Warnl(int(v.Line), "removed nil check")
@@ -4605,6 +4607,11 @@ func (s *genState) genValue(v *ssa.Value) {
                                }
                        }
                        if w.Type.IsMemory() {
+                               if w.Op == ssa.OpVarDef || w.Op == ssa.OpVarKill || w.Op == ssa.OpVarLive {
+                                       // these ops are OK
+                                       mem = w
+                                       continue
+                               }
                                // We can't delay the nil check past the next store.
                                break
                        }
index 1ba774d83966e1e79fa607b8ed4c212981771ee9..258547733c9b838e662bdb191e3348b7ad219389 100644 (file)
@@ -193,3 +193,21 @@ func f4(x *[10]int) {
        x = y
        _ = &x[9] // ERROR "removed repeated nil check"
 }
+
+func f5(p *float32, q *float64, r *float32, s *float64) float64 {
+       x := float64(*p) // ERROR "removed nil check"
+       y := *q          // ERROR "removed nil check"
+       *r = 7           // ERROR "removed nil check"
+       *s = 9           // ERROR "removed nil check"
+       return x + y
+}
+
+type T [29]byte
+
+func f6(p, q *T) {
+       x := *p // ERROR "generated nil check"
+       // On ARM, the nil check on this store gets removed.  On other archs,
+       // it doesn't.  Makes this hard to test.  SSA will always remove it.
+       //*q = x
+       _ = x
+}
index d324076114d035bddd9a5d76226a9d319057dbcd..ba60a64602b11fdfaca9964521cf9309975ce533 100644 (file)
@@ -192,3 +192,18 @@ func f4(x *[10]int) {
        x = y
        _ = &x[9] // ERROR "removed[a-z ]* nil check"
 }
+
+func f5(p *float32, q *float64, r *float32, s *float64) float64 {
+       x := float64(*p) // ERROR "removed nil check"
+       y := *q          // ERROR "removed nil check"
+       *r = 7           // ERROR "removed nil check"
+       *s = 9           // ERROR "removed nil check"
+       return x + y
+}
+
+type T [29]byte
+
+func f6(p, q *T) {
+       x := *p // ERROR "removed nil check"
+       *q = x  // ERROR "removed nil check"
+}