Help us shape the future of Go! Take the 2026 Go Developer Survey

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

     1  // Copyright 2026 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  	"fmt"
     9  	"testing"
    10  
    11  	"cmd/compile/internal/ssa"
    12  	"cmd/compile/internal/ssa/block"
    13  	"cmd/compile/internal/ssa/ssaop"
    14  	"cmd/internal/src"
    15  )
    16  
    17  func BenchmarkMemcombineSharedOR(b *testing.B) {
    18  	for _, n := range []int{8, 16, 22} {
    19  		b.Run(fmt.Sprint(n), func(b *testing.B) {
    20  			c := testConfig(b)
    21  			f := c.config.NewFunc(c.Frontend(), new(ssa.Cache))
    22  			entry := f.NewBlock(block.BlockExit)
    23  			f.Entry = entry
    24  			typ := c.config.Types.UInt64
    25  			x := entry.NewValue0(src.NoXPos, ssaop.OpArg, typ)
    26  			y := entry.NewValue0(src.NoXPos, ssaop.OpArg, typ)
    27  			v := entry.NewValue2(src.NoXPos, ssaop.OpOr64, typ, x, y)
    28  			// Each level uses the previous result through two parents.
    29  			// Expanding this graph as a tree takes exponential work.
    30  			for range n {
    31  				a := entry.NewValue2(src.NoXPos, ssaop.OpOr64, typ, v, x)
    32  				b := entry.NewValue2(src.NoXPos, ssaop.OpOr64, typ, v, y)
    33  				v = entry.NewValue2(src.NoXPos, ssaop.OpOr64, typ, a, b)
    34  			}
    35  			b.ReportAllocs()
    36  			for b.Loop() {
    37  				memcombineLoads(f, nil)
    38  			}
    39  		})
    40  	}
    41  }
    42  

View as plain text