1@ This test has a partner (ldr-pseudo-darwin.s) that contains matching 2@ tests for the ldr-pseudo on darwin targets. We need separate files 3@ because the syntax for switching sections and temporary labels differs 4@ between darwin and linux. Any tests added here should have a matching 5@ test added there. 6 7@RUN: llvm-mc -triple armv7-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-ARM --check-prefix=CHECK %s 8@RUN: llvm-mc -triple armv5-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-ARMV5 --check-prefix=CHECK %s 9@RUN: llvm-mc -triple thumbv5-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-THUMB --check-prefix=CHECK %s 10@RUN: llvm-mc -triple thumbv7-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-THUMB2 --check-prefix=CHECK %s 11@RUN: llvm-mc -triple thumbv8m.base-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-BASELINE --check-prefix=CHECK %s 12@ 13@ Check that large constants are converted to ldr from constant pool 14@ 15@ simple test 16.section b,"ax",%progbits 17@ CHECK-LABEL: f3: 18f3: 19 ldr r0, =0x10002 20@ CHECK: ldr r0, .Ltmp[[TMP0:[0-9]+]] 21 22@ loading multiple constants 23.section c,"ax",%progbits 24@ CHECK-LABEL: f4: 25f4: 26 ldr r0, =0x10003 27@ CHECK: ldr r0, .Ltmp[[TMP1:[0-9]+]] 28 adds r0, r0, #1 29 adds r0, r0, #1 30 adds r0, r0, #1 31 adds r0, r0, #1 32 ldr r0, =0x10004 33@ CHECK: ldr r0, .Ltmp[[TMP2:[0-9]+]] 34 adds r0, r0, #1 35 adds r0, r0, #1 36 37@ TODO: the same constants should have the same constant pool location 38.section d,"ax",%progbits 39@ CHECK-LABEL: f5: 40f5: 41 ldr r0, =0x10005 42@ CHECK: ldr r0, .Ltmp[[TMP3:[0-9]+]] 43 adds r0, r0, #1 44 adds r0, r0, #1 45 adds r0, r0, #1 46 adds r0, r0, #1 47 adds r0, r0, #1 48 adds r0, r0, #1 49 adds r0, r0, #1 50 ldr r0, =0x10005 51@ CHECK: ldr r0, .Ltmp[[TMP3:[0-9]+]] 52 adds r0, r0, #1 53 adds r0, r0, #1 54 adds r0, r0, #1 55 adds r0, r0, #1 56 adds r0, r0, #1 57 adds r0, r0, #1 58 59@ a section defined in multiple pieces should be merged and use a single constant pool 60.section e,"ax",%progbits 61@ CHECK-LABEL: f6: 62f6: 63 ldr r0, =0x10006 64@ CHECK: ldr r0, .Ltmp[[TMP5:[0-9]+]] 65 adds r0, r0, #1 66 adds r0, r0, #1 67 adds r0, r0, #1 68 69.section f, "ax", %progbits 70@ CHECK-LABEL: f7: 71f7: 72 adds r0, r0, #1 73 adds r0, r0, #1 74 adds r0, r0, #1 75 76.section e, "ax", %progbits 77@ CHECK-LABEL: f8: 78f8: 79 adds r0, r0, #1 80 ldr r0, =0x10007 81@ CHECK: ldr r0, .Ltmp[[TMP6:[0-9]+]] 82 adds r0, r0, #1 83 adds r0, r0, #1 84 85@ 86@ Check that symbols can be loaded using ldr pseudo 87@ 88 89@ load an undefined symbol 90.section g,"ax",%progbits 91@ CHECK-LABEL: f9: 92f9: 93 ldr r0, =foo 94@ CHECK: ldr r0, .Ltmp[[TMP7:[0-9]+]] 95 96@ load a symbol from another section 97.section h,"ax",%progbits 98@ CHECK-LABEL: f10: 99f10: 100 ldr r0, =f5 101@ CHECK: ldr r0, .Ltmp[[TMP8:[0-9]+]] 102 103@ load a symbol from the same section 104.section i,"ax",%progbits 105@ CHECK-LABEL: f11: 106f11: 107 ldr r0, =f12 108@ CHECK: ldr r0, .Ltmp[[TMP9:[0-9]+]] 109 110@ CHECK-LABEL: f12: 111f12: 112 adds r0, r0, #1 113 adds r0, r0, #1 114 115.section j,"ax",%progbits 116@ mix of symbols and constants 117@ CHECK-LABEL: f13: 118f13: 119 adds r0, r0, #1 120 adds r0, r0, #1 121 ldr r0, =0x10008 122@ CHECK: ldr r0, .Ltmp[[TMP10:[0-9]+]] 123 adds r0, r0, #1 124 adds r0, r0, #1 125 ldr r0, =bar 126@ CHECK: ldr r0, .Ltmp[[TMP11:[0-9]+]] 127 adds r0, r0, #1 128 adds r0, r0, #1 129@ 130@ Check for correct usage in other contexts 131@ 132 133@ usage in macro 134.macro useit_in_a_macro 135 ldr r0, =0x10009 136 ldr r0, =baz 137.endm 138.section k,"ax",%progbits 139@ CHECK-LABEL: f14: 140f14: 141 useit_in_a_macro 142@ CHECK: ldr r0, .Ltmp[[TMP12:[0-9]+]] 143@ CHECK: ldr r0, .Ltmp[[TMP13:[0-9]+]] 144 145@ usage with expressions 146.section l, "ax", %progbits 147@ CHECK-LABEL: f15: 148f15: 149 ldr r0, =0x10001+9 150@ CHECK: ldr r0, .Ltmp[[TMP14:[0-9]+]] 151 adds r0, r0, #1 152 ldr r0, =bar+4 153@ CHECK: ldr r0, .Ltmp[[TMP15:[0-9]+]] 154 adds r0, r0, #1 155 156@ transformation to mov 157.section m, "ax", %progbits 158@ CHECK-LABEL: f16: 159f16: 160 161@ Representable in ARM, and Thumb with support mov.w or movw 162 ldr r1, =0x1 163@ CHECK-ARM: mov r1, #1 164@ CHECK-ARMV5: mov r1, #1 165@ CHECK-THUMB: ldr r1, .Ltmp[[TMP16:[0-9]+]] 166@ CHECK-THUMB2: mov.w r1, #1 167@ CHECK-BASELINE: movw r1, #1 168 169@ Immediate is representable in A1 and T2 modified immediate only not movw 170 ldr r2, =0x120000 171@ CHECK-ARM: mov r2, #1179648 172@ CHECK-ARMV5: mov r2, #1179648 173@ CHECK-THUMB: ldr r2, .Ltmp[[TMP17:[0-9]+]] 174@ CHECK-THUMB2: mov.w r2, #1179648 175@ CHECK-BASELINE: ldr r2, .Ltmp[[TMP16:[0-9]+]] 176 177@ Immediate can be represented only with movw instruction 178 ldr r3, =0x1234 179@ CHECK-ARM: movw r3, #4660 180@ CHECK-ARMV5: ldr r3, .Ltmp[[TMP16:[0-9]+]] 181@ CHECK-THUMB: ldr r3, .Ltmp[[TMP18:[0-9]+]] 182@ CHECK-THUMB2: movw r3, #4660 183@ CHECK-BASELINE: movw r3, #4660 184 185@ Immediate can be represented only with T2 modified immediate 186 ldr r4, =0xabababab 187@ CHECK-ARM: ldr r4, .Ltmp[[TMP16:[0-9]+]] 188@ CHECK-ARMV5: ldr r4, .Ltmp[[TMP17:[0-9]+]] 189@ CHECK-THUMB: ldr r4, .Ltmp[[TMP19:[0-9]+]] 190@ CHECK-THUMB2: mov.w r4, #2880154539 191@ CHECK-BASELINE: ldr r4, .Ltmp[[TMP17:[0-9]+]] 192 193@ Immediate can be represented only with A1 modified immediate 194 ldr r5, =0x1000000b 195@ CHECK-ARM: mov r5, #268435467 196@ CHECK-ARMV5: mov r5, #268435467 197@ CHECK-THUMB: ldr r5, .Ltmp[[TMP20:[0-9]+]] 198@ CHECK-THUMB2: ldr r5, .Ltmp[[TMP16:[0-9]+]] 199@ CHECK-BASELINE: ldr r5, .Ltmp[[TMP18:[0-9]+]] 200 201@ Negative numbers can be used with MVN or in Thumb2 with modified immediate 202 ldr r6, =-1 203@ CHECK-ARM: mvn r6, #0 204@ CHECK-ARMV5: mvn r6, #0 205@ CHECK-THUMB: ldr r6, .Ltmp[[TMP21:[0-9]+]] 206@ CHECK-THUMB2: mov.w r6, #-1 207@ CHECK-BASELINE: ldr r6, .Ltmp[[TMP19:[0-9]+]] 208 ldr r7, =-0x100 209@ CHECK-ARM: mvn r7, #255 210@ CHECK-ARMV5: mvn r7, #255 211@ CHECK-THUMB: ldr r7, .Ltmp[[TMP22:[0-9]+]] 212@ CHECK-THUMB2: mvn r7, #255 213@ CHECK-BASELINE: ldr r7, .Ltmp[[TMP20:[0-9]+]] 214 215@ Constant expressions can be used 216 .equ expr, 0x10 + 0x10 217 ldr r0, = expr 218@ CHECK-ARM: mov r0, #32 219@ CHECK-ARMV5: mov r0, #32 220@ CHECK-THUMB: ldr r0, .Ltmp[[TMP23:[0-9]+]] 221@ CHECK-THUMB2: mov.w r0, #32 222@ CHECK-BASELINE: movw r0, #32 223 ldr r1, = expr - 0x10 224@ CHECK-ARM: mov r1, #16 225@ CHECK-ARMV5: mov r1, #16 226@ CHECK-THUMB: ldr r1, .Ltmp[[TMP24:[0-9]+]] 227@ CHECK-THUMB2: mov.w r1, #16 228@ CHECK-BASELINE: movw r1, #16 229 230@ usage of translation in macro 231.macro usemov_in_a_macro 232 ldr r2, =0x3 233 ldr r3, =expr 234.endm 235@ CHECK-LABEL: f17: 236f17: 237 usemov_in_a_macro 238@ CHECK-ARM: mov r2, #3 239@ CHECK-ARM: mov r3, #32 240@ CHECK-ARMV5: mov r2, #3 241@ CHECK-ARMV5: mov r3, #32 242@ CHECK-THUMB: ldr r2, .Ltmp[[TMP25:[0-9]+]] 243@ CHECK-THUMB: ldr r3, .Ltmp[[TMP26:[0-9]+]] 244@ CHECK-THUMB2: mov.w r2, #3 245@ CHECK-THUMB2: mov.w r3, #32 246@ CHECK-BASELINE: movw r2, #3 247@ CHECK-BASELINE: movw r3, #32 248@ 249@ Constant Pools 250@ 251@ CHECK: .section b,"ax",%progbits 252@ CHECK: .p2align 2 253@ CHECK: .Ltmp[[TMP0]] 254@ CHECK: .long 65538 255 256@ CHECK: .section c,"ax",%progbits 257@ CHECK: .p2align 2 258@ CHECK: .Ltmp[[TMP1]] 259@ CHECK: .long 65539 260@ CHECK: .Ltmp[[TMP2]] 261@ CHECK: .long 65540 262 263@ CHECK: .section d,"ax",%progbits 264@ CHECK: .p2align 2 265@ CHECK: .Ltmp[[TMP3]] 266@ CHECK: .long 65541 267 268@ CHECK: .section e,"ax",%progbits 269@ CHECK: .p2align 2 270@ CHECK: .Ltmp[[TMP5]] 271@ CHECK: .long 65542 272@ CHECK: .Ltmp[[TMP6]] 273@ CHECK: .long 65543 274 275@ Should not switch to section because it has no constant pool 276@ CHECK-NOT: .section f,"ax",%progbits 277 278@ CHECK: .section g,"ax",%progbits 279@ CHECK: .p2align 2 280@ CHECK: .Ltmp[[TMP7]] 281@ CHECK: .long foo 282 283@ CHECK: .section h,"ax",%progbits 284@ CHECK: .p2align 2 285@ CHECK: .Ltmp[[TMP8]] 286@ CHECK: .long f5 287 288@ CHECK: .section i,"ax",%progbits 289@ CHECK: .p2align 2 290@ CHECK: .Ltmp[[TMP9]] 291@ CHECK: .long f12 292 293@ CHECK: .section j,"ax",%progbits 294@ CHECK: .p2align 2 295@ CHECK: .Ltmp[[TMP10]] 296@ CHECK: .long 65544 297@ CHECK: .Ltmp[[TMP11]] 298@ CHECK: .long bar 299 300@ CHECK: .section k,"ax",%progbits 301@ CHECK: .p2align 2 302@ CHECK: .Ltmp[[TMP12]] 303@ CHECK: .long 65545 304@ CHECK: .Ltmp[[TMP13]] 305@ CHECK: .long baz 306 307@ CHECK: .section l,"ax",%progbits 308@ CHECK: .p2align 2 309@ CHECK: .Ltmp[[TMP14]] 310@ CHECK: .long 65546 311@ CHECK: .Ltmp[[TMP15]] 312@ CHECK: .long bar+4 313