[SystemZ] Add long branch pass
Before this change, the SystemZ backend would use BRCL for all branches
and only consider shortening them to BRC when generating an object file.
E.g. a branch on equal would use the JGE alias of BRCL in assembly output,
but might be shortened to the JE alias of BRC in ELF output. This was
a useful first step, but it had two problems:
(1) The z assembler isn't traditionally supposed to perform branch shortening
or branch relaxation. We followed this rule by not relaxing branches
in assembler input, but that meant that generating assembly code and
then assembling it would not produce the same result as going directly
to object code; the former would give long branches everywhere, whereas
the latter would use short branches where possible.
(2) Other useful branches, like COMPARE AND BRANCH, do not have long forms.
We would need to do something else before supporting them.
(Although COMPARE AND BRANCH does not change the condition codes,
the plan is to model COMPARE AND BRANCH as a CC-clobbering instruction
during codegen, so that we can safely lower it to a separate compare
and long branch where necessary. This is not a valid transformation
for the assembler proper to make.)
This patch therefore moves branch relaxation to a pre-emit pass.
For now, calls are still shortened from BRASL to BRAS by the assembler,
although this too is not really the traditional behaviour.
The first test takes about 1.5s to run, and there are likely to be
more tests in this vein once further branch types are added. The feeling
on IRC was that 1.5s is a bit much for a single test, so I've restricted
it to SystemZ hosts for now.
The patch exposes (and fixes) some typos in the main CodeGen/SystemZ tests.
A later patch will remove the {{g}}s from that directory.
llvm-svn: 182274
2013-05-20 22:23:08 +08:00
|
|
|
# Test normal conditional branches in cases where the sheer number of
|
|
|
|
# instructions causes some branches to be out of range.
|
|
|
|
# RUN: python %s | llc -mtriple=s390x-linux-gnu | FileCheck %s
|
|
|
|
|
|
|
|
# Construct:
|
|
|
|
#
|
|
|
|
# before0:
|
|
|
|
# conditional branch to after0
|
|
|
|
# ...
|
|
|
|
# beforeN:
|
|
|
|
# conditional branch to after0
|
|
|
|
# main:
|
|
|
|
# 0xffd8 bytes, from MVIY instructions
|
|
|
|
# conditional branch to main
|
|
|
|
# after0:
|
|
|
|
# ...
|
|
|
|
# conditional branch to main
|
|
|
|
# afterN:
|
|
|
|
#
|
|
|
|
# Each conditional branch sequence occupies 8 bytes if it uses a short branch
|
|
|
|
# and 10 if it uses a long one. The ones before "main:" have to take the branch
|
|
|
|
# length into account -- which is 4 bytes for short branches -- so the final
|
|
|
|
# (0x28 - 4) / 8 == 4 blocks can use short branches. The ones after "main:"
|
|
|
|
# do not, so the first 0x28 / 8 == 5 can use short branches. However,
|
|
|
|
# the conservative algorithm we use makes one branch unnecessarily long
|
|
|
|
# on each side.
|
|
|
|
#
|
|
|
|
# CHECK: c %r4, 0(%r3)
|
|
|
|
# CHECK: jge [[LABEL:\.L[^ ]*]]
|
|
|
|
# CHECK: c %r4, 4(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 8(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 12(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 16(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 20(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 24(%r3)
|
|
|
|
# CHECK: j{{g?}}e [[LABEL]]
|
|
|
|
# CHECK: c %r4, 28(%r3)
|
|
|
|
# CHECK: je [[LABEL]]
|
|
|
|
# CHECK: c %r4, 32(%r3)
|
|
|
|
# CHECK: je [[LABEL]]
|
|
|
|
# CHECK: c %r4, 36(%r3)
|
|
|
|
# CHECK: je [[LABEL]]
|
|
|
|
# ...main goes here...
|
|
|
|
# CHECK: c %r4, 100(%r3)
|
|
|
|
# CHECK: je [[LABEL:\.L[^ ]*]]
|
|
|
|
# CHECK: c %r4, 104(%r3)
|
|
|
|
# CHECK: je [[LABEL]]
|
|
|
|
# CHECK: c %r4, 108(%r3)
|
|
|
|
# CHECK: je [[LABEL]]
|
|
|
|
# CHECK: c %r4, 112(%r3)
|
|
|
|
# CHECK: je [[LABEL]]
|
|
|
|
# CHECK: c %r4, 116(%r3)
|
|
|
|
# CHECK: j{{g?}}e [[LABEL]]
|
|
|
|
# CHECK: c %r4, 120(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 124(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 128(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 132(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
# CHECK: c %r4, 136(%r3)
|
|
|
|
# CHECK: jge [[LABEL]]
|
|
|
|
|
|
|
|
branch_blocks = 10
|
|
|
|
main_size = 0xffd8
|
|
|
|
|
|
|
|
print 'define void @f1(i8 *%base, i32 *%stop, i32 %limit) {'
|
|
|
|
print 'entry:'
|
|
|
|
print ' br label %before0'
|
|
|
|
print ''
|
|
|
|
|
|
|
|
for i in xrange(branch_blocks):
|
|
|
|
next = 'before%d' % (i + 1) if i + 1 < branch_blocks else 'main'
|
|
|
|
print 'before%d:' % i
|
|
|
|
print ' %%bstop%d = getelementptr i32 *%%stop, i64 %d' % (i, i)
|
2013-12-10 18:36:34 +08:00
|
|
|
print ' %%bcur%d = load i32 *%%bstop%d' % (i, i)
|
[SystemZ] Add long branch pass
Before this change, the SystemZ backend would use BRCL for all branches
and only consider shortening them to BRC when generating an object file.
E.g. a branch on equal would use the JGE alias of BRCL in assembly output,
but might be shortened to the JE alias of BRC in ELF output. This was
a useful first step, but it had two problems:
(1) The z assembler isn't traditionally supposed to perform branch shortening
or branch relaxation. We followed this rule by not relaxing branches
in assembler input, but that meant that generating assembly code and
then assembling it would not produce the same result as going directly
to object code; the former would give long branches everywhere, whereas
the latter would use short branches where possible.
(2) Other useful branches, like COMPARE AND BRANCH, do not have long forms.
We would need to do something else before supporting them.
(Although COMPARE AND BRANCH does not change the condition codes,
the plan is to model COMPARE AND BRANCH as a CC-clobbering instruction
during codegen, so that we can safely lower it to a separate compare
and long branch where necessary. This is not a valid transformation
for the assembler proper to make.)
This patch therefore moves branch relaxation to a pre-emit pass.
For now, calls are still shortened from BRASL to BRAS by the assembler,
although this too is not really the traditional behaviour.
The first test takes about 1.5s to run, and there are likely to be
more tests in this vein once further branch types are added. The feeling
on IRC was that 1.5s is a bit much for a single test, so I've restricted
it to SystemZ hosts for now.
The patch exposes (and fixes) some typos in the main CodeGen/SystemZ tests.
A later patch will remove the {{g}}s from that directory.
llvm-svn: 182274
2013-05-20 22:23:08 +08:00
|
|
|
print ' %%btest%d = icmp eq i32 %%limit, %%bcur%d' % (i, i)
|
|
|
|
print ' br i1 %%btest%d, label %%after0, label %%%s' % (i, next)
|
|
|
|
print ''
|
|
|
|
|
|
|
|
print '%s:' % next
|
|
|
|
a, b = 1, 1
|
|
|
|
for i in xrange(0, main_size, 6):
|
|
|
|
a, b = b, a + b
|
|
|
|
offset = 4096 + b % 500000
|
|
|
|
value = a % 256
|
|
|
|
print ' %%ptr%d = getelementptr i8 *%%base, i64 %d' % (i, offset)
|
|
|
|
print ' store volatile i8 %d, i8 *%%ptr%d' % (value, i)
|
|
|
|
|
|
|
|
for i in xrange(branch_blocks):
|
|
|
|
print ' %%astop%d = getelementptr i32 *%%stop, i64 %d' % (i, i + 25)
|
2013-12-10 18:36:34 +08:00
|
|
|
print ' %%acur%d = load i32 *%%astop%d' % (i, i)
|
[SystemZ] Add long branch pass
Before this change, the SystemZ backend would use BRCL for all branches
and only consider shortening them to BRC when generating an object file.
E.g. a branch on equal would use the JGE alias of BRCL in assembly output,
but might be shortened to the JE alias of BRC in ELF output. This was
a useful first step, but it had two problems:
(1) The z assembler isn't traditionally supposed to perform branch shortening
or branch relaxation. We followed this rule by not relaxing branches
in assembler input, but that meant that generating assembly code and
then assembling it would not produce the same result as going directly
to object code; the former would give long branches everywhere, whereas
the latter would use short branches where possible.
(2) Other useful branches, like COMPARE AND BRANCH, do not have long forms.
We would need to do something else before supporting them.
(Although COMPARE AND BRANCH does not change the condition codes,
the plan is to model COMPARE AND BRANCH as a CC-clobbering instruction
during codegen, so that we can safely lower it to a separate compare
and long branch where necessary. This is not a valid transformation
for the assembler proper to make.)
This patch therefore moves branch relaxation to a pre-emit pass.
For now, calls are still shortened from BRASL to BRAS by the assembler,
although this too is not really the traditional behaviour.
The first test takes about 1.5s to run, and there are likely to be
more tests in this vein once further branch types are added. The feeling
on IRC was that 1.5s is a bit much for a single test, so I've restricted
it to SystemZ hosts for now.
The patch exposes (and fixes) some typos in the main CodeGen/SystemZ tests.
A later patch will remove the {{g}}s from that directory.
llvm-svn: 182274
2013-05-20 22:23:08 +08:00
|
|
|
print ' %%atest%d = icmp eq i32 %%limit, %%acur%d' % (i, i)
|
|
|
|
print ' br i1 %%atest%d, label %%main, label %%after%d' % (i, i)
|
|
|
|
print ''
|
|
|
|
print 'after%d:' % i
|
|
|
|
|
|
|
|
print ' ret void'
|
|
|
|
print '}'
|