[DAGCombiner] Add target hook function to decide folding (mul (add x, c1), c2)
[llvm-project.git] / llvm / test / MC / RISCV / pcrel-fixups.s
blobf4f9e2c57a0e7839383f0c00e9c32ba6da4eadaa
1 # RUN: llvm-mc -triple riscv32 -mattr=-relax -filetype obj %s \
2 # RUN: | llvm-objdump -M no-aliases -d -r - \
3 # RUN: | FileCheck --check-prefix NORELAX %s
4 # RUN: llvm-mc -triple riscv32 -mattr=+relax -filetype obj %s \
5 # RUN: | llvm-objdump -M no-aliases -d -r - \
6 # RUN: | FileCheck --check-prefix RELAX %s
7 # RUN: llvm-mc -triple riscv64 -mattr=-relax -filetype obj %s \
8 # RUN: | llvm-objdump -M no-aliases -d -r - \
9 # RUN: | FileCheck --check-prefix NORELAX %s
10 # RUN: llvm-mc -triple riscv64 -mattr=+relax -filetype obj %s \
11 # RUN: | llvm-objdump -M no-aliases -d -r - \
12 # RUN: | FileCheck --check-prefix RELAX %s
14 # Fixups for %pcrel_hi / %pcrel_lo can be evaluated within a section,
15 # regardless of the fragment containing the target address, provided symbol
16 # binding allows it.
18 function:
19 .Lpcrel_label1:
20 auipc a0, %pcrel_hi(local_function)
21 addi a1, a0, %pcrel_lo(.Lpcrel_label1)
22 # NORELAX: auipc a0, 0
23 # NORELAX-NOT: R_RISCV
24 # NORELAX: addi a1, a0, 16
25 # NORELAX-NOT: R_RISCV
27 # RELAX: auipc a0, 0
28 # RELAX: R_RISCV_PCREL_HI20 local_function
29 # RELAX: R_RISCV_RELAX *ABS*
30 # RELAX: addi a1, a0, 0
31 # RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label1
32 # RELAX: R_RISCV_RELAX *ABS*
34 .p2align 2 # Cause a new fragment be emitted here
35 .Lpcrel_label2:
36 auipc a0, %pcrel_hi(local_function)
37 addi a1, a0, %pcrel_lo(.Lpcrel_label2)
38 # NORELAX: auipc a0, 0
39 # NORELAX-NOT: R_RISCV
40 # NORELAX: addi a1, a0, 8
41 # NORELAX-NOT: R_RISCV
43 # RELAX: auipc a0, 0
44 # RELAX: R_RISCV_PCREL_HI20 local_function
45 # RELAX: R_RISCV_RELAX *ABS*
46 # RELAX: addi a1, a0, 0
47 # RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label2
48 # RELAX: R_RISCV_RELAX *ABS*
50 .type local_function,@function
51 local_function:
52 ret
54 # Check we correctly evaluate when fixups are in different fragments
56 .Lpcrel_label3:
57 auipc a0, %pcrel_hi(local_function)
58 .p2align 2 # Cause a new fragment be emitted here
59 addi a1, a0, %pcrel_lo(.Lpcrel_label3)
60 # NORELAX: auipc a0, 0
61 # NORELAX-NOT: R_RISCV
62 # NORELAX: addi a1, a0, -4
63 # NORELAX-NOT: R_RISCV
65 # RELAX: auipc a0, 0
66 # RELAX: R_RISCV_PCREL_HI20 local_function
67 # RELAX: R_RISCV_RELAX *ABS*
68 # RELAX: addi a1, a0, 0
69 # RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label3
70 # RELAX: R_RISCV_RELAX *ABS*
72 # Check handling of symbol binding.
74 .Lpcrel_label4:
75 auipc a0, %pcrel_hi(global_function)
76 addi a1, a0, %pcrel_lo(.Lpcrel_label4)
77 # NORELAX: auipc a0, 0
78 # NORELAX: R_RISCV_PCREL_HI20 global_function
79 # NORELAX: addi a1, a0, 0
80 # NORELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label4
82 # RELAX: auipc a0, 0
83 # RELAX: R_RISCV_PCREL_HI20 global_function
84 # RELAX: R_RISCV_RELAX *ABS*
85 # RELAX: addi a1, a0, 0
86 # RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label4
87 # RELAX: R_RISCV_RELAX *ABS*
89 .Lpcrel_label5:
90 auipc a0, %pcrel_hi(weak_function)
91 addi a1, a0, %pcrel_lo(.Lpcrel_label5)
92 # NORELAX: auipc a0, 0
93 # NORELAX: R_RISCV_PCREL_HI20 weak_function
94 # NORELAX: addi a1, a0, 0
95 # NORELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label5
97 # RELAX: auipc a0, 0
98 # RELAX: R_RISCV_PCREL_HI20 weak_function
99 # RELAX: R_RISCV_RELAX *ABS*
100 # RELAX: addi a1, a0, 0
101 # RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label5
102 # RELAX: R_RISCV_RELAX *ABS*
104 .global global_function
105 .type global_function,@function
106 global_function:
109 .weak weak_function
110 .type weak_function,@function
111 weak_function: