github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/backend/backend_test.go (about)

     1  package backend_test
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"runtime"
     8  	"testing"
     9  
    10  	"github.com/tetratelabs/wazero/api"
    11  	"github.com/tetratelabs/wazero/experimental"
    12  	"github.com/tetratelabs/wazero/internal/engine/wazevo/backend"
    13  	"github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64"
    14  	"github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64"
    15  	"github.com/tetratelabs/wazero/internal/engine/wazevo/frontend"
    16  	"github.com/tetratelabs/wazero/internal/engine/wazevo/ssa"
    17  	"github.com/tetratelabs/wazero/internal/engine/wazevo/testcases"
    18  	"github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi"
    19  	"github.com/tetratelabs/wazero/internal/platform"
    20  	"github.com/tetratelabs/wazero/internal/testing/require"
    21  	"github.com/tetratelabs/wazero/internal/wasm"
    22  )
    23  
    24  func TestMain(m *testing.M) {
    25  	if !platform.CompilerSupported() {
    26  		os.Exit(0)
    27  	}
    28  	os.Exit(m.Run())
    29  }
    30  
    31  func newMachine() backend.Machine {
    32  	switch runtime.GOARCH {
    33  	case "arm64":
    34  		return arm64.NewBackend()
    35  	case "amd64":
    36  		return amd64.NewBackend()
    37  	default:
    38  		panic("unsupported architecture")
    39  	}
    40  }
    41  
    42  func TestE2E(t *testing.T) {
    43  	const verbose = false
    44  
    45  	type testCase struct {
    46  		name                                   string
    47  		m                                      *wasm.Module
    48  		targetIndex                            uint32
    49  		afterLoweringARM64, afterFinalizeARM64 string
    50  		afterLoweringAMD64, afterFinalizeAMD64 string
    51  	}
    52  
    53  	for _, tc := range []testCase{
    54  		{
    55  			name: "empty", m: testcases.Empty.Module,
    56  			afterLoweringARM64: `
    57  L1 (SSA Block: blk0):
    58  	ret
    59  `,
    60  			afterFinalizeARM64: `
    61  L1 (SSA Block: blk0):
    62  	stp x30, xzr, [sp, #-0x10]!
    63  	str xzr, [sp, #-0x10]!
    64  	add sp, sp, #0x10
    65  	ldr x30, [sp], #0x10
    66  	ret
    67  `,
    68  		},
    69  		{
    70  			name: "selects", m: testcases.Selects.Module,
    71  			afterFinalizeARM64: `
    72  L1 (SSA Block: blk0):
    73  	stp x30, xzr, [sp, #-0x10]!
    74  	str xzr, [sp, #-0x10]!
    75  	subs xzr, x4, x5
    76  	csel w0, w2, w3, eq
    77  	subs wzr, w3, wzr
    78  	csel x1, x4, x5, ne
    79  	fcmp d2, d3
    80  	fcsel s8, s0, s1, gt
    81  	fcmp s0, s1
    82  	fcsel d1, d2, d3, ne
    83  	mov v0.8b, v8.8b
    84  	add sp, sp, #0x10
    85  	ldr x30, [sp], #0x10
    86  	ret
    87  `,
    88  		},
    89  		{
    90  			name: "consts", m: testcases.Constants.Module,
    91  			afterLoweringARM64: `
    92  L1 (SSA Block: blk0):
    93  	ldr d133?, #8; b 16; data.f64 64.000000
    94  	mov v1.8b, v133?.8b
    95  	ldr s132?, #8; b 8; data.f32 32.000000
    96  	mov v0.8b, v132?.8b
    97  	orr x131?, xzr, #0x2
    98  	mov x1, x131?
    99  	orr w130?, wzr, #0x1
   100  	mov x0, x130?
   101  	ret
   102  `,
   103  			afterFinalizeARM64: `
   104  L1 (SSA Block: blk0):
   105  	stp x30, xzr, [sp, #-0x10]!
   106  	str xzr, [sp, #-0x10]!
   107  	ldr d1, #8; b 16; data.f64 64.000000
   108  	ldr s0, #8; b 8; data.f32 32.000000
   109  	orr x1, xzr, #0x2
   110  	orr w0, wzr, #0x1
   111  	add sp, sp, #0x10
   112  	ldr x30, [sp], #0x10
   113  	ret
   114  `,
   115  		},
   116  		{
   117  			name: "add sub params return", m: testcases.AddSubParamsReturn.Module,
   118  			afterLoweringARM64: `
   119  L1 (SSA Block: blk0):
   120  	mov x130?, x2
   121  	mov x131?, x3
   122  	add w132?, w130?, w131?
   123  	sub w133?, w132?, w130?
   124  	mov x0, x133?
   125  	ret
   126  `,
   127  			afterFinalizeARM64: `
   128  L1 (SSA Block: blk0):
   129  	stp x30, xzr, [sp, #-0x10]!
   130  	str xzr, [sp, #-0x10]!
   131  	add w8, w2, w3
   132  	sub w0, w8, w2
   133  	add sp, sp, #0x10
   134  	ldr x30, [sp], #0x10
   135  	ret
   136  `,
   137  		},
   138  		{
   139  			name: "locals params", m: testcases.LocalsParams.Module,
   140  			afterLoweringARM64: `
   141  L1 (SSA Block: blk0):
   142  	mov x130?, x2
   143  	mov v131?.8b, v0.8b
   144  	mov v132?.8b, v1.8b
   145  	add x133?, x130?, x130?
   146  	sub x134?, x133?, x130?
   147  	fadd s135?, s131?, s131?
   148  	fsub s136?, s135?, s131?
   149  	fmul s137?, s136?, s131?
   150  	fdiv s138?, s137?, s131?
   151  	fmax s139?, s138?, s131?
   152  	fmin s140?, s139?, s131?
   153  	fadd d141?, d132?, d132?
   154  	fsub d142?, d141?, d132?
   155  	fmul d143?, d142?, d132?
   156  	fdiv d144?, d143?, d132?
   157  	fmax d145?, d144?, d132?
   158  	fmin d146?, d145?, d132?
   159  	mov v1.8b, v146?.8b
   160  	mov v0.8b, v140?.8b
   161  	mov x0, x134?
   162  	ret
   163  `,
   164  			afterFinalizeARM64: `
   165  L1 (SSA Block: blk0):
   166  	stp x30, xzr, [sp, #-0x10]!
   167  	str xzr, [sp, #-0x10]!
   168  	add x8, x2, x2
   169  	sub x0, x8, x2
   170  	fadd s8, s0, s0
   171  	fsub s8, s8, s0
   172  	fmul s8, s8, s0
   173  	fdiv s8, s8, s0
   174  	fmax s8, s8, s0
   175  	fmin s0, s8, s0
   176  	fadd d8, d1, d1
   177  	fsub d8, d8, d1
   178  	fmul d8, d8, d1
   179  	fdiv d8, d8, d1
   180  	fmax d8, d8, d1
   181  	fmin d1, d8, d1
   182  	add sp, sp, #0x10
   183  	ldr x30, [sp], #0x10
   184  	ret
   185  `,
   186  		},
   187  		{
   188  			name: "local_param_return", m: testcases.LocalParamReturn.Module,
   189  			afterLoweringARM64: `
   190  L1 (SSA Block: blk0):
   191  	mov x130?, x2
   192  	mov x131?, xzr
   193  	mov x1, x131?
   194  	mov x0, x130?
   195  	ret
   196  `,
   197  			afterFinalizeARM64: `
   198  L1 (SSA Block: blk0):
   199  	stp x30, xzr, [sp, #-0x10]!
   200  	str xzr, [sp, #-0x10]!
   201  	mov x1, xzr
   202  	mov x0, x2
   203  	add sp, sp, #0x10
   204  	ldr x30, [sp], #0x10
   205  	ret
   206  `,
   207  		},
   208  		{
   209  			name: "swap_param_and_return", m: testcases.SwapParamAndReturn.Module,
   210  			afterLoweringARM64: `
   211  L1 (SSA Block: blk0):
   212  	mov x130?, x2
   213  	mov x131?, x3
   214  	mov x1, x130?
   215  	mov x0, x131?
   216  	ret
   217  `,
   218  			afterFinalizeARM64: `
   219  L1 (SSA Block: blk0):
   220  	stp x30, xzr, [sp, #-0x10]!
   221  	str xzr, [sp, #-0x10]!
   222  	mov x1, x2
   223  	mov x0, x3
   224  	add sp, sp, #0x10
   225  	ldr x30, [sp], #0x10
   226  	ret
   227  `,
   228  		},
   229  		{
   230  			name: "swap_params_and_return", m: testcases.SwapParamsAndReturn.Module,
   231  			afterLoweringARM64: `
   232  L1 (SSA Block: blk0):
   233  	mov x130?, x2
   234  	mov x131?, x3
   235  L2 (SSA Block: blk1):
   236  	mov x1, x130?
   237  	mov x0, x131?
   238  	ret
   239  `,
   240  			afterFinalizeARM64: `
   241  L1 (SSA Block: blk0):
   242  	stp x30, xzr, [sp, #-0x10]!
   243  	str xzr, [sp, #-0x10]!
   244  L2 (SSA Block: blk1):
   245  	mov x1, x2
   246  	mov x0, x3
   247  	add sp, sp, #0x10
   248  	ldr x30, [sp], #0x10
   249  	ret
   250  `,
   251  		},
   252  		{
   253  			name: "block_br", m: testcases.BlockBr.Module,
   254  			afterLoweringARM64: `
   255  L1 (SSA Block: blk0):
   256  L2 (SSA Block: blk1):
   257  	ret
   258  `,
   259  			afterFinalizeARM64: `
   260  L1 (SSA Block: blk0):
   261  	stp x30, xzr, [sp, #-0x10]!
   262  	str xzr, [sp, #-0x10]!
   263  L2 (SSA Block: blk1):
   264  	add sp, sp, #0x10
   265  	ldr x30, [sp], #0x10
   266  	ret
   267  `,
   268  		},
   269  		{
   270  			name: "block_br_if", m: testcases.BlockBrIf.Module,
   271  			afterLoweringARM64: `
   272  L1 (SSA Block: blk0):
   273  	mov x128?, x0
   274  	mov x131?, xzr
   275  	cbnz w131?, L2
   276  L3 (SSA Block: blk2):
   277  	movz x132?, #0x3, lsl 0
   278  	str w132?, [x128?]
   279  	mov x133?, sp
   280  	str x133?, [x128?, #0x38]
   281  	adr x134?, #0x0
   282  	str x134?, [x128?, #0x30]
   283  	exit_sequence x128?
   284  L2 (SSA Block: blk1):
   285  	ret
   286  `,
   287  			afterFinalizeARM64: `
   288  L1 (SSA Block: blk0):
   289  	stp x30, xzr, [sp, #-0x10]!
   290  	str xzr, [sp, #-0x10]!
   291  	mov x8, xzr
   292  	cbnz w8, #0x34 (L2)
   293  L3 (SSA Block: blk2):
   294  	movz x8, #0x3, lsl 0
   295  	str w8, [x0]
   296  	mov x8, sp
   297  	str x8, [x0, #0x38]
   298  	adr x8, #0x0
   299  	str x8, [x0, #0x30]
   300  	exit_sequence x0
   301  L2 (SSA Block: blk1):
   302  	add sp, sp, #0x10
   303  	ldr x30, [sp], #0x10
   304  	ret
   305  `,
   306  		},
   307  		{
   308  			name: "loop_br", m: testcases.LoopBr.Module,
   309  			afterLoweringARM64: `
   310  L1 (SSA Block: blk0):
   311  L2 (SSA Block: blk1):
   312  	b L2
   313  `,
   314  			afterFinalizeARM64: `
   315  L1 (SSA Block: blk0):
   316  	stp x30, xzr, [sp, #-0x10]!
   317  	str xzr, [sp, #-0x10]!
   318  L2 (SSA Block: blk1):
   319  	b #0x0 (L2)
   320  `,
   321  		},
   322  		{
   323  			name: "loop_with_param_results", m: testcases.LoopBrWithParamResults.Module,
   324  			afterLoweringARM64: `
   325  L1 (SSA Block: blk0):
   326  	mov x130?, x2
   327  L2 (SSA Block: blk1):
   328  	orr w133?, wzr, #0x1
   329  	cbz w133?, (L3)
   330  L4 (SSA Block: blk4):
   331  	b L2
   332  L3 (SSA Block: blk3):
   333  L5 (SSA Block: blk2):
   334  	mov x0, x130?
   335  	ret
   336  `,
   337  			afterFinalizeARM64: `
   338  L1 (SSA Block: blk0):
   339  	stp x30, xzr, [sp, #-0x10]!
   340  	str xzr, [sp, #-0x10]!
   341  L2 (SSA Block: blk1):
   342  	orr w8, wzr, #0x1
   343  	cbz w8, #0x8 L3
   344  L4 (SSA Block: blk4):
   345  	b #-0x8 (L2)
   346  L3 (SSA Block: blk3):
   347  L5 (SSA Block: blk2):
   348  	mov x0, x2
   349  	add sp, sp, #0x10
   350  	ldr x30, [sp], #0x10
   351  	ret
   352  `,
   353  		},
   354  		{
   355  			name: "loop_br_if", m: testcases.LoopBrIf.Module,
   356  			afterLoweringARM64: `
   357  L1 (SSA Block: blk0):
   358  L2 (SSA Block: blk1):
   359  	orr w131?, wzr, #0x1
   360  	cbz w131?, (L3)
   361  L4 (SSA Block: blk4):
   362  	b L2
   363  L3 (SSA Block: blk3):
   364  	ret
   365  `,
   366  			afterFinalizeARM64: `
   367  L1 (SSA Block: blk0):
   368  	stp x30, xzr, [sp, #-0x10]!
   369  	str xzr, [sp, #-0x10]!
   370  L2 (SSA Block: blk1):
   371  	orr w8, wzr, #0x1
   372  	cbz w8, #0x8 L3
   373  L4 (SSA Block: blk4):
   374  	b #-0x8 (L2)
   375  L3 (SSA Block: blk3):
   376  	add sp, sp, #0x10
   377  	ldr x30, [sp], #0x10
   378  	ret
   379  `,
   380  		},
   381  		{
   382  			name: "block_block_br", m: testcases.BlockBlockBr.Module,
   383  			afterLoweringARM64: `
   384  L1 (SSA Block: blk0):
   385  L2 (SSA Block: blk1):
   386  	ret
   387  `,
   388  			afterFinalizeARM64: `
   389  L1 (SSA Block: blk0):
   390  	stp x30, xzr, [sp, #-0x10]!
   391  	str xzr, [sp, #-0x10]!
   392  L2 (SSA Block: blk1):
   393  	add sp, sp, #0x10
   394  	ldr x30, [sp], #0x10
   395  	ret
   396  `,
   397  		},
   398  		{
   399  			name: "if_without_else", m: testcases.IfWithoutElse.Module,
   400  			// Note: The block of "b L4" seems redundant, but it is needed when we need to insert return value preparations.
   401  			// So we cannot have the general optimization on this kind of redundant branch elimination before register allocations.
   402  			// Instead, we can do it during the code generation phase where we actually resolve the label offsets.
   403  			afterLoweringARM64: `
   404  L1 (SSA Block: blk0):
   405  	mov x131?, xzr
   406  	cbz w131?, (L2)
   407  L3 (SSA Block: blk1):
   408  	b L4
   409  L2 (SSA Block: blk2):
   410  L4 (SSA Block: blk3):
   411  	ret
   412  `,
   413  			afterFinalizeARM64: `
   414  L1 (SSA Block: blk0):
   415  	stp x30, xzr, [sp, #-0x10]!
   416  	str xzr, [sp, #-0x10]!
   417  	mov x8, xzr
   418  	cbz w8, #0x8 L2
   419  L3 (SSA Block: blk1):
   420  	b #0x4 (L4)
   421  L2 (SSA Block: blk2):
   422  L4 (SSA Block: blk3):
   423  	add sp, sp, #0x10
   424  	ldr x30, [sp], #0x10
   425  	ret
   426  `,
   427  		},
   428  		{
   429  			name: "if_else", m: testcases.IfElse.Module,
   430  			afterLoweringARM64: `
   431  L1 (SSA Block: blk0):
   432  	mov x131?, xzr
   433  	cbz w131?, (L2)
   434  L3 (SSA Block: blk1):
   435  L4 (SSA Block: blk3):
   436  	ret
   437  L2 (SSA Block: blk2):
   438  	ret
   439  `,
   440  			afterFinalizeARM64: `
   441  L1 (SSA Block: blk0):
   442  	stp x30, xzr, [sp, #-0x10]!
   443  	str xzr, [sp, #-0x10]!
   444  	mov x8, xzr
   445  	cbz w8, #0x10 L2
   446  L3 (SSA Block: blk1):
   447  L4 (SSA Block: blk3):
   448  	add sp, sp, #0x10
   449  	ldr x30, [sp], #0x10
   450  	ret
   451  L2 (SSA Block: blk2):
   452  	add sp, sp, #0x10
   453  	ldr x30, [sp], #0x10
   454  	ret
   455  `,
   456  		},
   457  		{
   458  			name: "single_predecessor_local_refs", m: testcases.SinglePredecessorLocalRefs.Module,
   459  			afterLoweringARM64: `
   460  L1 (SSA Block: blk0):
   461  	mov x132?, xzr
   462  	cbz w132?, (L2)
   463  L3 (SSA Block: blk1):
   464  	mov x131?, xzr
   465  	mov x0, x131?
   466  	ret
   467  L2 (SSA Block: blk2):
   468  L4 (SSA Block: blk3):
   469  	mov x130?, xzr
   470  	mov x0, x130?
   471  	ret
   472  `,
   473  			afterFinalizeARM64: `
   474  L1 (SSA Block: blk0):
   475  	stp x30, xzr, [sp, #-0x10]!
   476  	str xzr, [sp, #-0x10]!
   477  	mov x8, xzr
   478  	cbz w8, #0x14 L2
   479  L3 (SSA Block: blk1):
   480  	mov x0, xzr
   481  	add sp, sp, #0x10
   482  	ldr x30, [sp], #0x10
   483  	ret
   484  L2 (SSA Block: blk2):
   485  L4 (SSA Block: blk3):
   486  	mov x0, xzr
   487  	add sp, sp, #0x10
   488  	ldr x30, [sp], #0x10
   489  	ret
   490  `,
   491  		},
   492  		{
   493  			name: "multi_predecessor_local_ref", m: testcases.MultiPredecessorLocalRef.Module,
   494  			afterLoweringARM64: `
   495  L1 (SSA Block: blk0):
   496  	mov x130?, x2
   497  	mov x131?, x3
   498  	cbz w130?, (L2)
   499  L3 (SSA Block: blk1):
   500  	mov x132?, x130?
   501  	b L4
   502  L2 (SSA Block: blk2):
   503  	mov x132?, x131?
   504  L4 (SSA Block: blk3):
   505  	mov x0, x132?
   506  	ret
   507  `,
   508  			afterFinalizeARM64: `
   509  L1 (SSA Block: blk0):
   510  	stp x30, xzr, [sp, #-0x10]!
   511  	str xzr, [sp, #-0x10]!
   512  	cbz w2, #0x8 L2
   513  L3 (SSA Block: blk1):
   514  	b #0x8 (L4)
   515  L2 (SSA Block: blk2):
   516  	mov x2, x3
   517  L4 (SSA Block: blk3):
   518  	mov x0, x2
   519  	add sp, sp, #0x10
   520  	ldr x30, [sp], #0x10
   521  	ret
   522  `,
   523  		},
   524  		{
   525  			name: "reference_value_from_unsealed_block", m: testcases.ReferenceValueFromUnsealedBlock.Module,
   526  			afterLoweringARM64: `
   527  L1 (SSA Block: blk0):
   528  	mov x130?, x2
   529  L2 (SSA Block: blk1):
   530  	mov x0, x130?
   531  	ret
   532  `,
   533  			afterFinalizeARM64: `
   534  L1 (SSA Block: blk0):
   535  	stp x30, xzr, [sp, #-0x10]!
   536  	str xzr, [sp, #-0x10]!
   537  L2 (SSA Block: blk1):
   538  	mov x0, x2
   539  	add sp, sp, #0x10
   540  	ldr x30, [sp], #0x10
   541  	ret
   542  `,
   543  		},
   544  		{
   545  			name: "reference_value_from_unsealed_block2", m: testcases.ReferenceValueFromUnsealedBlock2.Module,
   546  			afterLoweringARM64: `
   547  L1 (SSA Block: blk0):
   548  	mov x130?, x2
   549  L2 (SSA Block: blk1):
   550  	cbz w130?, (L3)
   551  L4 (SSA Block: blk5):
   552  	b L2
   553  L3 (SSA Block: blk4):
   554  L5 (SSA Block: blk3):
   555  L6 (SSA Block: blk2):
   556  	mov x131?, xzr
   557  	mov x0, x131?
   558  	ret
   559  `,
   560  			afterFinalizeARM64: `
   561  L1 (SSA Block: blk0):
   562  	stp x30, xzr, [sp, #-0x10]!
   563  	str xzr, [sp, #-0x10]!
   564  L2 (SSA Block: blk1):
   565  	cbz w2, #0x8 L3
   566  L4 (SSA Block: blk5):
   567  	b #-0x4 (L2)
   568  L3 (SSA Block: blk4):
   569  L5 (SSA Block: blk3):
   570  L6 (SSA Block: blk2):
   571  	mov x0, xzr
   572  	add sp, sp, #0x10
   573  	ldr x30, [sp], #0x10
   574  	ret
   575  `,
   576  		},
   577  		{
   578  			name: "reference_value_from_unsealed_block3", m: testcases.ReferenceValueFromUnsealedBlock3.Module,
   579  			// TODO: we should be able to invert cbnz in so that L2 can end with fallthrough. investigate builder.LayoutBlocks function.
   580  			afterLoweringARM64: `
   581  L1 (SSA Block: blk0):
   582  	mov x130?, x2
   583  	mov x131?, x130?
   584  L2 (SSA Block: blk1):
   585  	cbnz w131?, L4
   586  	b L3
   587  L4 (SSA Block: blk5):
   588  	ret
   589  L3 (SSA Block: blk4):
   590  L5 (SSA Block: blk3):
   591  	load_const_block_arg x131?, 0x1
   592  	b L2
   593  `,
   594  			afterFinalizeARM64: `
   595  L1 (SSA Block: blk0):
   596  	stp x30, xzr, [sp, #-0x10]!
   597  	str xzr, [sp, #-0x10]!
   598  L2 (SSA Block: blk1):
   599  	cbnz w2, #0x8 (L4)
   600  	b #0x10 (L3)
   601  L4 (SSA Block: blk5):
   602  	add sp, sp, #0x10
   603  	ldr x30, [sp], #0x10
   604  	ret
   605  L3 (SSA Block: blk4):
   606  L5 (SSA Block: blk3):
   607  	load_const_block_arg x2, 0x1
   608  	orr w2, wzr, #0x1
   609  	b #-0x18 (L2)
   610  `,
   611  		},
   612  		{
   613  			name: "call", m: testcases.Call.Module,
   614  			afterLoweringARM64: `
   615  L1 (SSA Block: blk0):
   616  	mov x128?, x0
   617  	mov x129?, x1
   618  	mov x0, x128?
   619  	mov x1, x129?
   620  	bl f1
   621  	mov x130?, x0
   622  	mov x0, x128?
   623  	mov x1, x129?
   624  	mov x2, x130?
   625  	movz w131?, #0x5, lsl 0
   626  	mov x3, x131?
   627  	bl f2
   628  	mov x132?, x0
   629  	mov x0, x128?
   630  	mov x1, x129?
   631  	mov x2, x132?
   632  	bl f3
   633  	mov x133?, x0
   634  	mov x134?, x1
   635  	mov x1, x134?
   636  	mov x0, x133?
   637  	ret
   638  `,
   639  			afterFinalizeARM64: `
   640  L1 (SSA Block: blk0):
   641  	stp x30, xzr, [sp, #-0x10]!
   642  	sub sp, sp, #0x10
   643  	orr x27, xzr, #0x10
   644  	str x27, [sp, #-0x10]!
   645  	str x0, [sp, #0x10]
   646  	str x1, [sp, #0x18]
   647  	bl f1
   648  	mov x2, x0
   649  	ldr x8, [sp, #0x10]
   650  	mov x0, x8
   651  	ldr x9, [sp, #0x18]
   652  	mov x1, x9
   653  	movz w3, #0x5, lsl 0
   654  	bl f2
   655  	mov x2, x0
   656  	ldr x8, [sp, #0x10]
   657  	mov x0, x8
   658  	ldr x8, [sp, #0x18]
   659  	mov x1, x8
   660  	bl f3
   661  	add sp, sp, #0x10
   662  	add sp, sp, #0x10
   663  	ldr x30, [sp], #0x10
   664  	ret
   665  `,
   666  		},
   667  		{
   668  			name: "call_many_params", m: testcases.CallManyParams.Module,
   669  			afterLoweringARM64: `
   670  L1 (SSA Block: blk0):
   671  	mov x128?, x0
   672  	mov x129?, x1
   673  	mov x130?, x2
   674  	mov x131?, x3
   675  	mov v132?.8b, v0.8b
   676  	mov v133?.8b, v1.8b
   677  	mov x0, x128?
   678  	mov x1, x129?
   679  	mov x2, x130?
   680  	mov x3, x131?
   681  	mov v0.8b, v132?.8b
   682  	mov v1.8b, v133?.8b
   683  	mov x4, x130?
   684  	mov x5, x131?
   685  	mov v2.8b, v132?.8b
   686  	mov v3.8b, v133?.8b
   687  	mov x6, x130?
   688  	mov x7, x131?
   689  	mov v4.8b, v132?.8b
   690  	mov v5.8b, v133?.8b
   691  	str w130?, [sp, #-0xd0]
   692  	str x131?, [sp, #-0xc8]
   693  	mov v6.8b, v132?.8b
   694  	mov v7.8b, v133?.8b
   695  	str w130?, [sp, #-0xc0]
   696  	str x131?, [sp, #-0xb8]
   697  	str s132?, [sp, #-0xb0]
   698  	str d133?, [sp, #-0xa8]
   699  	str w130?, [sp, #-0xa0]
   700  	str x131?, [sp, #-0x98]
   701  	str s132?, [sp, #-0x90]
   702  	str d133?, [sp, #-0x88]
   703  	str w130?, [sp, #-0x80]
   704  	str x131?, [sp, #-0x78]
   705  	str s132?, [sp, #-0x70]
   706  	str d133?, [sp, #-0x68]
   707  	str w130?, [sp, #-0x60]
   708  	str x131?, [sp, #-0x58]
   709  	str s132?, [sp, #-0x50]
   710  	str d133?, [sp, #-0x48]
   711  	str w130?, [sp, #-0x40]
   712  	str x131?, [sp, #-0x38]
   713  	str s132?, [sp, #-0x30]
   714  	str d133?, [sp, #-0x28]
   715  	str w130?, [sp, #-0x20]
   716  	str x131?, [sp, #-0x18]
   717  	str s132?, [sp, #-0x10]
   718  	str d133?, [sp, #-0x8]
   719  	bl f1
   720  	ret
   721  `,
   722  			afterFinalizeARM64: `
   723  L1 (SSA Block: blk0):
   724  	stp x30, xzr, [sp, #-0x10]!
   725  	sub sp, sp, #0x20
   726  	orr x27, xzr, #0x20
   727  	str x27, [sp, #-0x10]!
   728  	str w2, [sp, #0x10]
   729  	str x3, [sp, #0x14]
   730  	str s0, [sp, #0x1c]
   731  	str d1, [sp, #0x20]
   732  	ldr w8, [sp, #0x10]
   733  	mov x4, x8
   734  	ldr x9, [sp, #0x14]
   735  	mov x5, x9
   736  	ldr s8, [sp, #0x1c]
   737  	mov v2.8b, v8.8b
   738  	ldr d9, [sp, #0x20]
   739  	mov v3.8b, v9.8b
   740  	mov x6, x8
   741  	mov x7, x9
   742  	mov v4.8b, v8.8b
   743  	mov v5.8b, v9.8b
   744  	str w8, [sp, #-0xd0]
   745  	str x9, [sp, #-0xc8]
   746  	mov v6.8b, v8.8b
   747  	mov v7.8b, v9.8b
   748  	str w8, [sp, #-0xc0]
   749  	str x9, [sp, #-0xb8]
   750  	str s8, [sp, #-0xb0]
   751  	str d9, [sp, #-0xa8]
   752  	str w8, [sp, #-0xa0]
   753  	str x9, [sp, #-0x98]
   754  	str s8, [sp, #-0x90]
   755  	str d9, [sp, #-0x88]
   756  	str w8, [sp, #-0x80]
   757  	str x9, [sp, #-0x78]
   758  	str s8, [sp, #-0x70]
   759  	str d9, [sp, #-0x68]
   760  	str w8, [sp, #-0x60]
   761  	str x9, [sp, #-0x58]
   762  	str s8, [sp, #-0x50]
   763  	str d9, [sp, #-0x48]
   764  	str w8, [sp, #-0x40]
   765  	str x9, [sp, #-0x38]
   766  	str s8, [sp, #-0x30]
   767  	str d9, [sp, #-0x28]
   768  	str w8, [sp, #-0x20]
   769  	str x9, [sp, #-0x18]
   770  	str s8, [sp, #-0x10]
   771  	str d9, [sp, #-0x8]
   772  	bl f1
   773  	add sp, sp, #0x10
   774  	add sp, sp, #0x20
   775  	ldr x30, [sp], #0x10
   776  	ret
   777  `,
   778  		},
   779  		{
   780  			name: "call_many_returns", m: testcases.CallManyReturns.Module,
   781  			afterLoweringARM64: `
   782  L1 (SSA Block: blk0):
   783  	mov x128?, x0
   784  	mov x129?, x1
   785  	mov x130?, x2
   786  	mov x131?, x3
   787  	mov v132?.8b, v0.8b
   788  	mov v133?.8b, v1.8b
   789  	mov x0, x128?
   790  	mov x1, x129?
   791  	mov x2, x130?
   792  	mov x3, x131?
   793  	mov v0.8b, v132?.8b
   794  	mov v1.8b, v133?.8b
   795  	bl f1
   796  	mov x134?, x0
   797  	mov x135?, x1
   798  	mov v136?.8b, v0.8b
   799  	mov v137?.8b, v1.8b
   800  	mov x138?, x2
   801  	mov x139?, x3
   802  	mov v140?.8b, v2.8b
   803  	mov v141?.8b, v3.8b
   804  	mov x142?, x4
   805  	mov x143?, x5
   806  	mov v144?.8b, v4.8b
   807  	mov v145?.8b, v5.8b
   808  	mov x146?, x6
   809  	mov x147?, x7
   810  	mov v148?.8b, v6.8b
   811  	mov v149?.8b, v7.8b
   812  	ldr w150?, [sp, #-0xc0]
   813  	ldr x151?, [sp, #-0xb8]
   814  	ldr s152?, [sp, #-0xb0]
   815  	ldr d153?, [sp, #-0xa8]
   816  	ldr w154?, [sp, #-0xa0]
   817  	ldr x155?, [sp, #-0x98]
   818  	ldr s156?, [sp, #-0x90]
   819  	ldr d157?, [sp, #-0x88]
   820  	ldr w158?, [sp, #-0x80]
   821  	ldr x159?, [sp, #-0x78]
   822  	ldr s160?, [sp, #-0x70]
   823  	ldr d161?, [sp, #-0x68]
   824  	ldr w162?, [sp, #-0x60]
   825  	ldr x163?, [sp, #-0x58]
   826  	ldr s164?, [sp, #-0x50]
   827  	ldr d165?, [sp, #-0x48]
   828  	ldr w166?, [sp, #-0x40]
   829  	ldr x167?, [sp, #-0x38]
   830  	ldr s168?, [sp, #-0x30]
   831  	ldr d169?, [sp, #-0x28]
   832  	ldr w170?, [sp, #-0x20]
   833  	ldr x171?, [sp, #-0x18]
   834  	ldr s172?, [sp, #-0x10]
   835  	ldr d173?, [sp, #-0x8]
   836  	str d173?, [#ret_space, #0xb8]
   837  	str s172?, [#ret_space, #0xb0]
   838  	str x171?, [#ret_space, #0xa8]
   839  	str w170?, [#ret_space, #0xa0]
   840  	str d169?, [#ret_space, #0x98]
   841  	str s168?, [#ret_space, #0x90]
   842  	str x167?, [#ret_space, #0x88]
   843  	str w166?, [#ret_space, #0x80]
   844  	str d165?, [#ret_space, #0x78]
   845  	str s164?, [#ret_space, #0x70]
   846  	str x163?, [#ret_space, #0x68]
   847  	str w162?, [#ret_space, #0x60]
   848  	str d161?, [#ret_space, #0x58]
   849  	str s160?, [#ret_space, #0x50]
   850  	str x159?, [#ret_space, #0x48]
   851  	str w158?, [#ret_space, #0x40]
   852  	str d157?, [#ret_space, #0x38]
   853  	str s156?, [#ret_space, #0x30]
   854  	str x155?, [#ret_space, #0x28]
   855  	str w154?, [#ret_space, #0x20]
   856  	str d153?, [#ret_space, #0x18]
   857  	str s152?, [#ret_space, #0x10]
   858  	str x151?, [#ret_space, #0x8]
   859  	str w150?, [#ret_space, #0x0]
   860  	mov v7.8b, v149?.8b
   861  	mov v6.8b, v148?.8b
   862  	mov x7, x147?
   863  	mov x6, x146?
   864  	mov v5.8b, v145?.8b
   865  	mov v4.8b, v144?.8b
   866  	mov x5, x143?
   867  	mov x4, x142?
   868  	mov v3.8b, v141?.8b
   869  	mov v2.8b, v140?.8b
   870  	mov x3, x139?
   871  	mov x2, x138?
   872  	mov v1.8b, v137?.8b
   873  	mov v0.8b, v136?.8b
   874  	mov x1, x135?
   875  	mov x0, x134?
   876  	ret
   877  `,
   878  			afterFinalizeARM64: `
   879  L1 (SSA Block: blk0):
   880  	orr x27, xzr, #0xc0
   881  	sub sp, sp, x27
   882  	stp x30, x27, [sp, #-0x10]!
   883  	str x19, [sp, #-0x10]!
   884  	str x20, [sp, #-0x10]!
   885  	str q18, [sp, #-0x10]!
   886  	str q19, [sp, #-0x10]!
   887  	orr x27, xzr, #0x40
   888  	str x27, [sp, #-0x10]!
   889  	bl f1
   890  	ldr w8, [sp, #-0xc0]
   891  	ldr x9, [sp, #-0xb8]
   892  	ldr s8, [sp, #-0xb0]
   893  	ldr d9, [sp, #-0xa8]
   894  	ldr w10, [sp, #-0xa0]
   895  	ldr x11, [sp, #-0x98]
   896  	ldr s10, [sp, #-0x90]
   897  	ldr d11, [sp, #-0x88]
   898  	ldr w12, [sp, #-0x80]
   899  	ldr x13, [sp, #-0x78]
   900  	ldr s12, [sp, #-0x70]
   901  	ldr d13, [sp, #-0x68]
   902  	ldr w14, [sp, #-0x60]
   903  	ldr x15, [sp, #-0x58]
   904  	ldr s14, [sp, #-0x50]
   905  	ldr d15, [sp, #-0x48]
   906  	ldr w16, [sp, #-0x40]
   907  	ldr x17, [sp, #-0x38]
   908  	ldr s16, [sp, #-0x30]
   909  	ldr d17, [sp, #-0x28]
   910  	ldr w19, [sp, #-0x20]
   911  	ldr x20, [sp, #-0x18]
   912  	ldr s18, [sp, #-0x10]
   913  	ldr d19, [sp, #-0x8]
   914  	str d19, [sp, #0x118]
   915  	str s18, [sp, #0x110]
   916  	str x20, [sp, #0x108]
   917  	str w19, [sp, #0x100]
   918  	str d17, [sp, #0xf8]
   919  	str s16, [sp, #0xf0]
   920  	str x17, [sp, #0xe8]
   921  	str w16, [sp, #0xe0]
   922  	str d15, [sp, #0xd8]
   923  	str s14, [sp, #0xd0]
   924  	str x15, [sp, #0xc8]
   925  	str w14, [sp, #0xc0]
   926  	str d13, [sp, #0xb8]
   927  	str s12, [sp, #0xb0]
   928  	str x13, [sp, #0xa8]
   929  	str w12, [sp, #0xa0]
   930  	str d11, [sp, #0x98]
   931  	str s10, [sp, #0x90]
   932  	str x11, [sp, #0x88]
   933  	str w10, [sp, #0x80]
   934  	str d9, [sp, #0x78]
   935  	str s8, [sp, #0x70]
   936  	str x9, [sp, #0x68]
   937  	str w8, [sp, #0x60]
   938  	add sp, sp, #0x10
   939  	ldr q19, [sp], #0x10
   940  	ldr q18, [sp], #0x10
   941  	ldr x20, [sp], #0x10
   942  	ldr x19, [sp], #0x10
   943  	ldr x30, [sp], #0x10
   944  	add sp, sp, #0xc0
   945  	ret
   946  `,
   947  		},
   948  		{
   949  			name: "integer_extensions",
   950  			m:    testcases.IntegerExtensions.Module,
   951  			afterLoweringARM64: `
   952  L1 (SSA Block: blk0):
   953  	mov x130?, x2
   954  	mov x131?, x3
   955  	sxtw x132?, w130?
   956  	uxtw x133?, w130?
   957  	sxtb x134?, w131?
   958  	sxth x135?, w131?
   959  	sxtw x136?, w131?
   960  	sxtb w137?, w130?
   961  	sxth w138?, w130?
   962  	mov x6, x138?
   963  	mov x5, x137?
   964  	mov x4, x136?
   965  	mov x3, x135?
   966  	mov x2, x134?
   967  	mov x1, x133?
   968  	mov x0, x132?
   969  	ret
   970  `,
   971  			afterFinalizeARM64: `
   972  L1 (SSA Block: blk0):
   973  	stp x30, xzr, [sp, #-0x10]!
   974  	str xzr, [sp, #-0x10]!
   975  	sxtw x0, w2
   976  	uxtw x1, w2
   977  	sxtb x8, w3
   978  	sxth x9, w3
   979  	sxtw x4, w3
   980  	sxtb w5, w2
   981  	sxth w6, w2
   982  	mov x3, x9
   983  	mov x2, x8
   984  	add sp, sp, #0x10
   985  	ldr x30, [sp], #0x10
   986  	ret
   987  `,
   988  		},
   989  		{
   990  			name: "integer bit counts", m: testcases.IntegerBitCounts.Module,
   991  			afterLoweringARM64: `
   992  L1 (SSA Block: blk0):
   993  	mov x130?, x2
   994  	mov x131?, x3
   995  	clz w132?, w130?
   996  	rbit w145?, w130?
   997  	clz w133?, w145?
   998  	ins v142?.d[0], x130?
   999  	cnt v143?.16b, v142?.16b
  1000  	uaddlv h144?, v143?.8b
  1001  	mov x134?, v144?.d[0]
  1002  	clz x135?, x131?
  1003  	rbit x141?, x131?
  1004  	clz x136?, x141?
  1005  	ins v138?.d[0], x131?
  1006  	cnt v139?.16b, v138?.16b
  1007  	uaddlv h140?, v139?.8b
  1008  	mov x137?, v140?.d[0]
  1009  	mov x5, x137?
  1010  	mov x4, x136?
  1011  	mov x3, x135?
  1012  	mov x2, x134?
  1013  	mov x1, x133?
  1014  	mov x0, x132?
  1015  	ret
  1016  `,
  1017  			afterFinalizeARM64: `
  1018  L1 (SSA Block: blk0):
  1019  	stp x30, xzr, [sp, #-0x10]!
  1020  	str xzr, [sp, #-0x10]!
  1021  	clz w0, w2
  1022  	rbit w8, w2
  1023  	clz w1, w8
  1024  	ins v8.d[0], x2
  1025  	cnt v8.16b, v8.16b
  1026  	uaddlv h8, v8.8b
  1027  	mov x2, v8.d[0]
  1028  	clz x8, x3
  1029  	rbit x9, x3
  1030  	clz x4, x9
  1031  	ins v8.d[0], x3
  1032  	cnt v8.16b, v8.16b
  1033  	uaddlv h8, v8.8b
  1034  	mov x5, v8.d[0]
  1035  	mov x3, x8
  1036  	add sp, sp, #0x10
  1037  	ldr x30, [sp], #0x10
  1038  	ret
  1039  `,
  1040  		},
  1041  		{
  1042  			name: "float_comparisons",
  1043  			m:    testcases.FloatComparisons.Module,
  1044  			afterFinalizeARM64: `
  1045  L1 (SSA Block: blk0):
  1046  	orr x27, xzr, #0x20
  1047  	sub sp, sp, x27
  1048  	stp x30, x27, [sp, #-0x10]!
  1049  	str xzr, [sp, #-0x10]!
  1050  	fcmp s0, s1
  1051  	cset x0, eq
  1052  	fcmp s0, s1
  1053  	cset x1, ne
  1054  	fcmp s0, s1
  1055  	cset x2, mi
  1056  	fcmp s0, s1
  1057  	cset x3, gt
  1058  	fcmp s0, s1
  1059  	cset x4, ls
  1060  	fcmp s0, s1
  1061  	cset x5, ge
  1062  	fcmp d2, d3
  1063  	cset x6, eq
  1064  	fcmp d2, d3
  1065  	cset x7, ne
  1066  	fcmp d2, d3
  1067  	cset x8, mi
  1068  	fcmp d2, d3
  1069  	cset x9, gt
  1070  	fcmp d2, d3
  1071  	cset x10, ls
  1072  	fcmp d2, d3
  1073  	cset x11, ge
  1074  	str w11, [sp, #0x38]
  1075  	str w10, [sp, #0x30]
  1076  	str w9, [sp, #0x28]
  1077  	str w8, [sp, #0x20]
  1078  	add sp, sp, #0x10
  1079  	ldr x30, [sp], #0x10
  1080  	add sp, sp, #0x20
  1081  	ret
  1082  `,
  1083  		},
  1084  		{
  1085  			name: "float_conversions",
  1086  			m:    testcases.FloatConversions.Module,
  1087  			afterFinalizeARM64: `
  1088  L1 (SSA Block: blk0):
  1089  	stp x30, xzr, [sp, #-0x10]!
  1090  	str xzr, [sp, #-0x10]!
  1091  	msr fpsr, xzr
  1092  	fcvtzs x8, d0
  1093  	mrs x9 fpsr
  1094  	mov x10, x0
  1095  	mov v8.16b, v0.16b
  1096  	subs xzr, x9, #0x1
  1097  	b.ne #0x70, (L17)
  1098  	fcmp d8, d8
  1099  	mov x9, x10
  1100  	b.vc #0x34, (L16)
  1101  	movz x11, #0xc, lsl 0
  1102  	str w11, [x9]
  1103  	mov x11, sp
  1104  	str x11, [x9, #0x38]
  1105  	adr x11, #0x0
  1106  	str x11, [x9, #0x30]
  1107  	exit_sequence x9
  1108  L16:
  1109  	movz x9, #0xb, lsl 0
  1110  	str w9, [x10]
  1111  	mov x9, sp
  1112  	str x9, [x10, #0x38]
  1113  	adr x9, #0x0
  1114  	str x9, [x10, #0x30]
  1115  	exit_sequence x10
  1116  L17:
  1117  	msr fpsr, xzr
  1118  	fcvtzs x1, s1
  1119  	mrs x9 fpsr
  1120  	mov x10, x0
  1121  	mov v8.16b, v1.16b
  1122  	subs xzr, x9, #0x1
  1123  	b.ne #0x70, (L15)
  1124  	fcmp s8, s8
  1125  	mov x9, x10
  1126  	b.vc #0x34, (L14)
  1127  	movz x11, #0xc, lsl 0
  1128  	str w11, [x9]
  1129  	mov x11, sp
  1130  	str x11, [x9, #0x38]
  1131  	adr x11, #0x0
  1132  	str x11, [x9, #0x30]
  1133  	exit_sequence x9
  1134  L14:
  1135  	movz x9, #0xb, lsl 0
  1136  	str w9, [x10]
  1137  	mov x9, sp
  1138  	str x9, [x10, #0x38]
  1139  	adr x9, #0x0
  1140  	str x9, [x10, #0x30]
  1141  	exit_sequence x10
  1142  L15:
  1143  	msr fpsr, xzr
  1144  	fcvtzs w2, d0
  1145  	mrs x9 fpsr
  1146  	mov x10, x0
  1147  	mov v8.16b, v0.16b
  1148  	subs xzr, x9, #0x1
  1149  	b.ne #0x70, (L13)
  1150  	fcmp d8, d8
  1151  	mov x9, x10
  1152  	b.vc #0x34, (L12)
  1153  	movz x11, #0xc, lsl 0
  1154  	str w11, [x9]
  1155  	mov x11, sp
  1156  	str x11, [x9, #0x38]
  1157  	adr x11, #0x0
  1158  	str x11, [x9, #0x30]
  1159  	exit_sequence x9
  1160  L12:
  1161  	movz x9, #0xb, lsl 0
  1162  	str w9, [x10]
  1163  	mov x9, sp
  1164  	str x9, [x10, #0x38]
  1165  	adr x9, #0x0
  1166  	str x9, [x10, #0x30]
  1167  	exit_sequence x10
  1168  L13:
  1169  	msr fpsr, xzr
  1170  	fcvtzs w3, s1
  1171  	mrs x9 fpsr
  1172  	mov x10, x0
  1173  	mov v8.16b, v1.16b
  1174  	subs xzr, x9, #0x1
  1175  	b.ne #0x70, (L11)
  1176  	fcmp s8, s8
  1177  	mov x9, x10
  1178  	b.vc #0x34, (L10)
  1179  	movz x11, #0xc, lsl 0
  1180  	str w11, [x9]
  1181  	mov x11, sp
  1182  	str x11, [x9, #0x38]
  1183  	adr x11, #0x0
  1184  	str x11, [x9, #0x30]
  1185  	exit_sequence x9
  1186  L10:
  1187  	movz x9, #0xb, lsl 0
  1188  	str w9, [x10]
  1189  	mov x9, sp
  1190  	str x9, [x10, #0x38]
  1191  	adr x9, #0x0
  1192  	str x9, [x10, #0x30]
  1193  	exit_sequence x10
  1194  L11:
  1195  	msr fpsr, xzr
  1196  	fcvtzu x4, d0
  1197  	mrs x9 fpsr
  1198  	mov x10, x0
  1199  	mov v8.16b, v0.16b
  1200  	subs xzr, x9, #0x1
  1201  	b.ne #0x70, (L9)
  1202  	fcmp d8, d8
  1203  	mov x9, x10
  1204  	b.vc #0x34, (L8)
  1205  	movz x11, #0xc, lsl 0
  1206  	str w11, [x9]
  1207  	mov x11, sp
  1208  	str x11, [x9, #0x38]
  1209  	adr x11, #0x0
  1210  	str x11, [x9, #0x30]
  1211  	exit_sequence x9
  1212  L8:
  1213  	movz x9, #0xb, lsl 0
  1214  	str w9, [x10]
  1215  	mov x9, sp
  1216  	str x9, [x10, #0x38]
  1217  	adr x9, #0x0
  1218  	str x9, [x10, #0x30]
  1219  	exit_sequence x10
  1220  L9:
  1221  	msr fpsr, xzr
  1222  	fcvtzu x5, s1
  1223  	mrs x9 fpsr
  1224  	mov x10, x0
  1225  	mov v8.16b, v1.16b
  1226  	subs xzr, x9, #0x1
  1227  	b.ne #0x70, (L7)
  1228  	fcmp s8, s8
  1229  	mov x9, x10
  1230  	b.vc #0x34, (L6)
  1231  	movz x11, #0xc, lsl 0
  1232  	str w11, [x9]
  1233  	mov x11, sp
  1234  	str x11, [x9, #0x38]
  1235  	adr x11, #0x0
  1236  	str x11, [x9, #0x30]
  1237  	exit_sequence x9
  1238  L6:
  1239  	movz x9, #0xb, lsl 0
  1240  	str w9, [x10]
  1241  	mov x9, sp
  1242  	str x9, [x10, #0x38]
  1243  	adr x9, #0x0
  1244  	str x9, [x10, #0x30]
  1245  	exit_sequence x10
  1246  L7:
  1247  	msr fpsr, xzr
  1248  	fcvtzu w6, d0
  1249  	mrs x9 fpsr
  1250  	mov x10, x0
  1251  	mov v8.16b, v0.16b
  1252  	subs xzr, x9, #0x1
  1253  	b.ne #0x70, (L5)
  1254  	fcmp d8, d8
  1255  	mov x9, x10
  1256  	b.vc #0x34, (L4)
  1257  	movz x11, #0xc, lsl 0
  1258  	str w11, [x9]
  1259  	mov x11, sp
  1260  	str x11, [x9, #0x38]
  1261  	adr x11, #0x0
  1262  	str x11, [x9, #0x30]
  1263  	exit_sequence x9
  1264  L4:
  1265  	movz x9, #0xb, lsl 0
  1266  	str w9, [x10]
  1267  	mov x9, sp
  1268  	str x9, [x10, #0x38]
  1269  	adr x9, #0x0
  1270  	str x9, [x10, #0x30]
  1271  	exit_sequence x10
  1272  L5:
  1273  	msr fpsr, xzr
  1274  	fcvtzu w7, s1
  1275  	mrs x9 fpsr
  1276  	mov v8.16b, v1.16b
  1277  	subs xzr, x9, #0x1
  1278  	b.ne #0x70, (L3)
  1279  	fcmp s8, s8
  1280  	mov x9, x0
  1281  	b.vc #0x34, (L2)
  1282  	movz x10, #0xc, lsl 0
  1283  	str w10, [x9]
  1284  	mov x10, sp
  1285  	str x10, [x9, #0x38]
  1286  	adr x10, #0x0
  1287  	str x10, [x9, #0x30]
  1288  	exit_sequence x9
  1289  L2:
  1290  	movz x9, #0xb, lsl 0
  1291  	str w9, [x0]
  1292  	mov x9, sp
  1293  	str x9, [x0, #0x38]
  1294  	adr x9, #0x0
  1295  	str x9, [x0, #0x30]
  1296  	exit_sequence x0
  1297  L3:
  1298  	fcvt s0, d0
  1299  	fcvt d1, s1
  1300  	mov x0, x8
  1301  	add sp, sp, #0x10
  1302  	ldr x30, [sp], #0x10
  1303  	ret
  1304  `,
  1305  		},
  1306  		{
  1307  			name: "nontrapping_float_conversions",
  1308  			m:    testcases.NonTrappingFloatConversions.Module,
  1309  			afterFinalizeARM64: `
  1310  L1 (SSA Block: blk0):
  1311  	stp x30, xzr, [sp, #-0x10]!
  1312  	str xzr, [sp, #-0x10]!
  1313  	fcvtzs x8, d0
  1314  	fcvtzs x1, s1
  1315  	fcvtzs w2, d0
  1316  	fcvtzs w3, s1
  1317  	fcvtzu x4, d0
  1318  	fcvtzu x5, s1
  1319  	fcvtzu w6, d0
  1320  	fcvtzu w7, s1
  1321  	mov x0, x8
  1322  	add sp, sp, #0x10
  1323  	ldr x30, [sp], #0x10
  1324  	ret
  1325  `,
  1326  		},
  1327  		{
  1328  			name: "many_middle_values",
  1329  			m:    testcases.ManyMiddleValues.Module,
  1330  			afterLoweringARM64: `
  1331  L1 (SSA Block: blk0):
  1332  	mov x130?, x2
  1333  	mov v131?.8b, v0.8b
  1334  	orr w289?, wzr, #0x1
  1335  	madd w133?, w130?, w289?, wzr
  1336  	orr w288?, wzr, #0x2
  1337  	madd w135?, w130?, w288?, wzr
  1338  	orr w287?, wzr, #0x3
  1339  	madd w137?, w130?, w287?, wzr
  1340  	orr w286?, wzr, #0x4
  1341  	madd w139?, w130?, w286?, wzr
  1342  	movz w285?, #0x5, lsl 0
  1343  	madd w141?, w130?, w285?, wzr
  1344  	orr w284?, wzr, #0x6
  1345  	madd w143?, w130?, w284?, wzr
  1346  	orr w283?, wzr, #0x7
  1347  	madd w145?, w130?, w283?, wzr
  1348  	orr w282?, wzr, #0x8
  1349  	madd w147?, w130?, w282?, wzr
  1350  	movz w281?, #0x9, lsl 0
  1351  	madd w149?, w130?, w281?, wzr
  1352  	movz w280?, #0xa, lsl 0
  1353  	madd w151?, w130?, w280?, wzr
  1354  	movz w279?, #0xb, lsl 0
  1355  	madd w153?, w130?, w279?, wzr
  1356  	orr w278?, wzr, #0xc
  1357  	madd w155?, w130?, w278?, wzr
  1358  	movz w277?, #0xd, lsl 0
  1359  	madd w157?, w130?, w277?, wzr
  1360  	orr w276?, wzr, #0xe
  1361  	madd w159?, w130?, w276?, wzr
  1362  	orr w275?, wzr, #0xf
  1363  	madd w161?, w130?, w275?, wzr
  1364  	orr w274?, wzr, #0x10
  1365  	madd w163?, w130?, w274?, wzr
  1366  	movz w273?, #0x11, lsl 0
  1367  	madd w165?, w130?, w273?, wzr
  1368  	movz w272?, #0x12, lsl 0
  1369  	madd w167?, w130?, w272?, wzr
  1370  	movz w271?, #0x13, lsl 0
  1371  	madd w169?, w130?, w271?, wzr
  1372  	movz w270?, #0x14, lsl 0
  1373  	madd w171?, w130?, w270?, wzr
  1374  	add w172?, w169?, w171?
  1375  	add w173?, w167?, w172?
  1376  	add w174?, w165?, w173?
  1377  	add w175?, w163?, w174?
  1378  	add w176?, w161?, w175?
  1379  	add w177?, w159?, w176?
  1380  	add w178?, w157?, w177?
  1381  	add w179?, w155?, w178?
  1382  	add w180?, w153?, w179?
  1383  	add w181?, w151?, w180?
  1384  	add w182?, w149?, w181?
  1385  	add w183?, w147?, w182?
  1386  	add w184?, w145?, w183?
  1387  	add w185?, w143?, w184?
  1388  	add w186?, w141?, w185?
  1389  	add w187?, w139?, w186?
  1390  	add w188?, w137?, w187?
  1391  	add w189?, w135?, w188?
  1392  	add w190?, w133?, w189?
  1393  	ldr s269?, #8; b 8; data.f32 1.000000
  1394  	fmul s192?, s131?, s269?
  1395  	ldr s268?, #8; b 8; data.f32 2.000000
  1396  	fmul s194?, s131?, s268?
  1397  	ldr s267?, #8; b 8; data.f32 3.000000
  1398  	fmul s196?, s131?, s267?
  1399  	ldr s266?, #8; b 8; data.f32 4.000000
  1400  	fmul s198?, s131?, s266?
  1401  	ldr s265?, #8; b 8; data.f32 5.000000
  1402  	fmul s200?, s131?, s265?
  1403  	ldr s264?, #8; b 8; data.f32 6.000000
  1404  	fmul s202?, s131?, s264?
  1405  	ldr s263?, #8; b 8; data.f32 7.000000
  1406  	fmul s204?, s131?, s263?
  1407  	ldr s262?, #8; b 8; data.f32 8.000000
  1408  	fmul s206?, s131?, s262?
  1409  	ldr s261?, #8; b 8; data.f32 9.000000
  1410  	fmul s208?, s131?, s261?
  1411  	ldr s260?, #8; b 8; data.f32 10.000000
  1412  	fmul s210?, s131?, s260?
  1413  	ldr s259?, #8; b 8; data.f32 11.000000
  1414  	fmul s212?, s131?, s259?
  1415  	ldr s258?, #8; b 8; data.f32 12.000000
  1416  	fmul s214?, s131?, s258?
  1417  	ldr s257?, #8; b 8; data.f32 13.000000
  1418  	fmul s216?, s131?, s257?
  1419  	ldr s256?, #8; b 8; data.f32 14.000000
  1420  	fmul s218?, s131?, s256?
  1421  	ldr s255?, #8; b 8; data.f32 15.000000
  1422  	fmul s220?, s131?, s255?
  1423  	ldr s254?, #8; b 8; data.f32 16.000000
  1424  	fmul s222?, s131?, s254?
  1425  	ldr s253?, #8; b 8; data.f32 17.000000
  1426  	fmul s224?, s131?, s253?
  1427  	ldr s252?, #8; b 8; data.f32 18.000000
  1428  	fmul s226?, s131?, s252?
  1429  	ldr s251?, #8; b 8; data.f32 19.000000
  1430  	fmul s228?, s131?, s251?
  1431  	ldr s250?, #8; b 8; data.f32 20.000000
  1432  	fmul s230?, s131?, s250?
  1433  	fadd s231?, s228?, s230?
  1434  	fadd s232?, s226?, s231?
  1435  	fadd s233?, s224?, s232?
  1436  	fadd s234?, s222?, s233?
  1437  	fadd s235?, s220?, s234?
  1438  	fadd s236?, s218?, s235?
  1439  	fadd s237?, s216?, s236?
  1440  	fadd s238?, s214?, s237?
  1441  	fadd s239?, s212?, s238?
  1442  	fadd s240?, s210?, s239?
  1443  	fadd s241?, s208?, s240?
  1444  	fadd s242?, s206?, s241?
  1445  	fadd s243?, s204?, s242?
  1446  	fadd s244?, s202?, s243?
  1447  	fadd s245?, s200?, s244?
  1448  	fadd s246?, s198?, s245?
  1449  	fadd s247?, s196?, s246?
  1450  	fadd s248?, s194?, s247?
  1451  	fadd s249?, s192?, s248?
  1452  	mov v0.8b, v249?.8b
  1453  	mov x0, x190?
  1454  	ret
  1455  `,
  1456  			afterFinalizeARM64: `
  1457  L1 (SSA Block: blk0):
  1458  	stp x30, xzr, [sp, #-0x10]!
  1459  	str x19, [sp, #-0x10]!
  1460  	str x20, [sp, #-0x10]!
  1461  	str x21, [sp, #-0x10]!
  1462  	str x22, [sp, #-0x10]!
  1463  	str x23, [sp, #-0x10]!
  1464  	str x24, [sp, #-0x10]!
  1465  	str x25, [sp, #-0x10]!
  1466  	str x26, [sp, #-0x10]!
  1467  	str q18, [sp, #-0x10]!
  1468  	str q19, [sp, #-0x10]!
  1469  	str q20, [sp, #-0x10]!
  1470  	str q21, [sp, #-0x10]!
  1471  	str q22, [sp, #-0x10]!
  1472  	str q23, [sp, #-0x10]!
  1473  	str q24, [sp, #-0x10]!
  1474  	str q25, [sp, #-0x10]!
  1475  	str q26, [sp, #-0x10]!
  1476  	str q27, [sp, #-0x10]!
  1477  	movz x27, #0x120, lsl 0
  1478  	str x27, [sp, #-0x10]!
  1479  	orr w8, wzr, #0x1
  1480  	madd w8, w2, w8, wzr
  1481  	orr w9, wzr, #0x2
  1482  	madd w9, w2, w9, wzr
  1483  	orr w10, wzr, #0x3
  1484  	madd w10, w2, w10, wzr
  1485  	orr w11, wzr, #0x4
  1486  	madd w11, w2, w11, wzr
  1487  	movz w12, #0x5, lsl 0
  1488  	madd w12, w2, w12, wzr
  1489  	orr w13, wzr, #0x6
  1490  	madd w13, w2, w13, wzr
  1491  	orr w14, wzr, #0x7
  1492  	madd w14, w2, w14, wzr
  1493  	orr w15, wzr, #0x8
  1494  	madd w15, w2, w15, wzr
  1495  	movz w16, #0x9, lsl 0
  1496  	madd w16, w2, w16, wzr
  1497  	movz w17, #0xa, lsl 0
  1498  	madd w17, w2, w17, wzr
  1499  	movz w19, #0xb, lsl 0
  1500  	madd w19, w2, w19, wzr
  1501  	orr w20, wzr, #0xc
  1502  	madd w20, w2, w20, wzr
  1503  	movz w21, #0xd, lsl 0
  1504  	madd w21, w2, w21, wzr
  1505  	orr w22, wzr, #0xe
  1506  	madd w22, w2, w22, wzr
  1507  	orr w23, wzr, #0xf
  1508  	madd w23, w2, w23, wzr
  1509  	orr w24, wzr, #0x10
  1510  	madd w24, w2, w24, wzr
  1511  	movz w25, #0x11, lsl 0
  1512  	madd w25, w2, w25, wzr
  1513  	movz w26, #0x12, lsl 0
  1514  	madd w26, w2, w26, wzr
  1515  	movz w29, #0x13, lsl 0
  1516  	madd w29, w2, w29, wzr
  1517  	movz w30, #0x14, lsl 0
  1518  	madd w30, w2, w30, wzr
  1519  	add w29, w29, w30
  1520  	add w26, w26, w29
  1521  	add w25, w25, w26
  1522  	add w24, w24, w25
  1523  	add w23, w23, w24
  1524  	add w22, w22, w23
  1525  	add w21, w21, w22
  1526  	add w20, w20, w21
  1527  	add w19, w19, w20
  1528  	add w17, w17, w19
  1529  	add w16, w16, w17
  1530  	add w15, w15, w16
  1531  	add w14, w14, w15
  1532  	add w13, w13, w14
  1533  	add w12, w12, w13
  1534  	add w11, w11, w12
  1535  	add w10, w10, w11
  1536  	add w9, w9, w10
  1537  	add w0, w8, w9
  1538  	ldr s8, #8; b 8; data.f32 1.000000
  1539  	fmul s8, s0, s8
  1540  	ldr s9, #8; b 8; data.f32 2.000000
  1541  	fmul s9, s0, s9
  1542  	ldr s10, #8; b 8; data.f32 3.000000
  1543  	fmul s10, s0, s10
  1544  	ldr s11, #8; b 8; data.f32 4.000000
  1545  	fmul s11, s0, s11
  1546  	ldr s12, #8; b 8; data.f32 5.000000
  1547  	fmul s12, s0, s12
  1548  	ldr s13, #8; b 8; data.f32 6.000000
  1549  	fmul s13, s0, s13
  1550  	ldr s14, #8; b 8; data.f32 7.000000
  1551  	fmul s14, s0, s14
  1552  	ldr s15, #8; b 8; data.f32 8.000000
  1553  	fmul s15, s0, s15
  1554  	ldr s16, #8; b 8; data.f32 9.000000
  1555  	fmul s16, s0, s16
  1556  	ldr s17, #8; b 8; data.f32 10.000000
  1557  	fmul s17, s0, s17
  1558  	ldr s18, #8; b 8; data.f32 11.000000
  1559  	fmul s18, s0, s18
  1560  	ldr s19, #8; b 8; data.f32 12.000000
  1561  	fmul s19, s0, s19
  1562  	ldr s20, #8; b 8; data.f32 13.000000
  1563  	fmul s20, s0, s20
  1564  	ldr s21, #8; b 8; data.f32 14.000000
  1565  	fmul s21, s0, s21
  1566  	ldr s22, #8; b 8; data.f32 15.000000
  1567  	fmul s22, s0, s22
  1568  	ldr s23, #8; b 8; data.f32 16.000000
  1569  	fmul s23, s0, s23
  1570  	ldr s24, #8; b 8; data.f32 17.000000
  1571  	fmul s24, s0, s24
  1572  	ldr s25, #8; b 8; data.f32 18.000000
  1573  	fmul s25, s0, s25
  1574  	ldr s26, #8; b 8; data.f32 19.000000
  1575  	fmul s26, s0, s26
  1576  	ldr s27, #8; b 8; data.f32 20.000000
  1577  	fmul s27, s0, s27
  1578  	fadd s26, s26, s27
  1579  	fadd s25, s25, s26
  1580  	fadd s24, s24, s25
  1581  	fadd s23, s23, s24
  1582  	fadd s22, s22, s23
  1583  	fadd s21, s21, s22
  1584  	fadd s20, s20, s21
  1585  	fadd s19, s19, s20
  1586  	fadd s18, s18, s19
  1587  	fadd s17, s17, s18
  1588  	fadd s16, s16, s17
  1589  	fadd s15, s15, s16
  1590  	fadd s14, s14, s15
  1591  	fadd s13, s13, s14
  1592  	fadd s12, s12, s13
  1593  	fadd s11, s11, s12
  1594  	fadd s10, s10, s11
  1595  	fadd s9, s9, s10
  1596  	fadd s0, s8, s9
  1597  	add sp, sp, #0x10
  1598  	ldr q27, [sp], #0x10
  1599  	ldr q26, [sp], #0x10
  1600  	ldr q25, [sp], #0x10
  1601  	ldr q24, [sp], #0x10
  1602  	ldr q23, [sp], #0x10
  1603  	ldr q22, [sp], #0x10
  1604  	ldr q21, [sp], #0x10
  1605  	ldr q20, [sp], #0x10
  1606  	ldr q19, [sp], #0x10
  1607  	ldr q18, [sp], #0x10
  1608  	ldr x26, [sp], #0x10
  1609  	ldr x25, [sp], #0x10
  1610  	ldr x24, [sp], #0x10
  1611  	ldr x23, [sp], #0x10
  1612  	ldr x22, [sp], #0x10
  1613  	ldr x21, [sp], #0x10
  1614  	ldr x20, [sp], #0x10
  1615  	ldr x19, [sp], #0x10
  1616  	ldr x30, [sp], #0x10
  1617  	ret
  1618  `,
  1619  		},
  1620  		{
  1621  			name: "imported_function_call", m: testcases.ImportedFunctionCall.Module,
  1622  			afterLoweringARM64: `
  1623  L1 (SSA Block: blk0):
  1624  	mov x128?, x0
  1625  	mov x129?, x1
  1626  	mov x130?, x2
  1627  	str x129?, [x128?, #0x8]
  1628  	ldr x131?, [x129?, #0x8]
  1629  	ldr x132?, [x129?, #0x10]
  1630  	mov x0, x128?
  1631  	mov x1, x132?
  1632  	mov x2, x130?
  1633  	mov x3, x130?
  1634  	bl x131?
  1635  	mov x133?, x0
  1636  	mov x0, x133?
  1637  	ret
  1638  `,
  1639  			afterFinalizeARM64: `
  1640  L1 (SSA Block: blk0):
  1641  	stp x30, xzr, [sp, #-0x10]!
  1642  	sub sp, sp, #0x10
  1643  	orr x27, xzr, #0x10
  1644  	str x27, [sp, #-0x10]!
  1645  	str w2, [sp, #0x10]
  1646  	str x1, [x0, #0x8]
  1647  	ldr x8, [x1, #0x8]
  1648  	ldr x1, [x1, #0x10]
  1649  	ldr w9, [sp, #0x10]
  1650  	mov x3, x9
  1651  	bl x8
  1652  	add sp, sp, #0x10
  1653  	add sp, sp, #0x10
  1654  	ldr x30, [sp], #0x10
  1655  	ret
  1656  `,
  1657  		},
  1658  		{
  1659  			name: "memory_load_basic", m: testcases.MemoryLoadBasic.Module,
  1660  			afterLoweringARM64: `
  1661  L1 (SSA Block: blk0):
  1662  	mov x128?, x0
  1663  	mov x129?, x1
  1664  	mov x130?, x2
  1665  	uxtw x132?, w130?
  1666  	ldr w133?, [x129?, #0x10]
  1667  	add x134?, x132?, #0x4
  1668  	subs xzr, x133?, x134?
  1669  	mov x140?, x128?
  1670  	b.hs L2
  1671  	movz x141?, #0x4, lsl 0
  1672  	str w141?, [x140?]
  1673  	mov x142?, sp
  1674  	str x142?, [x140?, #0x38]
  1675  	adr x143?, #0x0
  1676  	str x143?, [x140?, #0x30]
  1677  	exit_sequence x140?
  1678  L2:
  1679  	ldr x136?, [x129?, #0x8]
  1680  	add x139?, x136?, x132?
  1681  	ldr w138?, [x139?]
  1682  	mov x0, x138?
  1683  	ret
  1684  `,
  1685  			afterFinalizeARM64: `
  1686  L1 (SSA Block: blk0):
  1687  	stp x30, xzr, [sp, #-0x10]!
  1688  	str xzr, [sp, #-0x10]!
  1689  	uxtw x8, w2
  1690  	ldr w9, [x1, #0x10]
  1691  	add x10, x8, #0x4
  1692  	subs xzr, x9, x10
  1693  	b.hs #0x34, (L2)
  1694  	movz x9, #0x4, lsl 0
  1695  	str w9, [x0]
  1696  	mov x9, sp
  1697  	str x9, [x0, #0x38]
  1698  	adr x9, #0x0
  1699  	str x9, [x0, #0x30]
  1700  	exit_sequence x0
  1701  L2:
  1702  	ldr x9, [x1, #0x8]
  1703  	add x8, x9, x8
  1704  	ldr w0, [x8]
  1705  	add sp, sp, #0x10
  1706  	ldr x30, [sp], #0x10
  1707  	ret
  1708  `,
  1709  		},
  1710  		{
  1711  			name: "memory_stores", m: testcases.MemoryStores.Module,
  1712  			afterFinalizeARM64: `
  1713  L1 (SSA Block: blk0):
  1714  	stp x30, xzr, [sp, #-0x10]!
  1715  	str xzr, [sp, #-0x10]!
  1716  	mov x8, xzr
  1717  	uxtw x8, w8
  1718  	ldr w9, [x1, #0x10]
  1719  	add x10, x8, #0x4
  1720  	subs xzr, x9, x10
  1721  	mov x10, x0
  1722  	b.hs #0x34, (L10)
  1723  	movz x11, #0x4, lsl 0
  1724  	str w11, [x10]
  1725  	mov x11, sp
  1726  	str x11, [x10, #0x38]
  1727  	adr x11, #0x0
  1728  	str x11, [x10, #0x30]
  1729  	exit_sequence x10
  1730  L10:
  1731  	ldr x10, [x1, #0x8]
  1732  	add x8, x10, x8
  1733  	str w2, [x8]
  1734  	orr w8, wzr, #0x8
  1735  	uxtw x8, w8
  1736  	add x11, x8, #0x8
  1737  	subs xzr, x9, x11
  1738  	mov x11, x0
  1739  	b.hs #0x34, (L9)
  1740  	movz x12, #0x4, lsl 0
  1741  	str w12, [x11]
  1742  	mov x12, sp
  1743  	str x12, [x11, #0x38]
  1744  	adr x12, #0x0
  1745  	str x12, [x11, #0x30]
  1746  	exit_sequence x11
  1747  L9:
  1748  	add x8, x10, x8
  1749  	str x3, [x8]
  1750  	orr w8, wzr, #0x10
  1751  	uxtw x8, w8
  1752  	add x11, x8, #0x4
  1753  	subs xzr, x9, x11
  1754  	mov x11, x0
  1755  	b.hs #0x34, (L8)
  1756  	movz x12, #0x4, lsl 0
  1757  	str w12, [x11]
  1758  	mov x12, sp
  1759  	str x12, [x11, #0x38]
  1760  	adr x12, #0x0
  1761  	str x12, [x11, #0x30]
  1762  	exit_sequence x11
  1763  L8:
  1764  	add x8, x10, x8
  1765  	str s0, [x8]
  1766  	orr w8, wzr, #0x18
  1767  	uxtw x8, w8
  1768  	add x11, x8, #0x8
  1769  	subs xzr, x9, x11
  1770  	mov x11, x0
  1771  	b.hs #0x34, (L7)
  1772  	movz x12, #0x4, lsl 0
  1773  	str w12, [x11]
  1774  	mov x12, sp
  1775  	str x12, [x11, #0x38]
  1776  	adr x12, #0x0
  1777  	str x12, [x11, #0x30]
  1778  	exit_sequence x11
  1779  L7:
  1780  	add x8, x10, x8
  1781  	str d1, [x8]
  1782  	orr w8, wzr, #0x20
  1783  	uxtw x8, w8
  1784  	add x11, x8, #0x1
  1785  	subs xzr, x9, x11
  1786  	mov x11, x0
  1787  	b.hs #0x34, (L6)
  1788  	movz x12, #0x4, lsl 0
  1789  	str w12, [x11]
  1790  	mov x12, sp
  1791  	str x12, [x11, #0x38]
  1792  	adr x12, #0x0
  1793  	str x12, [x11, #0x30]
  1794  	exit_sequence x11
  1795  L6:
  1796  	add x8, x10, x8
  1797  	strb w2, [x8]
  1798  	movz w8, #0x28, lsl 0
  1799  	uxtw x8, w8
  1800  	add x11, x8, #0x2
  1801  	subs xzr, x9, x11
  1802  	mov x11, x0
  1803  	b.hs #0x34, (L5)
  1804  	movz x12, #0x4, lsl 0
  1805  	str w12, [x11]
  1806  	mov x12, sp
  1807  	str x12, [x11, #0x38]
  1808  	adr x12, #0x0
  1809  	str x12, [x11, #0x30]
  1810  	exit_sequence x11
  1811  L5:
  1812  	add x8, x10, x8
  1813  	strh w2, [x8]
  1814  	orr w8, wzr, #0x30
  1815  	uxtw x8, w8
  1816  	add x11, x8, #0x1
  1817  	subs xzr, x9, x11
  1818  	mov x11, x0
  1819  	b.hs #0x34, (L4)
  1820  	movz x12, #0x4, lsl 0
  1821  	str w12, [x11]
  1822  	mov x12, sp
  1823  	str x12, [x11, #0x38]
  1824  	adr x12, #0x0
  1825  	str x12, [x11, #0x30]
  1826  	exit_sequence x11
  1827  L4:
  1828  	add x8, x10, x8
  1829  	strb w3, [x8]
  1830  	orr w8, wzr, #0x38
  1831  	uxtw x8, w8
  1832  	add x11, x8, #0x2
  1833  	subs xzr, x9, x11
  1834  	mov x11, x0
  1835  	b.hs #0x34, (L3)
  1836  	movz x12, #0x4, lsl 0
  1837  	str w12, [x11]
  1838  	mov x12, sp
  1839  	str x12, [x11, #0x38]
  1840  	adr x12, #0x0
  1841  	str x12, [x11, #0x30]
  1842  	exit_sequence x11
  1843  L3:
  1844  	add x8, x10, x8
  1845  	strh w3, [x8]
  1846  	orr w8, wzr, #0x40
  1847  	uxtw x8, w8
  1848  	add x11, x8, #0x4
  1849  	subs xzr, x9, x11
  1850  	b.hs #0x34, (L2)
  1851  	movz x9, #0x4, lsl 0
  1852  	str w9, [x0]
  1853  	mov x9, sp
  1854  	str x9, [x0, #0x38]
  1855  	adr x9, #0x0
  1856  	str x9, [x0, #0x30]
  1857  	exit_sequence x0
  1858  L2:
  1859  	add x8, x10, x8
  1860  	str w3, [x8]
  1861  	add sp, sp, #0x10
  1862  	ldr x30, [sp], #0x10
  1863  	ret
  1864  `,
  1865  		},
  1866  		{
  1867  			name: "globals_mutable[0]",
  1868  			m:    testcases.GlobalsMutable.Module,
  1869  			afterLoweringARM64: `
  1870  L1 (SSA Block: blk0):
  1871  	mov x128?, x0
  1872  	mov x129?, x1
  1873  	ldr w130?, [x129?, #0x10]
  1874  	ldr x131?, [x129?, #0x20]
  1875  	ldr s132?, [x129?, #0x30]
  1876  	ldr d133?, [x129?, #0x40]
  1877  	mov x0, x128?
  1878  	mov x1, x129?
  1879  	bl f1
  1880  	ldr w134?, [x129?, #0x10]
  1881  	ldr x135?, [x129?, #0x20]
  1882  	ldr s136?, [x129?, #0x30]
  1883  	ldr d137?, [x129?, #0x40]
  1884  	mov v3.8b, v137?.8b
  1885  	mov v2.8b, v136?.8b
  1886  	mov x3, x135?
  1887  	mov x2, x134?
  1888  	mov v1.8b, v133?.8b
  1889  	mov v0.8b, v132?.8b
  1890  	mov x1, x131?
  1891  	mov x0, x130?
  1892  	ret
  1893  `,
  1894  			afterFinalizeARM64: `
  1895  L1 (SSA Block: blk0):
  1896  	stp x30, xzr, [sp, #-0x10]!
  1897  	sub sp, sp, #0x20
  1898  	orr x27, xzr, #0x20
  1899  	str x27, [sp, #-0x10]!
  1900  	str x1, [sp, #0x10]
  1901  	ldr w8, [x1, #0x10]
  1902  	str w8, [sp, #0x2c]
  1903  	ldr x9, [x1, #0x20]
  1904  	str x9, [sp, #0x24]
  1905  	ldr s0, [x1, #0x30]
  1906  	str s0, [sp, #0x20]
  1907  	ldr d1, [x1, #0x40]
  1908  	str d1, [sp, #0x18]
  1909  	bl f1
  1910  	ldr x8, [sp, #0x10]
  1911  	ldr w2, [x8, #0x10]
  1912  	ldr x3, [x8, #0x20]
  1913  	ldr s2, [x8, #0x30]
  1914  	ldr d3, [x8, #0x40]
  1915  	ldr d1, [sp, #0x18]
  1916  	ldr s0, [sp, #0x20]
  1917  	ldr x1, [sp, #0x24]
  1918  	ldr w0, [sp, #0x2c]
  1919  	add sp, sp, #0x10
  1920  	add sp, sp, #0x20
  1921  	ldr x30, [sp], #0x10
  1922  	ret
  1923  `,
  1924  		},
  1925  		{
  1926  			name:        "globals_mutable[1]",
  1927  			m:           testcases.GlobalsMutable.Module,
  1928  			targetIndex: 1,
  1929  			afterLoweringARM64: `
  1930  L1 (SSA Block: blk0):
  1931  	mov x129?, x1
  1932  	orr w137?, wzr, #0x1
  1933  	str w137?, [x129?, #0x10]
  1934  	orr x136?, xzr, #0x2
  1935  	str x136?, [x129?, #0x20]
  1936  	ldr s135?, #8; b 8; data.f32 3.000000
  1937  	str s135?, [x129?, #0x30]
  1938  	ldr d134?, #8; b 16; data.f64 4.000000
  1939  	str d134?, [x129?, #0x40]
  1940  	ret
  1941  `,
  1942  			afterFinalizeARM64: `
  1943  L1 (SSA Block: blk0):
  1944  	stp x30, xzr, [sp, #-0x10]!
  1945  	str xzr, [sp, #-0x10]!
  1946  	orr w8, wzr, #0x1
  1947  	str w8, [x1, #0x10]
  1948  	orr x8, xzr, #0x2
  1949  	str x8, [x1, #0x20]
  1950  	ldr s8, #8; b 8; data.f32 3.000000
  1951  	str s8, [x1, #0x30]
  1952  	ldr d8, #8; b 16; data.f64 4.000000
  1953  	str d8, [x1, #0x40]
  1954  	add sp, sp, #0x10
  1955  	ldr x30, [sp], #0x10
  1956  	ret
  1957  `,
  1958  		},
  1959  		{
  1960  			name:        "br_table",
  1961  			m:           testcases.BrTable.Module,
  1962  			targetIndex: 0,
  1963  			afterLoweringARM64: `
  1964  L1 (SSA Block: blk0):
  1965  	mov x130?, x2
  1966  	orr w137?, wzr, #0x6
  1967  	subs wzr, w130?, w137?
  1968  	csel w138?, w137?, w130?, hs
  1969  	br_table_sequence x138?, table_index=0
  1970  L2 (SSA Block: blk7):
  1971  	b L9
  1972  L3 (SSA Block: blk8):
  1973  L10 (SSA Block: blk5):
  1974  	orr w131?, wzr, #0xc
  1975  	mov x0, x131?
  1976  	ret
  1977  L4 (SSA Block: blk9):
  1978  L11 (SSA Block: blk4):
  1979  	movz w132?, #0xd, lsl 0
  1980  	mov x0, x132?
  1981  	ret
  1982  L5 (SSA Block: blk10):
  1983  L12 (SSA Block: blk3):
  1984  	orr w133?, wzr, #0xe
  1985  	mov x0, x133?
  1986  	ret
  1987  L6 (SSA Block: blk11):
  1988  L13 (SSA Block: blk2):
  1989  	orr w134?, wzr, #0xf
  1990  	mov x0, x134?
  1991  	ret
  1992  L7 (SSA Block: blk12):
  1993  L14 (SSA Block: blk1):
  1994  	orr w135?, wzr, #0x10
  1995  	mov x0, x135?
  1996  	ret
  1997  L8 (SSA Block: blk13):
  1998  L9 (SSA Block: blk6):
  1999  	movz w136?, #0xb, lsl 0
  2000  	mov x0, x136?
  2001  	ret
  2002  `,
  2003  			afterFinalizeARM64: `
  2004  L1 (SSA Block: blk0):
  2005  	stp x30, xzr, [sp, #-0x10]!
  2006  	str xzr, [sp, #-0x10]!
  2007  	orr w8, wzr, #0x6
  2008  	subs wzr, w2, w8
  2009  	csel w8, w8, w2, hs
  2010  	br_table_sequence x8, table_index=0
  2011  L2 (SSA Block: blk7):
  2012  	b #0x54 (L9)
  2013  L3 (SSA Block: blk8):
  2014  L10 (SSA Block: blk5):
  2015  	orr w0, wzr, #0xc
  2016  	add sp, sp, #0x10
  2017  	ldr x30, [sp], #0x10
  2018  	ret
  2019  L4 (SSA Block: blk9):
  2020  L11 (SSA Block: blk4):
  2021  	movz w0, #0xd, lsl 0
  2022  	add sp, sp, #0x10
  2023  	ldr x30, [sp], #0x10
  2024  	ret
  2025  L5 (SSA Block: blk10):
  2026  L12 (SSA Block: blk3):
  2027  	orr w0, wzr, #0xe
  2028  	add sp, sp, #0x10
  2029  	ldr x30, [sp], #0x10
  2030  	ret
  2031  L6 (SSA Block: blk11):
  2032  L13 (SSA Block: blk2):
  2033  	orr w0, wzr, #0xf
  2034  	add sp, sp, #0x10
  2035  	ldr x30, [sp], #0x10
  2036  	ret
  2037  L7 (SSA Block: blk12):
  2038  L14 (SSA Block: blk1):
  2039  	orr w0, wzr, #0x10
  2040  	add sp, sp, #0x10
  2041  	ldr x30, [sp], #0x10
  2042  	ret
  2043  L8 (SSA Block: blk13):
  2044  L9 (SSA Block: blk6):
  2045  	movz w0, #0xb, lsl 0
  2046  	add sp, sp, #0x10
  2047  	ldr x30, [sp], #0x10
  2048  	ret
  2049  `,
  2050  		},
  2051  		{
  2052  			name: "VecShuffle",
  2053  			m:    testcases.VecShuffle.Module,
  2054  			afterFinalizeARM64: `
  2055  L1 (SSA Block: blk0):
  2056  	stp x30, xzr, [sp, #-0x10]!
  2057  	str q29, [sp, #-0x10]!
  2058  	str q30, [sp, #-0x10]!
  2059  	orr x27, xzr, #0x20
  2060  	str x27, [sp, #-0x10]!
  2061  	mov v29.16b, v0.16b
  2062  	mov v30.16b, v1.16b
  2063  	ldr q8, #8; b 32; data.v128  0706050403020100 1f1e1d1c1b1a1918
  2064  	tbl v0.16b, { v29.16b, v30.16b }, v8.16b
  2065  	add sp, sp, #0x10
  2066  	ldr q30, [sp], #0x10
  2067  	ldr q29, [sp], #0x10
  2068  	ldr x30, [sp], #0x10
  2069  	ret
  2070  `,
  2071  		},
  2072  		{
  2073  			name: "AtomicRmwAdd",
  2074  			m:    testcases.AtomicRmwAdd.Module,
  2075  			afterFinalizeARM64: `
  2076  L1 (SSA Block: blk0):
  2077  	orr x27, xzr, #0x10
  2078  	sub sp, sp, x27
  2079  	stp x30, x27, [sp, #-0x10]!
  2080  	str xzr, [sp, #-0x10]!
  2081  	ldr x8, [sp, #0x20]
  2082  	mov x9, xzr
  2083  	uxtw x9, w9
  2084  	add x10, x1, #0x10
  2085  	ldar x10, x10
  2086  	add x11, x9, #0x1
  2087  	subs xzr, x10, x11
  2088  	mov x10, x0
  2089  	b.hs #0x34, (L13)
  2090  	movz x11, #0x4, lsl 0
  2091  	str w11, [x10]
  2092  	mov x11, sp
  2093  	str x11, [x10, #0x38]
  2094  	adr x11, #0x0
  2095  	str x11, [x10, #0x30]
  2096  	exit_sequence x10
  2097  L13:
  2098  	ldr x10, [x1, #0x8]
  2099  	add x9, x10, x9
  2100  	ldaddalb w2, w9, x9
  2101  	orr w11, wzr, #0x8
  2102  	uxtw x11, w11
  2103  	add x12, x1, #0x10
  2104  	ldar x12, x12
  2105  	add x13, x11, #0x2
  2106  	subs xzr, x12, x13
  2107  	mov x12, x0
  2108  	b.hs #0x34, (L12)
  2109  	movz x13, #0x4, lsl 0
  2110  	str w13, [x12]
  2111  	mov x13, sp
  2112  	str x13, [x12, #0x38]
  2113  	adr x13, #0x0
  2114  	str x13, [x12, #0x30]
  2115  	exit_sequence x12
  2116  L12:
  2117  	add x11, x10, x11
  2118  	ands xzr, x11, #0x1
  2119  	mov x12, x0
  2120  	b.eq #0x34, (L11)
  2121  	movz x13, #0x17, lsl 0
  2122  	str w13, [x12]
  2123  	mov x13, sp
  2124  	str x13, [x12, #0x38]
  2125  	adr x13, #0x0
  2126  	str x13, [x12, #0x30]
  2127  	exit_sequence x12
  2128  L11:
  2129  	ldaddalh w3, w11, x11
  2130  	orr w12, wzr, #0x10
  2131  	uxtw x12, w12
  2132  	add x13, x1, #0x10
  2133  	ldar x13, x13
  2134  	add x14, x12, #0x4
  2135  	subs xzr, x13, x14
  2136  	mov x13, x0
  2137  	b.hs #0x34, (L10)
  2138  	movz x14, #0x4, lsl 0
  2139  	str w14, [x13]
  2140  	mov x14, sp
  2141  	str x14, [x13, #0x38]
  2142  	adr x14, #0x0
  2143  	str x14, [x13, #0x30]
  2144  	exit_sequence x13
  2145  L10:
  2146  	add x12, x10, x12
  2147  	ands xzr, x12, #0x3
  2148  	mov x13, x0
  2149  	b.eq #0x34, (L9)
  2150  	movz x14, #0x17, lsl 0
  2151  	str w14, [x13]
  2152  	mov x14, sp
  2153  	str x14, [x13, #0x38]
  2154  	adr x14, #0x0
  2155  	str x14, [x13, #0x30]
  2156  	exit_sequence x13
  2157  L9:
  2158  	ldaddal w4, w2, x12
  2159  	orr w12, wzr, #0x18
  2160  	uxtw x12, w12
  2161  	add x13, x1, #0x10
  2162  	ldar x13, x13
  2163  	add x14, x12, #0x1
  2164  	subs xzr, x13, x14
  2165  	mov x13, x0
  2166  	b.hs #0x34, (L8)
  2167  	movz x14, #0x4, lsl 0
  2168  	str w14, [x13]
  2169  	mov x14, sp
  2170  	str x14, [x13, #0x38]
  2171  	adr x14, #0x0
  2172  	str x14, [x13, #0x30]
  2173  	exit_sequence x13
  2174  L8:
  2175  	add x12, x10, x12
  2176  	ldaddalb w5, w3, x12
  2177  	orr w12, wzr, #0x20
  2178  	uxtw x12, w12
  2179  	add x13, x1, #0x10
  2180  	ldar x13, x13
  2181  	add x14, x12, #0x2
  2182  	subs xzr, x13, x14
  2183  	mov x13, x0
  2184  	b.hs #0x34, (L7)
  2185  	movz x14, #0x4, lsl 0
  2186  	str w14, [x13]
  2187  	mov x14, sp
  2188  	str x14, [x13, #0x38]
  2189  	adr x14, #0x0
  2190  	str x14, [x13, #0x30]
  2191  	exit_sequence x13
  2192  L7:
  2193  	add x12, x10, x12
  2194  	ands xzr, x12, #0x1
  2195  	mov x13, x0
  2196  	b.eq #0x34, (L6)
  2197  	movz x14, #0x17, lsl 0
  2198  	str w14, [x13]
  2199  	mov x14, sp
  2200  	str x14, [x13, #0x38]
  2201  	adr x14, #0x0
  2202  	str x14, [x13, #0x30]
  2203  	exit_sequence x13
  2204  L6:
  2205  	ldaddalh w6, w4, x12
  2206  	movz w12, #0x28, lsl 0
  2207  	uxtw x12, w12
  2208  	add x13, x1, #0x10
  2209  	ldar x13, x13
  2210  	add x14, x12, #0x4
  2211  	subs xzr, x13, x14
  2212  	mov x13, x0
  2213  	b.hs #0x34, (L5)
  2214  	movz x14, #0x4, lsl 0
  2215  	str w14, [x13]
  2216  	mov x14, sp
  2217  	str x14, [x13, #0x38]
  2218  	adr x14, #0x0
  2219  	str x14, [x13, #0x30]
  2220  	exit_sequence x13
  2221  L5:
  2222  	add x12, x10, x12
  2223  	ands xzr, x12, #0x3
  2224  	mov x13, x0
  2225  	b.eq #0x34, (L4)
  2226  	movz x14, #0x17, lsl 0
  2227  	str w14, [x13]
  2228  	mov x14, sp
  2229  	str x14, [x13, #0x38]
  2230  	adr x14, #0x0
  2231  	str x14, [x13, #0x30]
  2232  	exit_sequence x13
  2233  L4:
  2234  	ldaddal w7, w5, x12
  2235  	orr w12, wzr, #0x30
  2236  	uxtw x12, w12
  2237  	add x13, x1, #0x10
  2238  	ldar x13, x13
  2239  	add x14, x12, #0x8
  2240  	subs xzr, x13, x14
  2241  	mov x13, x0
  2242  	b.hs #0x34, (L3)
  2243  	movz x14, #0x4, lsl 0
  2244  	str w14, [x13]
  2245  	mov x14, sp
  2246  	str x14, [x13, #0x38]
  2247  	adr x14, #0x0
  2248  	str x14, [x13, #0x30]
  2249  	exit_sequence x13
  2250  L3:
  2251  	add x10, x10, x12
  2252  	ands xzr, x10, #0x7
  2253  	b.eq #0x34, (L2)
  2254  	movz x12, #0x17, lsl 0
  2255  	str w12, [x0]
  2256  	mov x12, sp
  2257  	str x12, [x0, #0x38]
  2258  	adr x12, #0x0
  2259  	str x12, [x0, #0x30]
  2260  	exit_sequence x0
  2261  L2:
  2262  	ldaddal x8, x6, x10
  2263  	mov x1, x11
  2264  	mov x0, x9
  2265  	add sp, sp, #0x10
  2266  	ldr x30, [sp], #0x10
  2267  	add sp, sp, #0x10
  2268  	ret
  2269  `,
  2270  		},
  2271  		{
  2272  			name: "icmp_and_zero",
  2273  			m:    testcases.IcmpAndZero.Module,
  2274  			afterFinalizeAMD64: `
  2275  L1 (SSA Block: blk0):
  2276  	pushq %rbp
  2277  	movq %rsp, %rbp
  2278  	testl %edi, %ecx
  2279  	jnz L2
  2280  L3 (SSA Block: blk1):
  2281  	movl $1, %eax
  2282  	movq %rbp, %rsp
  2283  	popq %rbp
  2284  	ret
  2285  L2 (SSA Block: blk2):
  2286  	xor %rax, %rax
  2287  	movq %rbp, %rsp
  2288  	popq %rbp
  2289  	ret
  2290  `,
  2291  			afterFinalizeARM64: `
  2292  L1 (SSA Block: blk0):
  2293  	stp x30, xzr, [sp, #-0x10]!
  2294  	str xzr, [sp, #-0x10]!
  2295  	ands wzr, w2, w3
  2296  	b.ne #0x14, (L2)
  2297  L3 (SSA Block: blk1):
  2298  	orr w0, wzr, #0x1
  2299  	add sp, sp, #0x10
  2300  	ldr x30, [sp], #0x10
  2301  	ret
  2302  L2 (SSA Block: blk2):
  2303  	mov x0, xzr
  2304  	add sp, sp, #0x10
  2305  	ldr x30, [sp], #0x10
  2306  	ret
  2307  `,
  2308  		},
  2309  	} {
  2310  		t.Run(tc.name, func(t *testing.T) {
  2311  			var exp string
  2312  			switch runtime.GOARCH {
  2313  			case "arm64":
  2314  				exp = tc.afterFinalizeARM64
  2315  			case "amd64":
  2316  				if tc.afterFinalizeAMD64 != "" {
  2317  					exp = tc.afterFinalizeAMD64
  2318  				} else {
  2319  					t.Skip()
  2320  				}
  2321  			default:
  2322  				t.Fail()
  2323  			}
  2324  
  2325  			err := tc.m.Validate(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads)
  2326  			require.NoError(t, err)
  2327  
  2328  			ssab := ssa.NewBuilder()
  2329  			offset := wazevoapi.NewModuleContextOffsetData(tc.m, false)
  2330  			fc := frontend.NewFrontendCompiler(tc.m, ssab, &offset, false, false, false)
  2331  			machine := newMachine()
  2332  			machine.DisableStackCheck()
  2333  			be := backend.NewCompiler(context.Background(), machine, ssab)
  2334  
  2335  			// Lowers the Wasm to SSA.
  2336  			typeIndex := tc.m.FunctionSection[tc.targetIndex]
  2337  			code := &tc.m.CodeSection[tc.targetIndex]
  2338  			fc.Init(tc.targetIndex, typeIndex, &tc.m.TypeSection[typeIndex], code.LocalTypes, code.Body, false, 0)
  2339  			fc.LowerToSSA()
  2340  			if verbose {
  2341  				fmt.Println("============ SSA before passes ============")
  2342  				fmt.Println(ssab.Format())
  2343  			}
  2344  
  2345  			// Need to run passes before lowering to machine code.
  2346  			ssab.RunPasses()
  2347  			if verbose {
  2348  				fmt.Println("============ SSA after passes ============")
  2349  				fmt.Println(ssab.Format())
  2350  			}
  2351  
  2352  			// Lowers the SSA to ISA specific code.
  2353  			be.Lower()
  2354  			if verbose {
  2355  				fmt.Println("============ lowering result ============")
  2356  				fmt.Println(be.Format())
  2357  			}
  2358  
  2359  			switch runtime.GOARCH {
  2360  			case "arm64":
  2361  				if tc.afterLoweringARM64 != "" {
  2362  					require.Equal(t, tc.afterLoweringARM64, be.Format())
  2363  				}
  2364  			case "amd64":
  2365  				if tc.afterLoweringAMD64 != "" {
  2366  					require.Equal(t, tc.afterLoweringAMD64, be.Format())
  2367  				}
  2368  			default:
  2369  				t.Fail()
  2370  			}
  2371  
  2372  			be.RegAlloc()
  2373  			if verbose {
  2374  				fmt.Println("============ regalloc result ============")
  2375  				fmt.Println(be.Format())
  2376  			}
  2377  
  2378  			err = be.Finalize(context.Background())
  2379  			require.NoError(t, err)
  2380  			if verbose {
  2381  				fmt.Println("============ finalization result ============")
  2382  				fmt.Println(be.Format())
  2383  			}
  2384  
  2385  			require.Equal(t, exp, be.Format())
  2386  		})
  2387  	}
  2388  }