github.com/tidwall/go@v0.0.0-20170415222209-6694a6888b7d/src/cmd/compile/internal/ssa/loop_test.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ssa 6 7 import ( 8 "cmd/internal/src" 9 "testing" 10 ) 11 12 func TestLoopConditionS390X(t *testing.T) { 13 // Test that a simple loop condition does not generate a conditional 14 // move (issue #19227). 15 // 16 // MOVDLT is generated when Less64 is lowered but should be 17 // optimized into an LT branch. 18 // 19 // For example, compiling the following loop: 20 // 21 // for i := 0; i < N; i++ { 22 // sum += 3 23 // } 24 // 25 // should generate assembly similar to: 26 // loop: 27 // CMP R0, R1 28 // BGE done 29 // ADD $3, R4 30 // ADD $1, R1 31 // BR loop 32 // done: 33 // 34 // rather than: 35 // loop: 36 // MOVD $0, R2 37 // MOVD $1, R3 38 // CMP R0, R1 39 // MOVDLT R2, R3 40 // CMPW R2, $0 41 // BNE done 42 // ADD $3, R4 43 // ADD $1, R1 44 // BR loop 45 // done: 46 // 47 c := testConfigS390X(t) 48 fun := c.Fun("entry", 49 Bloc("entry", 50 Valu("mem", OpInitMem, TypeMem, 0, nil), 51 Valu("SP", OpSP, TypeUInt64, 0, nil), 52 Valu("ret", OpAddr, TypeInt64Ptr, 0, nil, "SP"), 53 Valu("N", OpArg, TypeInt64, 0, c.Frontend().Auto(src.NoXPos, TypeInt64)), 54 Valu("starti", OpConst64, TypeInt64, 0, nil), 55 Valu("startsum", OpConst64, TypeInt64, 0, nil), 56 Goto("b1")), 57 Bloc("b1", 58 Valu("phii", OpPhi, TypeInt64, 0, nil, "starti", "i"), 59 Valu("phisum", OpPhi, TypeInt64, 0, nil, "startsum", "sum"), 60 Valu("cmp1", OpLess64, TypeBool, 0, nil, "phii", "N"), 61 If("cmp1", "b2", "b3")), 62 Bloc("b2", 63 Valu("c1", OpConst64, TypeInt64, 1, nil), 64 Valu("i", OpAdd64, TypeInt64, 0, nil, "phii", "c1"), 65 Valu("c3", OpConst64, TypeInt64, 3, nil), 66 Valu("sum", OpAdd64, TypeInt64, 0, nil, "phisum", "c3"), 67 Goto("b1")), 68 Bloc("b3", 69 Valu("retdef", OpVarDef, TypeMem, 0, nil, "mem"), 70 Valu("store", OpStore, TypeMem, 0, TypeInt64, "ret", "phisum", "retdef"), 71 Exit("store"))) 72 CheckFunc(fun.f) 73 Compile(fun.f) 74 CheckFunc(fun.f) 75 76 checkOpcodeCounts(t, fun.f, map[Op]int{ 77 OpS390XMOVDLT: 0, 78 OpS390XMOVDGT: 0, 79 OpS390XMOVDLE: 0, 80 OpS390XMOVDGE: 0, 81 OpS390XMOVDEQ: 0, 82 OpS390XMOVDNE: 0, 83 OpS390XCMP: 1, 84 OpS390XCMPWconst: 0, 85 }) 86 }