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