github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/inline/inlheur/testdata/props/params.go (about)

     1  // Copyright 2023 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  // DO NOT EDIT (use 'go test -v -update-expected' instead.)
     6  // See github.com/go-asm/go/cmd/compile/inline/inlheur/testdata/props/README.txt
     7  // for more information on the format of this file.
     8  // <endfilepreamble>
     9  package params
    10  
    11  import "os"
    12  
    13  // params.go T_feeds_if_simple 20 0 1
    14  // ParamFlags
    15  //   0 ParamFeedsIfOrSwitch
    16  // <endpropsdump>
    17  // {"Flags":0,"ParamFlags":[32],"ResultFlags":null}
    18  // <endcallsites>
    19  // <endfuncpreamble>
    20  func T_feeds_if_simple(x int) {
    21  	if x < 100 {
    22  		os.Exit(1)
    23  	}
    24  	println(x)
    25  }
    26  
    27  // params.go T_feeds_if_nested 35 0 1
    28  // ParamFlags
    29  //   0 ParamMayFeedIfOrSwitch
    30  //   1 ParamFeedsIfOrSwitch
    31  // <endpropsdump>
    32  // {"Flags":0,"ParamFlags":[64,32],"ResultFlags":null}
    33  // <endcallsites>
    34  // <endfuncpreamble>
    35  func T_feeds_if_nested(x, y int) {
    36  	if y != 0 {
    37  		if x < 100 {
    38  			os.Exit(1)
    39  		}
    40  	}
    41  	println(x)
    42  }
    43  
    44  // params.go T_feeds_if_pointer 51 0 1
    45  // ParamFlags
    46  //   0 ParamFeedsIfOrSwitch
    47  // <endpropsdump>
    48  // {"Flags":0,"ParamFlags":[32],"ResultFlags":null}
    49  // <endcallsites>
    50  // <endfuncpreamble>
    51  func T_feeds_if_pointer(xp *int) {
    52  	if xp != nil {
    53  		os.Exit(1)
    54  	}
    55  	println(xp)
    56  }
    57  
    58  // params.go T.T_feeds_if_simple_method 66 0 1
    59  // ParamFlags
    60  //   0 ParamFeedsIfOrSwitch
    61  //   1 ParamFeedsIfOrSwitch
    62  // <endpropsdump>
    63  // {"Flags":0,"ParamFlags":[32,32],"ResultFlags":null}
    64  // <endcallsites>
    65  // <endfuncpreamble>
    66  func (r T) T_feeds_if_simple_method(x int) {
    67  	if x < 100 {
    68  		os.Exit(1)
    69  	}
    70  	if r != 99 {
    71  		os.Exit(2)
    72  	}
    73  	println(x)
    74  }
    75  
    76  // params.go T_feeds_if_blanks 86 0 1
    77  // ParamFlags
    78  //   0 ParamNoInfo
    79  //   1 ParamFeedsIfOrSwitch
    80  //   2 ParamNoInfo
    81  //   3 ParamNoInfo
    82  // <endpropsdump>
    83  // {"Flags":0,"ParamFlags":[0,32,0,0],"ResultFlags":null}
    84  // <endcallsites>
    85  // <endfuncpreamble>
    86  func T_feeds_if_blanks(_ string, x int, _ bool, _ bool) {
    87  	// blanks ignored; from a props perspective "x" is param 0
    88  	if x < 100 {
    89  		os.Exit(1)
    90  	}
    91  	println(x)
    92  }
    93  
    94  // params.go T_feeds_if_with_copy 101 0 1
    95  // ParamFlags
    96  //   0 ParamFeedsIfOrSwitch
    97  // <endpropsdump>
    98  // {"Flags":0,"ParamFlags":[32],"ResultFlags":null}
    99  // <endcallsites>
   100  // <endfuncpreamble>
   101  func T_feeds_if_with_copy(x int) {
   102  	// simple copy here -- we get this case
   103  	xx := x
   104  	if xx < 100 {
   105  		os.Exit(1)
   106  	}
   107  	println(x)
   108  }
   109  
   110  // params.go T_feeds_if_with_copy_expr 115 0 1
   111  // <endpropsdump>
   112  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
   113  // <endcallsites>
   114  // <endfuncpreamble>
   115  func T_feeds_if_with_copy_expr(x int) {
   116  	// this case (copy of expression) currently not handled.
   117  	xx := x < 100
   118  	if xx {
   119  		os.Exit(1)
   120  	}
   121  	println(x)
   122  }
   123  
   124  // params.go T_feeds_switch 131 0 1
   125  // ParamFlags
   126  //   0 ParamFeedsIfOrSwitch
   127  // <endpropsdump>
   128  // {"Flags":0,"ParamFlags":[32],"ResultFlags":null}
   129  // <endcallsites>
   130  // <endfuncpreamble>
   131  func T_feeds_switch(x int) {
   132  	switch x {
   133  	case 101:
   134  		println(101)
   135  	case 202:
   136  		panic("bad")
   137  	}
   138  	println(x)
   139  }
   140  
   141  // params.go T_feeds_if_toocomplex 146 0 1
   142  // <endpropsdump>
   143  // {"Flags":0,"ParamFlags":[0,0],"ResultFlags":null}
   144  // <endcallsites>
   145  // <endfuncpreamble>
   146  func T_feeds_if_toocomplex(x int, y int) {
   147  	// not handled at the moment; we only look for cases where
   148  	// an "if" or "switch" can be simplified based on a single
   149  	// constant param, not a combination of constant params.
   150  	if x < y {
   151  		panic("bad")
   152  	}
   153  	println(x + y)
   154  }
   155  
   156  // params.go T_feeds_if_redefined 161 0 1
   157  // <endpropsdump>
   158  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
   159  // <endcallsites>
   160  // <endfuncpreamble>
   161  func T_feeds_if_redefined(x int) {
   162  	if x < G {
   163  		x++
   164  	}
   165  	if x == 101 {
   166  		panic("bad")
   167  	}
   168  }
   169  
   170  // params.go T_feeds_if_redefined2 175 0 1
   171  // <endpropsdump>
   172  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
   173  // <endcallsites>
   174  // <endfuncpreamble>
   175  func T_feeds_if_redefined2(x int) {
   176  	// this currently classifies "x" as "no info", since the analysis we
   177  	// use to check for reassignments/redefinitions is not flow-sensitive,
   178  	// but we could probably catch this case with better analysis or
   179  	// high-level SSA.
   180  	if x == 101 {
   181  		panic("bad")
   182  	}
   183  	if x < G {
   184  		x++
   185  	}
   186  }
   187  
   188  // params.go T_feeds_multi_if 196 0 1
   189  // ParamFlags
   190  //   0 ParamFeedsIfOrSwitch
   191  //   1 ParamNoInfo
   192  // <endpropsdump>
   193  // {"Flags":0,"ParamFlags":[32,0],"ResultFlags":null}
   194  // <endcallsites>
   195  // <endfuncpreamble>
   196  func T_feeds_multi_if(x int, y int) {
   197  	// Here we have one "if" that is too complex (x < y) but one that is
   198  	// simple enough. Currently we enable the heuristic for this. It's
   199  	// possible to imagine this being a bad thing if the function in
   200  	// question is sufficiently large, but if it's too large we probably
   201  	// can't inline it anyhow.
   202  	if x < y {
   203  		panic("bad")
   204  	}
   205  	if x < 10 {
   206  		panic("whatev")
   207  	}
   208  	println(x + y)
   209  }
   210  
   211  // params.go T_feeds_if_redefined_indirectwrite 216 0 1
   212  // <endpropsdump>
   213  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
   214  // <endcallsites>
   215  // <endfuncpreamble>
   216  func T_feeds_if_redefined_indirectwrite(x int) {
   217  	ax := &x
   218  	if G != 2 {
   219  		*ax = G
   220  	}
   221  	if x == 101 {
   222  		panic("bad")
   223  	}
   224  }
   225  
   226  // params.go T_feeds_if_redefined_indirectwrite_copy 231 0 1
   227  // <endpropsdump>
   228  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
   229  // <endcallsites>
   230  // <endfuncpreamble>
   231  func T_feeds_if_redefined_indirectwrite_copy(x int) {
   232  	// we don't catch this case, "x" is marked as no info,
   233  	// since we're conservative about redefinitions.
   234  	ax := &x
   235  	cx := x
   236  	if G != 2 {
   237  		*ax = G
   238  	}
   239  	if cx == 101 {
   240  		panic("bad")
   241  	}
   242  }
   243  
   244  // params.go T_feeds_if_expr1 251 0 1
   245  // ParamFlags
   246  //   0 ParamFeedsIfOrSwitch
   247  // <endpropsdump>
   248  // {"Flags":0,"ParamFlags":[32],"ResultFlags":null}
   249  // <endcallsites>
   250  // <endfuncpreamble>
   251  func T_feeds_if_expr1(x int) {
   252  	if x == 101 || x == 102 || x&0xf == 0 {
   253  		panic("bad")
   254  	}
   255  }
   256  
   257  // params.go T_feeds_if_expr2 262 0 1
   258  // <endpropsdump>
   259  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
   260  // <endcallsites>
   261  // <endfuncpreamble>
   262  func T_feeds_if_expr2(x int) {
   263  	if (x*x)-(x+x)%x == 101 || x&0xf == 0 {
   264  		panic("bad")
   265  	}
   266  }
   267  
   268  // params.go T_feeds_if_expr3 273 0 1
   269  // <endpropsdump>
   270  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
   271  // <endcallsites>
   272  // <endfuncpreamble>
   273  func T_feeds_if_expr3(x int) {
   274  	if x-(x&0x1)^378 > (1 - G) {
   275  		panic("bad")
   276  	}
   277  }
   278  
   279  // params.go T_feeds_if_shift_may_panic 284 0 1
   280  // <endpropsdump>
   281  // {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
   282  // <endcallsites>
   283  // <endfuncpreamble>
   284  func T_feeds_if_shift_may_panic(x int) *int {
   285  	// here if "x" is a constant like 2, we could simplify the "if",
   286  	// but if we were to pass in a negative value for "x" we can't
   287  	// fold the condition due to the need to panic on negative shift.
   288  	if 1<<x > 1024 {
   289  		return nil
   290  	}
   291  	return &G
   292  }
   293  
   294  // params.go T_feeds_if_maybe_divide_by_zero 299 0 1
   295  // <endpropsdump>
   296  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
   297  // <endcallsites>
   298  // <endfuncpreamble>
   299  func T_feeds_if_maybe_divide_by_zero(x int) {
   300  	if 99/x == 3 {
   301  		return
   302  	}
   303  	println("blarg")
   304  }
   305  
   306  // params.go T_feeds_indcall 313 0 1
   307  // ParamFlags
   308  //   0 ParamMayFeedIndirectCall
   309  // <endpropsdump>
   310  // {"Flags":0,"ParamFlags":[16],"ResultFlags":null}
   311  // <endcallsites>
   312  // <endfuncpreamble>
   313  func T_feeds_indcall(x func()) {
   314  	if G != 20 {
   315  		x()
   316  	}
   317  }
   318  
   319  // params.go T_feeds_indcall_and_if 326 0 1
   320  // ParamFlags
   321  //   0 ParamMayFeedIndirectCall|ParamFeedsIfOrSwitch
   322  // <endpropsdump>
   323  // {"Flags":0,"ParamFlags":[48],"ResultFlags":null}
   324  // <endcallsites>
   325  // <endfuncpreamble>
   326  func T_feeds_indcall_and_if(x func()) {
   327  	if x != nil {
   328  		x()
   329  	}
   330  }
   331  
   332  // params.go T_feeds_indcall_with_copy 339 0 1
   333  // ParamFlags
   334  //   0 ParamFeedsIndirectCall
   335  // <endpropsdump>
   336  // {"Flags":0,"ParamFlags":[8],"ResultFlags":null}
   337  // <endcallsites>
   338  // <endfuncpreamble>
   339  func T_feeds_indcall_with_copy(x func()) {
   340  	xx := x
   341  	if G < 10 {
   342  		G--
   343  	}
   344  	xx()
   345  }
   346  
   347  // params.go T_feeds_interface_method_call 354 0 1
   348  // ParamFlags
   349  //   0 ParamFeedsInterfaceMethodCall
   350  // <endpropsdump>
   351  // {"Flags":0,"ParamFlags":[2],"ResultFlags":null}
   352  // <endcallsites>
   353  // <endfuncpreamble>
   354  func T_feeds_interface_method_call(i I) {
   355  	i.Blarg()
   356  }
   357  
   358  var G int
   359  
   360  type T int
   361  
   362  type I interface {
   363  	Blarg()
   364  }
   365  
   366  func (r T) Blarg() {
   367  }