]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: handle phi control values
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 5 Aug 2015 22:56:31 +0000 (15:56 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 6 Aug 2015 17:44:25 +0000 (17:44 +0000)
Tests courtesy of Todd Neal.

Change-Id: If657c7c7d3cd1ce01e9d9ad79eb6b2110230c0f9
Reviewed-on: https://go-review.googlesource.com/13267
Reviewed-by: Todd Neal <todd@tneal.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/testdata/ctl_ssa.go [new file with mode: 0644]
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/rewriteAMD64.go

diff --git a/src/cmd/compile/internal/gc/testdata/ctl_ssa.go b/src/cmd/compile/internal/gc/testdata/ctl_ssa.go
new file mode 100644 (file)
index 0000000..7377c9a
--- /dev/null
@@ -0,0 +1,53 @@
+// run
+
+// Copyright 2015 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.
+
+// Test control flow
+
+package main
+
+// nor_ssa calculates NOR(a, b).
+// It is implemented in a way that generates
+// phi control values.
+func nor_ssa(a, b bool) bool {
+       var c bool
+       if a {
+               c = true
+       }
+       if b {
+               c = true
+       }
+       if c {
+               return false
+       }
+       return true
+}
+
+func testPhiControl() {
+       tests := [...][3]bool{ // a, b, want
+               {false, false, true},
+               {true, false, false},
+               {false, true, false},
+               {true, true, false},
+       }
+       for _, test := range tests {
+               a, b := test[0], test[1]
+               got := nor_ssa(a, b)
+               want := test[2]
+               if want != got {
+                       print("nor(", a, ", ", b, ")=", want, " got ", got, "\n")
+                       failed = true
+               }
+       }
+}
+
+var failed = false
+
+func main() {
+       testPhiControl()
+       if failed {
+               panic("failed")
+       }
+}
index e7c712eb17480364bce95ed53736893d644d1af4..ea2311cae0833c025df76038f9f46c3326d18040 100644 (file)
 (If (SETBE cmp) yes no) -> (ULE cmp yes no)
 (If (SETA cmp) yes no) -> (UGT cmp yes no)
 (If (SETAE cmp) yes no) -> (UGE cmp yes no)
-(If cond yes no) && cond.Op == OpAMD64MOVBload -> (NE (TESTB <TypeFlags> cond cond) yes no)
+(If cond yes no) -> (NE (TESTB <TypeFlags> cond cond) yes no)
 
 (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem)
 (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem)
index 1e7d957f9266511e984c1cdc04718b9c9d0ca41f..4fa95a4726c1c392cae318d77243509ddff2a144 100644 (file)
@@ -8068,16 +8068,13 @@ func rewriteBlockAMD64(b *Block) bool {
        end9bea9963c3c5dfb97249a5feb8287f94:
                ;
                // match: (If cond yes no)
-               // cond: cond.Op == OpAMD64MOVBload
+               // cond:
                // result: (NE (TESTB <TypeFlags> cond cond) yes no)
                {
                        v := b.Control
                        cond := v
                        yes := b.Succs[0]
                        no := b.Succs[1]
-                       if !(cond.Op == OpAMD64MOVBload) {
-                               goto end7e22019fb0effc80f85c05ea30bdb5d9
-                       }
                        b.Kind = BlockAMD64NE
                        v0 := b.NewValue0(v.Line, OpAMD64TESTB, TypeInvalid)
                        v0.Type = TypeFlags
@@ -8088,8 +8085,8 @@ func rewriteBlockAMD64(b *Block) bool {
                        b.Succs[1] = no
                        return true
                }
-               goto end7e22019fb0effc80f85c05ea30bdb5d9
-       end7e22019fb0effc80f85c05ea30bdb5d9:
+               goto end012351592edfc708bd3181d7e53f3993
+       end012351592edfc708bd3181d7e53f3993:
                ;
        case BlockAMD64LE:
                // match: (LE (InvertFlags cmp) yes no)