xref: /aosp_15_r20/external/llvm/test/CodeGen/SystemZ/Large/branch-range-01.py (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker# Test normal conditional branches in cases where the sheer number of
2*9880d681SAndroid Build Coastguard Worker# instructions causes some branches to be out of range.
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# Construct:
6*9880d681SAndroid Build Coastguard Worker#
7*9880d681SAndroid Build Coastguard Worker# before0:
8*9880d681SAndroid Build Coastguard Worker#   conditional branch to after0
9*9880d681SAndroid Build Coastguard Worker#   ...
10*9880d681SAndroid Build Coastguard Worker# beforeN:
11*9880d681SAndroid Build Coastguard Worker#   conditional branch to after0
12*9880d681SAndroid Build Coastguard Worker# main:
13*9880d681SAndroid Build Coastguard Worker#   0xffd8 bytes, from MVIY instructions
14*9880d681SAndroid Build Coastguard Worker#   conditional branch to main
15*9880d681SAndroid Build Coastguard Worker# after0:
16*9880d681SAndroid Build Coastguard Worker#   ...
17*9880d681SAndroid Build Coastguard Worker#   conditional branch to main
18*9880d681SAndroid Build Coastguard Worker# afterN:
19*9880d681SAndroid Build Coastguard Worker#
20*9880d681SAndroid Build Coastguard Worker# Each conditional branch sequence occupies 8 bytes if it uses a short branch
21*9880d681SAndroid Build Coastguard Worker# and 10 if it uses a long one.  The ones before "main:" have to take the branch
22*9880d681SAndroid Build Coastguard Worker# length into account -- which is 4 bytes for short branches -- so the final
23*9880d681SAndroid Build Coastguard Worker# (0x28 - 4) / 8 == 4 blocks can use short branches.  The ones after "main:"
24*9880d681SAndroid Build Coastguard Worker# do not, so the first 0x28 / 8 == 5 can use short branches.  However,
25*9880d681SAndroid Build Coastguard Worker# the conservative algorithm we use makes one branch unnecessarily long
26*9880d681SAndroid Build Coastguard Worker# on each side.
27*9880d681SAndroid Build Coastguard Worker#
28*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 0(%r3)
29*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL:\.L[^ ]*]]
30*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 4(%r3)
31*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
32*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 8(%r3)
33*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
34*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 12(%r3)
35*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
36*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 16(%r3)
37*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
38*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 20(%r3)
39*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
40*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 24(%r3)
41*9880d681SAndroid Build Coastguard Worker# CHECK: j{{g?}}e [[LABEL]]
42*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 28(%r3)
43*9880d681SAndroid Build Coastguard Worker# CHECK: je [[LABEL]]
44*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 32(%r3)
45*9880d681SAndroid Build Coastguard Worker# CHECK: je [[LABEL]]
46*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 36(%r3)
47*9880d681SAndroid Build Coastguard Worker# CHECK: je [[LABEL]]
48*9880d681SAndroid Build Coastguard Worker# ...main goes here...
49*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 100(%r3)
50*9880d681SAndroid Build Coastguard Worker# CHECK: je [[LABEL:\.L[^ ]*]]
51*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 104(%r3)
52*9880d681SAndroid Build Coastguard Worker# CHECK: je [[LABEL]]
53*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 108(%r3)
54*9880d681SAndroid Build Coastguard Worker# CHECK: je [[LABEL]]
55*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 112(%r3)
56*9880d681SAndroid Build Coastguard Worker# CHECK: je [[LABEL]]
57*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 116(%r3)
58*9880d681SAndroid Build Coastguard Worker# CHECK: j{{g?}}e [[LABEL]]
59*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 120(%r3)
60*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
61*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 124(%r3)
62*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
63*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 128(%r3)
64*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
65*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 132(%r3)
66*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
67*9880d681SAndroid Build Coastguard Worker# CHECK: c %r4, 136(%r3)
68*9880d681SAndroid Build Coastguard Worker# CHECK: jge [[LABEL]]
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Workerbranch_blocks = 10
71*9880d681SAndroid Build Coastguard Workermain_size = 0xffd8
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Workerprint '@global = global i32 0'
74*9880d681SAndroid Build Coastguard Worker
75*9880d681SAndroid Build Coastguard Workerprint 'define void @f1(i8 *%base, i32 *%stop, i32 %limit) {'
76*9880d681SAndroid Build Coastguard Workerprint 'entry:'
77*9880d681SAndroid Build Coastguard Workerprint '  br label %before0'
78*9880d681SAndroid Build Coastguard Workerprint ''
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Workerfor i in xrange(branch_blocks):
81*9880d681SAndroid Build Coastguard Worker    next = 'before%d' % (i + 1) if i + 1 < branch_blocks else 'main'
82*9880d681SAndroid Build Coastguard Worker    print 'before%d:' % i
83*9880d681SAndroid Build Coastguard Worker    print '  %%bstop%d = getelementptr i32, i32 *%%stop, i64 %d' % (i, i)
84*9880d681SAndroid Build Coastguard Worker    print '  %%bcur%d = load i32 , i32 *%%bstop%d' % (i, i)
85*9880d681SAndroid Build Coastguard Worker    print '  %%btest%d = icmp eq i32 %%limit, %%bcur%d' % (i, i)
86*9880d681SAndroid Build Coastguard Worker    print '  br i1 %%btest%d, label %%after0, label %%%s' % (i, next)
87*9880d681SAndroid Build Coastguard Worker    print ''
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Workerprint '%s:' % next
90*9880d681SAndroid Build Coastguard Workera, b = 1, 1
91*9880d681SAndroid Build Coastguard Workerfor i in xrange(0, main_size, 6):
92*9880d681SAndroid Build Coastguard Worker    a, b = b, a + b
93*9880d681SAndroid Build Coastguard Worker    offset = 4096 + b % 500000
94*9880d681SAndroid Build Coastguard Worker    value = a % 256
95*9880d681SAndroid Build Coastguard Worker    print '  %%ptr%d = getelementptr i8, i8 *%%base, i64 %d' % (i, offset)
96*9880d681SAndroid Build Coastguard Worker    print '  store volatile i8 %d, i8 *%%ptr%d' % (value, i)
97*9880d681SAndroid Build Coastguard Worker
98*9880d681SAndroid Build Coastguard Workerfor i in xrange(branch_blocks):
99*9880d681SAndroid Build Coastguard Worker    print '  %%astop%d = getelementptr i32, i32 *%%stop, i64 %d' % (i, i + 25)
100*9880d681SAndroid Build Coastguard Worker    print '  %%acur%d = load i32 , i32 *%%astop%d' % (i, i)
101*9880d681SAndroid Build Coastguard Worker    print '  %%atest%d = icmp eq i32 %%limit, %%acur%d' % (i, i)
102*9880d681SAndroid Build Coastguard Worker    print '  br i1 %%atest%d, label %%main, label %%after%d' % (i, i)
103*9880d681SAndroid Build Coastguard Worker    print ''
104*9880d681SAndroid Build Coastguard Worker    print 'after%d:' % i
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Workerprint '  %dummy = load volatile i32, i32 *@global'
107*9880d681SAndroid Build Coastguard Workerprint '  ret void'
108*9880d681SAndroid Build Coastguard Workerprint '}'
109