Source file src/cmd/compile/internal/ssacompile/mem2reg_test.go

     1  // Copyright 2025 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 ssacompile
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  // Single-block mem2reg test
    12  //
    13  //go:noinline
    14  func justReturn0() int {
    15  	var x, y, z int
    16  	xp := &x
    17  	yp := &y
    18  	zp := &z
    19  	*xp = 0
    20  	*yp = 1
    21  	*zp = 2
    22  	*yp = 3
    23  	*zp = 4
    24  	*yp = 5
    25  	valX1 := *xp
    26  	*zp = valX1 - 1
    27  	*xp = 1
    28  	*yp = 2
    29  	*xp = 3
    30  	*yp = 4
    31  	*xp = 5
    32  	valZ1 := *zp
    33  	*yp = valZ1 + 1
    34  	*zp = 1
    35  	*xp = 2
    36  	*zp = 3
    37  	*xp = 4
    38  	*zp = 5
    39  	valY1 := *yp
    40  	return valY1
    41  }
    42  
    43  func TestMem2Reg(t *testing.T) {
    44  	if r := justReturn0(); r != 0 {
    45  		t.Errorf("justReturn0() = %d, want 0", r)
    46  	}
    47  }
    48  

View as plain text