blob: 2efd91f503e5d488d7d3bb69ed1bd8878f3e446e [file] [log] [blame]
Jonathan Roelofs229eb4c2015-01-21 22:39:43 +00001; RUN: llc -mtriple=thumbv4t-none--eabi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V4T
2; RUN: llc -mtriple=thumbv6m-none--eabi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V6M
3
Renato Golinb9887ef2015-02-25 14:41:06 +00004; CHECK-LABEL: test1
5define i32 @test1(i32* %p) {
Jonathan Roelofs229eb4c2015-01-21 22:39:43 +00006
Renato Golinb9887ef2015-02-25 14:41:06 +00007; Offsets less than 8 can be generated in a single add
8; CHECK: adds [[NEWBASE:r[0-9]]], r0, #4
David Blaikie79e6c742015-02-27 19:29:02 +00009 %1 = getelementptr inbounds i32, i32* %p, i32 1
10 %2 = getelementptr inbounds i32, i32* %p, i32 2
11 %3 = getelementptr inbounds i32, i32* %p, i32 3
12 %4 = getelementptr inbounds i32, i32* %p, i32 4
Jonathan Roelofs229eb4c2015-01-21 22:39:43 +000013
Jonathan Roelofs229eb4c2015-01-21 22:39:43 +000014; CHECK-NEXT: ldm [[NEWBASE]],
David Blaikiea79ac142015-02-27 21:17:42 +000015 %5 = load i32, i32* %1, align 4
16 %6 = load i32, i32* %2, align 4
17 %7 = load i32, i32* %3, align 4
18 %8 = load i32, i32* %4, align 4
Renato Golinb9887ef2015-02-25 14:41:06 +000019
20 %9 = add nsw i32 %5, %6
21 %10 = add nsw i32 %9, %7
22 %11 = add nsw i32 %10, %8
23 ret i32 %11
Jonathan Roelofs229eb4c2015-01-21 22:39:43 +000024}
25
Renato Golinb9887ef2015-02-25 14:41:06 +000026; CHECK-LABEL: test2
27define i32 @test2(i32* %p) {
28
29; Offsets >=8 require a mov and an add
30; CHECK-V4T: movs [[NEWBASE:r[0-9]]], r0
31; CHECK-V6M: mov [[NEWBASE:r[0-9]]], r0
32; CHECK-NEXT: adds [[NEWBASE]], #8
David Blaikie79e6c742015-02-27 19:29:02 +000033 %1 = getelementptr inbounds i32, i32* %p, i32 2
34 %2 = getelementptr inbounds i32, i32* %p, i32 3
35 %3 = getelementptr inbounds i32, i32* %p, i32 4
36 %4 = getelementptr inbounds i32, i32* %p, i32 5
Renato Golinb9887ef2015-02-25 14:41:06 +000037
38; CHECK-NEXT: ldm [[NEWBASE]],
David Blaikiea79ac142015-02-27 21:17:42 +000039 %5 = load i32, i32* %1, align 4
40 %6 = load i32, i32* %2, align 4
41 %7 = load i32, i32* %3, align 4
42 %8 = load i32, i32* %4, align 4
Renato Golinb9887ef2015-02-25 14:41:06 +000043
44 %9 = add nsw i32 %5, %6
45 %10 = add nsw i32 %9, %7
46 %11 = add nsw i32 %10, %8
47 ret i32 %11
48}