1# Test cases where we spill from one frame index to another, both of which 2# are out of range of MVC, and both of which need emergency spill slots. 3# RUN: python %s | llc -mtriple=s390x-linux-gnu | FileCheck %s 4 5# CHECK: f1: 6# CHECK: %fallthru 7# CHECK-DAG: stg [[REG1:%r[0-9]+]], 8168(%r15) 8# CHECK-DAG: stg [[REG2:%r[0-9]+]], 8176(%r15) 9# CHECK-DAG: lay [[REG3:%r[0-9]+]], 8192(%r15) 10# CHECK-DAG: lay [[REG4:%r[0-9]+]], 4096(%r15) 11# CHECK: mvc 0(8,[[REG3]]), 4088([[REG4]]) 12# CHECK-DAG: lg [[REG1]], 8168(%r15) 13# CHECK-DAG: lg [[REG2]], 8176(%r15) 14# CHECK: %skip 15# CHECK: br %r14 16 17# Arrange for %foo's spill slot to be at 8184(%r15) and the alloca area to be at 18# 8192(%r15). The two emergency spill slots live below that, so this requires 19# the first 8168 bytes to be used for the call. 160 of these bytes are 20# allocated for the ABI frame. There are also 5 argument registers, one of 21# which is used as a base pointer. 22 23from __future__ import print_function 24 25args = int((8168 - 160) / 8 + (5 - 1)) 26 27print('declare i64 *@foo(i64 *%s)' % (', i64' * args)) 28print('declare void @bar(i64 *)') 29print('') 30print('define i64 @f1(i64 %foo) {') 31print('entry:') 32 33# Make the allocation big, so that it goes at the top of the frame. 34print(' %array = alloca [1000 x i64]') 35print(' %area = getelementptr [1000 x i64], [1000 x i64] *%array, i64 0, i64 0') 36print(' %%base = call i64 *@foo(i64 *%%area%s)' % (', i64 0' * args)) 37print('') 38 39# Make sure all GPRs are used. One is needed for the stack pointer and 40# another for %base, so we need 14 live values. 41count = 14 42for i in range(count): 43 print(' %%ptr%d = getelementptr i64, i64 *%%base, i64 %d' % (i, i / 2)) 44 print(' %%val%d = load volatile i64 , i64 *%%ptr%d' % (i, i)) 45 print('') 46 47# Encourage the register allocator to give preference to these %vals 48# by using them several times. 49for j in range(4): 50 for i in range(count): 51 print(' store volatile i64 %%val%d, i64 *%%ptr%d' % (i, i)) 52 print('') 53 54# Copy the incoming argument, which we expect to be spilled, to the frame 55# index for the alloca area. Also throw in a volatile store, so that this 56# block cannot be reordered with the surrounding code. 57print(' %cond = icmp eq i64 %val0, %val1') 58print(' br i1 %cond, label %skip, label %fallthru') 59print('') 60print('fallthru:') 61print(' store i64 %foo, i64 *%area') 62print(' store volatile i64 %val0, i64 *%ptr0') 63print(' br label %skip') 64print('') 65print('skip:') 66 67# Use each %val a few more times to emphasise the point, and to make sure 68# that they are live across the store of %foo. 69for j in range(4): 70 for i in range(count): 71 print(' store volatile i64 %%val%d, i64 *%%ptr%d' % (i, i)) 72 print('') 73 74print(' call void @bar(i64 *%area)') 75print(' ret i64 0') 76print('}') 77