llvm-mirror/test/MC/AArch64/label-arithmetic-elf.s
Diana Picus aa4f835b48 [AArch64] Allow label arithmetic with add/sub/cmp
Allow instructions such as 'cmp w0, #(end - start)' by folding the
expression into a constant. For ELF, we fold only if the symbols are in
the same section. For MachO, we fold if the expression contains only
symbols that are not linker visible.

Fixes https://llvm.org/bugs/show_bug.cgi?id=18920

Differential Revision: https://reviews.llvm.org/D23834

llvm-svn: 283862
2016-10-11 09:17:47 +00:00

97 lines
1.9 KiB
ArmAsm

// RUN: llvm-mc -triple aarch64-elf -filetype=obj %s -o - | llvm-objdump -d - | FileCheck %s
start:
.space 8
end:
// CHECK-LABEL: end:
adds w0, w1, #(end - start)
adds x0, x1, #(end - start)
add w0, w1, #(end - start)
add x0, x1, #(end - start)
cmp w0, #(end - start)
cmp x0, #(end - start)
sub w0, w1, #(end - start)
sub x0, x1, #(end - start)
// CHECK: adds w0, w1, #8
// CHECK: adds x0, x1, #8
// CHECK: add w0, w1, #8
// CHECK: add x0, x1, #8
// CHECK: cmp w0, #8
// CHECK: cmp x0, #8
// CHECK: sub w0, w1, #8
// CHECK: sub x0, x1, #8
add w0, w1, #(end - start), lsl #12
cmp w0, #(end - start), lsl #12
// CHECK: add w0, w1, #8, lsl #12
// CHECK: cmp w0, #8, lsl #12
add w0, w1, #((end - start) >> 2)
cmp w0, #((end - start) >> 2)
// CHECK: add w0, w1, #2
// CHECK: cmp w0, #2
add w0, w1, #(end - start + 12)
cmp w0, #(end - start + 12)
// CHECK: add w0, w1, #20
// CHECK: cmp w0, #20
add w0, w1, #(forward - end)
cmp w0, #(forward - end)
// CHECK: add w0, w1, #320
// CHECK: cmp w0, #320
// Add some filler so we don't have to modify #(forward - end) if we add more
// instructions above
.Lfiller:
.space 320 - (.Lfiller - end)
forward:
.space 8
.Lstart:
.space 8
.Lend:
add w0, w1, #(.Lend - .Lstart)
cmp w0, #(.Lend - .Lstart)
// CHECK: add w0, w1, #8
// CHECK: cmp w0, #8
.Lprivate1:
.space 8
notprivate:
.space 8
.Lprivate2:
add w0, w1, #(.Lprivate2 - .Lprivate1)
cmp w0, #(.Lprivate2 - .Lprivate1)
// CHECK: add w0, w1, #16
// CHECK: cmp w0, #16
.type foo, @function
foo:
// CHECK-LABEL: foo:
add w0, w1, #(foo - .Lprivate2)
cmp w0, #(foo - .Lprivate2)
// CHECK: add w0, w1, #8
// CHECK: cmp w0, #8
ret
.type goo, @function
goo:
// CHECK-LABEL: goo:
add w0, w1, #(goo - foo)
cmp w0, #(goo - foo)
// CHECK: add w0, w1, #12
// CHECK: cmp w0, #12
add w0, w1, #(. - goo)
cmp w0, #(. - goo)
// CHECK: add w0, w1, #8
// CHECK: cmp w0, #12
ret