Home | History | Annotate | Download | only in AArch64
      1 //RUN: llvm-mc  -triple=aarch64-linux-gnu %s | FileCheck %s
      2 
      3 //
      4 // Check that large constants are converted to ldr from constant pool
      5 //
      6 // simple test
      7 .section a, "ax", @progbits
      8 // CHECK-LABEL: f1:
      9 f1:
     10   ldr x0, =0x1234
     11 // CHECK: movz    x0, #0x1234
     12   ldr w1, =0x4567
     13 // CHECK:  movz    w1, #0x4567
     14   ldr x0, =0x12340000
     15 // CHECK:  movz    x0, #0x1234, lsl #16
     16   ldr w1, =0x45670000
     17 // CHECK: movz    w1, #0x4567, lsl #16
     18   ldr x0, =0xabc00000000
     19 // CHECK: movz    x0, #0xabc, lsl #32
     20   ldr x0, =0xbeef000000000000
     21 // CHECK: movz    x0, #0xbeef, lsl #48
     22 
     23 .section b,"ax",@progbits
     24 // CHECK-LABEL: f3:
     25 f3:
     26   ldr x0, =0x10001
     27 // CHECK: ldr x0, .Ltmp[[TMP0:[0-9]+]]
     28 
     29 // loading multiple constants
     30 .section c,"ax",@progbits
     31 // CHECK-LABEL: f4:
     32 f4:
     33   ldr x0, =0x10002
     34 // CHECK: ldr x0, .Ltmp[[TMP1:[0-9]+]]
     35   adds x0, x0, #1
     36   adds x0, x0, #1
     37   adds x0, x0, #1
     38   adds x0, x0, #1
     39   ldr x0, =0x10003
     40 // CHECK: ldr x0, .Ltmp[[TMP2:[0-9]+]]
     41   adds x0, x0, #1
     42   adds x0, x0, #1
     43 
     44 // TODO: the same constants should have the same constant pool location
     45 .section d,"ax",@progbits
     46 // CHECK-LABEL: f5:
     47 f5:
     48   ldr x0, =0x10004
     49 // CHECK: ldr x0, .Ltmp[[TMP3:[0-9]+]]
     50   adds x0, x0, #1
     51   adds x0, x0, #1
     52   adds x0, x0, #1
     53   adds x0, x0, #1
     54   adds x0, x0, #1
     55   adds x0, x0, #1
     56   adds x0, x0, #1
     57   ldr x0, =0x10004
     58 // CHECK: ldr x0, .Ltmp[[TMP4:[0-9]+]]
     59   adds x0, x0, #1
     60   adds x0, x0, #1
     61   adds x0, x0, #1
     62   adds x0, x0, #1
     63   adds x0, x0, #1
     64   adds x0, x0, #1
     65 
     66 // a section defined in multiple pieces should be merged and use a single constant pool
     67 .section e,"ax",@progbits
     68 // CHECK-LABEL: f6:
     69 f6:
     70   ldr x0, =0x10006
     71 // CHECK: ldr x0, .Ltmp[[TMP5:[0-9]+]]
     72   adds x0, x0, #1
     73   adds x0, x0, #1
     74   adds x0, x0, #1
     75 
     76 .section f, "ax", @progbits
     77 // CHECK-LABEL: f7:
     78 f7:
     79   adds x0, x0, #1
     80   adds x0, x0, #1
     81   adds x0, x0, #1
     82 
     83 .section e, "ax", @progbits
     84 // CHECK-LABEL: f8:
     85 f8:
     86   adds x0, x0, #1
     87   ldr x0, =0x10007
     88 // CHECK: ldr x0, .Ltmp[[TMP6:[0-9]+]]
     89   adds x0, x0, #1
     90   adds x0, x0, #1
     91 
     92 //
     93 // Check that symbols can be loaded using ldr pseudo
     94 //
     95 
     96 // load an undefined symbol
     97 .section g,"ax",@progbits
     98 // CHECK-LABEL: f9:
     99 f9:
    100   ldr x0, =foo
    101 // CHECK: ldr x0, .Ltmp[[TMP7:[0-9]+]]
    102 
    103 // load a symbol from another section
    104 .section h,"ax",@progbits
    105 // CHECK-LABEL: f10:
    106 f10:
    107   ldr x0, =f5
    108 // CHECK: ldr x0, .Ltmp[[TMP8:[0-9]+]]
    109 
    110 // load a symbol from the same section
    111 .section i,"ax",@progbits
    112 // CHECK-LABEL: f11:
    113 f11:
    114   ldr x0, =f12
    115 // CHECK: ldr x0, .Ltmp[[TMP9:[0-9]+]]
    116   ldr w0,=0x3C000
    117 // CHECK: ldr     w0, .Ltmp[[TMP10:[0-9]+]]
    118 
    119 // CHECK-LABEL: f12:
    120 f12:
    121   adds x0, x0, #1
    122   adds x0, x0, #1
    123 
    124 .section j,"ax",@progbits
    125 // mix of symbols and constants
    126 // CHECK-LABEL: f13:
    127 f13:
    128   adds x0, x0, #1
    129   adds x0, x0, #1
    130   ldr x0, =0x101
    131 // CHECK: movz x0, #0x101
    132   adds x0, x0, #1
    133   adds x0, x0, #1
    134   ldr x0, =bar
    135 // CHECK: ldr x0, .Ltmp[[TMP11:[0-9]+]]
    136   adds x0, x0, #1
    137   adds x0, x0, #1
    138 //
    139 // Check for correct usage in other contexts
    140 //
    141 
    142 // usage in macro
    143 .macro useit_in_a_macro
    144   ldr x0, =0x10008
    145   ldr x0, =baz
    146 .endm
    147 .section k,"ax",@progbits
    148 // CHECK-LABEL: f14:
    149 f14:
    150   useit_in_a_macro
    151 // CHECK: ldr x0, .Ltmp[[TMP12:[0-9]+]]
    152 // CHECK: ldr x0, .Ltmp[[TMP13:[0-9]+]]
    153 
    154 // usage with expressions
    155 .section l, "ax", @progbits
    156 // CHECK-LABEL: f15:
    157 f15:
    158   ldr x0, =0x10001+8
    159 // CHECK: ldr x0, .Ltmp[[TMP14:[0-9]+]]
    160   adds x0, x0, #1
    161   ldr x0, =bar+4
    162 // CHECK: ldr x0, .Ltmp[[TMP15:[0-9]+]]
    163   adds x0, x0, #1
    164 
    165 //
    166 // Constant Pools
    167 //
    168 // CHECK: .section b,"ax",@progbits
    169 // CHECK: .align 2
    170 // CHECK: .Ltmp[[TMP0]]
    171 // CHECK: .word 65537
    172 
    173 // CHECK: .section c,"ax",@progbits
    174 // CHECK: .align 2
    175 // CHECK: .Ltmp[[TMP1]]
    176 // CHECK: .word 65538
    177 // CHECK: .Ltmp[[TMP2]]
    178 // CHECK: .word 65539
    179 
    180 // CHECK: .section d,"ax",@progbits
    181 // CHECK: .align 2
    182 // CHECK: .Ltmp[[TMP3]]
    183 // CHECK: .word 65540
    184 // CHECK: .Ltmp[[TMP4]]
    185 // CHECK: .word 65540
    186 
    187 // CHECK: .section e,"ax",@progbits
    188 // CHECK: .align 2
    189 // CHECK: .Ltmp[[TMP5]]
    190 // CHECK: .word 65542
    191 // CHECK: .Ltmp[[TMP6]]
    192 // CHECK: .word 65543
    193 
    194 // Should not switch to section because it has no constant pool
    195 // CHECK-NOT: .section f,"ax",@progbits
    196 
    197 // CHECK: .section g,"ax",@progbits
    198 // CHECK: .align 2
    199 // CHECK: .Ltmp[[TMP7]]
    200 // CHECK: .word foo
    201 
    202 // CHECK: .section h,"ax",@progbits
    203 // CHECK: .align 2
    204 // CHECK: .Ltmp[[TMP8]]
    205 // CHECK: .word f5
    206 
    207 // CHECK: .section i,"ax",@progbits
    208 // CHECK: .align 2
    209 // CHECK: .Ltmp[[TMP9]]
    210 // CHECK: .word f12
    211 // CHECK: .Ltmp[[TMP10]]
    212 // CHECK: .word 245760
    213 
    214 // CHECK: .section j,"ax",@progbits
    215 // CHECK: .align 2
    216 // CHECK: .Ltmp[[TMP11]]
    217 // CHECK: .word bar
    218 
    219 // CHECK: .section k,"ax",@progbits
    220 // CHECK: .align 2
    221 // CHECK: .Ltmp[[TMP12]]
    222 // CHECK: .word 65544
    223 // CHECK: .Ltmp[[TMP13]]
    224 // CHECK: .word baz
    225 
    226 // CHECK: .section l,"ax",@progbits
    227 // CHECK: .align 2
    228 // CHECK: .Ltmp[[TMP14]]
    229 // CHECK: .word 65545
    230 // CHECK: .Ltmp[[TMP15]]
    231 // CHECK: .word bar+4
    232