[llvm] [ARM] support -mlong-calls -fPIC on arm32 #39970 (PR #147313)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 08:55:54 PDT 2026


================
@@ -47,3 +130,127 @@ entry:
 declare void @callee0()
 
 attributes #0 = { "target-features"="+long-calls" }
+
+define dso_local void @global_func() {
+; NO-OPTION-LABEL: global_func:
+; NO-OPTION:       @ %bb.0: @ %entry
+; NO-OPTION-NEXT:    bx lr
+;
+; LONGCALL-LABEL: global_func:
+; LONGCALL:       @ %bb.0: @ %entry
+; LONGCALL-NEXT:    bx lr
+;
+; NO-LONGCALL-LABEL: global_func:
+; NO-LONGCALL:       @ %bb.0: @ %entry
+; NO-LONGCALL-NEXT:    bx lr
+;
+; XO-LONGCALL-LABEL: global_func:
+; XO-LONGCALL:       @ %bb.0: @ %entry
+; XO-LONGCALL-NEXT:    bx lr
+entry:
+  ret void
+}
+
+define void @test_global() {
+; NO-OPTION-LABEL: test_global:
+; NO-OPTION:       @ %bb.0: @ %entry
+; NO-OPTION-NEXT:    push {r7, lr}
+; NO-OPTION-NEXT:    bl global_func
+; NO-OPTION-NEXT:    pop {r7, pc}
+;
+; LONGCALL-LABEL: test_global:
+; LONGCALL:       @ %bb.0: @ %entry
+; LONGCALL-NEXT:    push {r7, lr}
+; LONGCALL-NEXT:    ldr r0, .LCPI3_0
+; LONGCALL-NEXT:    blx r0
+; LONGCALL-NEXT:    pop {r7, pc}
+; LONGCALL-NEXT:    .p2align 2
+; LONGCALL-NEXT:  @ %bb.1:
+; LONGCALL-NEXT:  .LCPI3_0:
+; LONGCALL-NEXT:    .long global_func
+;
+; NO-LONGCALL-LABEL: test_global:
+; NO-LONGCALL:       @ %bb.0: @ %entry
+; NO-LONGCALL-NEXT:    push {r7, lr}
+; NO-LONGCALL-NEXT:    bl global_func
+; NO-LONGCALL-NEXT:    pop {r7, pc}
+;
+; XO-LONGCALL-LABEL: test_global:
+; XO-LONGCALL:       @ %bb.0: @ %entry
+; XO-LONGCALL-NEXT:    .save {r11, lr}
+; XO-LONGCALL-NEXT:    push {r11, lr}
+; XO-LONGCALL-NEXT:    movw r0, :lower16:global_func
+; XO-LONGCALL-NEXT:    movt r0, :upper16:global_func
+; XO-LONGCALL-NEXT:    blx r0
+; XO-LONGCALL-NEXT:    pop {r11, pc}
+;
+; PIC-LONGCALL-LABEL: test_global:
+; PIC-LONGCALL:       @ %bb.0: @ %entry
+; PIC-LONGCALL-NEXT:    .save {r11, lr}
+; PIC-LONGCALL-NEXT:    push {r11, lr}
+; PIC-LONGCALL-NEXT:    ldr r0, .LCPI3_0
+; PIC-LONGCALL-NEXT:  .LPC3_0:
+; PIC-LONGCALL-NEXT:    add r0, pc, r0
+; PIC-LONGCALL-NEXT:    blx r0
+; PIC-LONGCALL-NEXT:    pop {r11, pc}
+; PIC-LONGCALL-NEXT:    .p2align 2
+; PIC-LONGCALL-NEXT:  @ %bb.1:
+; PIC-LONGCALL-NEXT:  .LCPI3_0:
+; PIC-LONGCALL-NEXT:    .long .Lglobal_func$local-(.LPC3_0+8)
+entry:
+  call void @global_func()
+  ret void
+}
+
+declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg)
+
+define void @test_memset(ptr %dst, i8 %val, i32 %len) {
+; NO-OPTION-LABEL: test_memset:
+; NO-OPTION:       @ %bb.0: @ %entry
+; NO-OPTION-NEXT:    push {r7, lr}
+; NO-OPTION-NEXT:    bl memset
+; NO-OPTION-NEXT:    pop {r7, pc}
+;
+; LONGCALL-LABEL: test_memset:
+; LONGCALL:       @ %bb.0: @ %entry
+; LONGCALL-NEXT:    push {r7, lr}
+; LONGCALL-NEXT:    ldr r3, .LCPI4_0
+; LONGCALL-NEXT:    blx r3
+; LONGCALL-NEXT:    pop {r7, pc}
+; LONGCALL-NEXT:    .p2align 2
+; LONGCALL-NEXT:  @ %bb.1:
+; LONGCALL-NEXT:  .LCPI4_0:
+; LONGCALL-NEXT:    .long memset
+;
+; NO-LONGCALL-LABEL: test_memset:
+; NO-LONGCALL:       @ %bb.0: @ %entry
+; NO-LONGCALL-NEXT:    push {r7, lr}
+; NO-LONGCALL-NEXT:    bl memset
+; NO-LONGCALL-NEXT:    pop {r7, pc}
+;
+; XO-LONGCALL-LABEL: test_memset:
+; XO-LONGCALL:       @ %bb.0: @ %entry
+; XO-LONGCALL-NEXT:    .save {r11, lr}
+; XO-LONGCALL-NEXT:    push {r11, lr}
+; XO-LONGCALL-NEXT:    movw r3, :lower16:memset
+; XO-LONGCALL-NEXT:    movt r3, :upper16:memset
+; XO-LONGCALL-NEXT:    blx r3
+; XO-LONGCALL-NEXT:    pop {r11, pc}
+;
+; PIC-LONGCALL-LABEL: test_memset:
+; PIC-LONGCALL:       @ %bb.0: @ %entry
+; PIC-LONGCALL-NEXT:    .save {r11, lr}
+; PIC-LONGCALL-NEXT:    push {r11, lr}
+; PIC-LONGCALL-NEXT:    ldr r3, .LCPI4_0
+; PIC-LONGCALL-NEXT:  .LPC4_0:
+; PIC-LONGCALL-NEXT:    ldr r3, [pc, r3]
+; PIC-LONGCALL-NEXT:    blx r3
+; PIC-LONGCALL-NEXT:    pop {r11, pc}
+; PIC-LONGCALL-NEXT:    .p2align 2
+; PIC-LONGCALL-NEXT:  @ %bb.1:
+; PIC-LONGCALL-NEXT:  .LCPI4_0:
+; PIC-LONGCALL-NEXT:    .long memset(GOT_PREL)
----------------
jxz-hw wrote:

Thanks, I fixed it. Now the external symbol and global address both use the same GOT_PREL form.



https://github.com/llvm/llvm-project/pull/147313


More information about the llvm-commits mailing list