1@ This test has a partner (ldr-pseudo.s) that contains matching 2@ tests for the ldr-pseudo on linux 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-base-apple-darwin %s | FileCheck --check-prefix=CHECK-ARM --check-prefix=CHECK %s 8@RUN: llvm-mc -triple armv5-base-apple-darwin %s | FileCheck --check-prefix=CHECK-ARMV5 --check-prefix=CHECK %s 9@RUN: llvm-mc -triple thumbv5-base-apple-darwin %s | FileCheck --check-prefix=CHECK-THUMB --check-prefix=CHECK %s 10@RUN: llvm-mc -triple thumbv7-base-apple-darwin %s | FileCheck --check-prefix=CHECK-THUMB2 --check-prefix=CHECK %s 11@RUN: llvm-mc -triple thumbv8m.base-base-apple-darwin %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 __TEXT,b,regular,pure_instructions 17@ CHECK-LABEL: f3: 18f3: 19 ldr r0, =0x10002 20@ CHECK: ldr r0, Ltmp0 21 22@ loading multiple constants 23.section __TEXT,c,regular,pure_instructions 24@ CHECK-LABEL: f4: 25f4: 26 ldr r0, =0x10003 27@ CHECK: ldr r0, Ltmp1 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, Ltmp2 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 __TEXT,d,regular,pure_instructions 39@ CHECK-LABEL: f5: 40f5: 41 ldr r0, =0x10005 42@ CHECK: ldr r0, Ltmp3 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, Ltmp4 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 __TEXT,e,regular,pure_instructions 61@ CHECK-LABEL: f6: 62f6: 63 ldr r0, =0x10006 64@ CHECK: ldr r0, Ltmp5 65 adds r0, r0, #1 66 adds r0, r0, #1 67 adds r0, r0, #1 68 69.section __TEXT,f,regular,pure_instructions 70@ CHECK-LABEL: f7: 71f7: 72 adds r0, r0, #1 73 adds r0, r0, #1 74 adds r0, r0, #1 75 76.section __TEXT,e,regular,pure_instructions 77@ CHECK-LABEL: f8: 78f8: 79 adds r0, r0, #1 80 ldr r0, =0x10007 81@ CHECK: ldr r0, Ltmp6 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 __TEXT,g,regular,pure_instructions 91@ CHECK-LABEL: f9: 92f9: 93 ldr r0, =foo 94@ CHECK: ldr r0, Ltmp7 95 96@ load a symbol from another section 97.section __TEXT,h,regular,pure_instructions 98@ CHECK-LABEL: f10: 99f10: 100 ldr r0, =f5 101@ CHECK: ldr r0, Ltmp8 102 103@ load a symbol from the same section 104.section __TEXT,i,regular,pure_instructions 105@ CHECK-LABEL: f11: 106f11: 107 ldr r0, =f12 108@ CHECK: ldr r0, Ltmp9 109 110@ CHECK-LABEL: f12: 111f12: 112 adds r0, r0, #1 113 adds r0, r0, #1 114 115.section __TEXT,j,regular,pure_instructions 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, Ltmp10 123 adds r0, r0, #1 124 adds r0, r0, #1 125 ldr r0, =bar 126@ CHECK: ldr r0, Ltmp11 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 __TEXT,k,regular,pure_instructions 139@ CHECK-LABEL: f14: 140f14: 141 useit_in_a_macro 142@ CHECK: ldr r0, Ltmp12 143@ CHECK: ldr r0, Ltmp13 144 145@ usage with expressions 146.section __TEXT,l,regular,pure_instructions 147@ CHECK-LABEL: f15: 148f15: 149 ldr r0, =0x10001+9 150@ CHECK: ldr r0, Ltmp14 151 adds r0, r0, #1 152 ldr r0, =bar+4 153@ CHECK: ldr r0, Ltmp15 154 adds r0, r0, #1 155 156@ transformation to mov 157.section __TEXT,m,regular,pure_instructions 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, Ltmp16 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, Ltmp17 174@ CHECK-THUMB2: mov.w r2, #1179648 175@ CHECK-BASELINE: ldr r2, Ltmp16 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, Ltmp16 181@ CHECK-THUMB: ldr r3, Ltmp18 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, Ltmp16 188@ CHECK-ARMV5: ldr r4, Ltmp17 189@ CHECK-THUMB: ldr r4, Ltmp19 190@ CHECK-THUMB2: mov.w r4, #2880154539 191@ CHECK-BASELINE: ldr r4, Ltmp17 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, Ltmp20 198@ CHECK-THUMB2: ldr r5, Ltmp16 199@ CHECK-BASELINE: ldr r5, Ltmp18 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, Ltmp21 206@ CHECK-THUMB2: mov.w r6, #-1 207@ CHECK-BASELINE: ldr r6, Ltmp19 208 ldr r7, =-0x100 209@ CHECK-ARM: mvn r7, #255 210@ CHECK-ARMV5: mvn r7, #255 211@ CHECK-THUMB: ldr r7, Ltmp22 212@ CHECK-THUMB2: mvn r7, #255 213@ CHECK-BASELINE: ldr r7, Ltmp20 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, Ltmp23 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, Ltmp24 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, Ltmp25 243@ CHECK-THUMB: ldr r3, Ltmp26 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 __TEXT,b,regular,pure_instructions 252@ CHECK: .data_region 253@ CHECK: .p2align 2 254@ CHECK-LABEL: Ltmp0: 255@ CHECK: .long 65538 256@ CHECK: .end_data_region 257 258@ CHECK: .section __TEXT,c,regular,pure_instructions 259@ CHECK: .data_region 260@ CHECK: .p2align 2 261@ CHECK-LABEL: Ltmp1: 262@ CHECK: .long 65539 263@ CHECK: .p2align 2 264@ CHECK-LABEL: Ltmp2: 265@ CHECK: .long 65540 266@ CHECK: .end_data_region 267 268@ CHECK: .section __TEXT,d,regular,pure_instructions 269@ CHECK: .data_region 270@ CHECK: .p2align 2 271@ CHECK-LABEL: Ltmp3: 272@ CHECK: .long 65541 273@ CHECK: .p2align 2 274@ CHECK-LABEL: Ltmp4: 275@ CHECK: .long 65541 276@ CHECK: .end_data_region 277 278@ CHECK: .section __TEXT,e,regular,pure_instructions 279@ CHECK: .data_region 280@ CHECK: .p2align 2 281@ CHECK-LABEL: Ltmp5: 282@ CHECK: .long 65542 283@ CHECK: .p2align 2 284@ CHECK-LABEL: Ltmp6: 285@ CHECK: .long 65543 286@ CHECK: .end_data_region 287 288@ Should not switch to section because it has no constant pool 289@ CHECK-NOT: .section __TEXT,f,regular,pure_instructions 290 291@ CHECK: .section __TEXT,g,regular,pure_instructions 292@ CHECK: .data_region 293@ CHECK: .p2align 2 294@ CHECK-LABEL: Ltmp7: 295@ CHECK: .long foo 296@ CHECK: .end_data_region 297 298@ CHECK: .section __TEXT,h,regular,pure_instructions 299@ CHECK: .data_region 300@ CHECK: .p2align 2 301@ CHECK-LABEL: Ltmp8: 302@ CHECK: .long f5 303@ CHECK: .end_data_region 304 305@ CHECK: .section __TEXT,i,regular,pure_instructions 306@ CHECK: .data_region 307@ CHECK: .p2align 2 308@ CHECK-LABEL: Ltmp9: 309@ CHECK: .long f12 310@ CHECK: .end_data_region 311 312@ CHECK: .section __TEXT,j,regular,pure_instructions 313@ CHECK: .data_region 314@ CHECK: .p2align 2 315@ CHECK-LABEL: Ltmp10: 316@ CHECK: .long 65544 317@ CHECK: .p2align 2 318@ CHECK-LABEL: Ltmp11: 319@ CHECK: .long bar 320@ CHECK: .end_data_region 321 322@ CHECK: .section __TEXT,k,regular,pure_instructions 323@ CHECK: .data_region 324@ CHECK: .p2align 2 325@ CHECK-LABEL: Ltmp12: 326@ CHECK: .long 65545 327@ CHECK: .p2align 2 328@ CHECK-LABEL: Ltmp13: 329@ CHECK: .long baz 330@ CHECK: .end_data_region 331 332@ CHECK: .section __TEXT,l,regular,pure_instructions 333@ CHECK: .data_region 334@ CHECK: .p2align 2 335@ CHECK-LABEL: Ltmp14: 336@ CHECK: .long 65546 337@ CHECK: .p2align 2 338@ CHECK-LABEL: Ltmp15: 339@ CHECK: .long bar+4 340@ CHECK: .end_data_region 341