133 lines · python
1# Test 64-bit COMPARE LOGICAL IMMEDIATE AND BRANCH in cases where the sheer2# number of instructions causes some branches to be out of range.3# RUN: %python %s | llc -mtriple=s390x-linux-gnu | FileCheck %s4 5# Construct:6#7# before0:8# conditional branch to after09# ...10# beforeN:11# conditional branch to after012# main:13# 0xffb4 bytes, from MVIY instructions14# conditional branch to main15# after0:16# ...17# conditional branch to main18# afterN:19#20# Each conditional branch sequence occupies 18 bytes if it uses a short21# branch and 24 if it uses a long one. The ones before "main:" have to22# take the branch length into account, which is 6 for short branches,23# so the final (0x4c - 6) / 18 == 3 blocks can use short branches.24# The ones after "main:" do not, so the first 0x4c / 18 == 4 blocks25# can use short branches. The conservative algorithm we use makes26# one of the forward branches unnecessarily long, as noted in the27# check output below.28#29# CHECK: lg [[REG:%r[0-5]]], 0(%r3)30# CHECK: sg [[REG]], 0(%r4)31# CHECK: clgfi [[REG]], 5032# CHECK: jgl [[LABEL:\.L[^ ]*]]33# CHECK: lg [[REG:%r[0-5]]], 0(%r3)34# CHECK: sg [[REG]], 0(%r4)35# CHECK: clgfi [[REG]], 5136# CHECK: jgl [[LABEL]]37# CHECK: lg [[REG:%r[0-5]]], 0(%r3)38# CHECK: sg [[REG]], 0(%r4)39# CHECK: clgfi [[REG]], 5240# CHECK: jgl [[LABEL]]41# CHECK: lg [[REG:%r[0-5]]], 0(%r3)42# CHECK: sg [[REG]], 0(%r4)43# CHECK: clgfi [[REG]], 5344# CHECK: jgl [[LABEL]]45# CHECK: lg [[REG:%r[0-5]]], 0(%r3)46# CHECK: sg [[REG]], 0(%r4)47# CHECK: clgfi [[REG]], 5448# CHECK: jgl [[LABEL]]49# ...as mentioned above, the next one could be a CLGIJL instead...50# CHECK: lg [[REG:%r[0-5]]], 0(%r3)51# CHECK: sg [[REG]], 0(%r4)52# CHECK: clgfi [[REG]], 5553# CHECK: jgl [[LABEL]]54# CHECK: lg [[REG:%r[0-5]]], 0(%r3)55# CHECK: sg [[REG]], 0(%r4)56# CHECK: clgijl [[REG]], 56, [[LABEL]]57# CHECK: lg [[REG:%r[0-5]]], 0(%r3)58# CHECK: sg [[REG]], 0(%r4)59# CHECK: clgijl [[REG]], 57, [[LABEL]]60# ...main goes here...61# CHECK: lg [[REG:%r[0-5]]], 0(%r3)62# CHECK: sg [[REG]], 0(%r4)63# CHECK: clgijl [[REG]], 100, [[LABEL:\.L[^ ]*]]64# CHECK: lg [[REG:%r[0-5]]], 0(%r3)65# CHECK: sg [[REG]], 0(%r4)66# CHECK: clgijl [[REG]], 101, [[LABEL]]67# CHECK: lg [[REG:%r[0-5]]], 0(%r3)68# CHECK: sg [[REG]], 0(%r4)69# CHECK: clgijl [[REG]], 102, [[LABEL]]70# CHECK: lg [[REG:%r[0-5]]], 0(%r3)71# CHECK: sg [[REG]], 0(%r4)72# CHECK: clgijl [[REG]], 103, [[LABEL]]73# CHECK: lg [[REG:%r[0-5]]], 0(%r3)74# CHECK: sg [[REG]], 0(%r4)75# CHECK: clgfi [[REG]], 10476# CHECK: jgl [[LABEL]]77# CHECK: lg [[REG:%r[0-5]]], 0(%r3)78# CHECK: sg [[REG]], 0(%r4)79# CHECK: clgfi [[REG]], 10580# CHECK: jgl [[LABEL]]81# CHECK: lg [[REG:%r[0-5]]], 0(%r3)82# CHECK: sg [[REG]], 0(%r4)83# CHECK: clgfi [[REG]], 10684# CHECK: jgl [[LABEL]]85# CHECK: lg [[REG:%r[0-5]]], 0(%r3)86# CHECK: sg [[REG]], 0(%r4)87# CHECK: clgfi [[REG]], 10788# CHECK: jgl [[LABEL]]89 90from __future__ import print_function91 92branch_blocks = 893main_size = 0xFFB494 95print("@global = global i32 0")96 97print("define void @f1(i8 *%base, i64 *%stopa, i64 *%stopb) {")98print("entry:")99print(" br label %before0")100print("")101 102for i in range(branch_blocks):103 next = "before%d" % (i + 1) if i + 1 < branch_blocks else "main"104 print("before%d:" % i)105 print(" %%bcur%da = load i64 , i64 *%%stopa" % i)106 print(" %%bcur%db = load i64 , i64 *%%stopb" % i)107 print(" %%bsub%d = sub i64 %%bcur%da, %%bcur%db" % (i, i, i))108 print(" %%btest%d = icmp ult i64 %%bsub%d, %d" % (i, i, i + 50))109 print(" br i1 %%btest%d, label %%after0, label %%%s" % (i, next))110 print("")111 112print("%s:" % next)113a, b = 1, 1114for i in range(0, main_size, 6):115 a, b = b, a + b116 offset = 4096 + b % 500000117 value = a % 256118 print(" %%ptr%d = getelementptr i8, i8 *%%base, i64 %d" % (i, offset))119 print(" store volatile i8 %d, i8 *%%ptr%d" % (value, i))120 121for i in range(branch_blocks):122 print(" %%acur%da = load i64 , i64 *%%stopa" % i)123 print(" %%acur%db = load i64 , i64 *%%stopb" % i)124 print(" %%asub%d = sub i64 %%acur%da, %%acur%db" % (i, i, i))125 print(" %%atest%d = icmp ult i64 %%asub%d, %d" % (i, i, i + 100))126 print(" br i1 %%atest%d, label %%main, label %%after%d" % (i, i))127 print("")128 print("after%d:" % i)129 130print(" %dummy = load volatile i32, i32 *@global")131print(" ret void")132print("}")133