Skip to content

Commit 3acb709

Browse files
authored
[LoongArch][NFC] Add tests for fixing missed addsub relocs when enabling relax (#154108)
1 parent ee7a6a4 commit 3acb709

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
; RUN: llc --filetype=obj --mtriple=loongarch64 %s -o %t.o
2+
; RUN: llvm-readobj -r %t.o | FileCheck %s
3+
; RUN: llc --filetype=obj --mtriple=loongarch64 --mattr=+relax %s -o %t.r
4+
; RUN: llvm-readobj -r %t.r | FileCheck --check-prefixes=CHECK,RELAX %s
5+
6+
;; This test shows the loss of ADD/SUB relocations because relax feature
7+
;; is not available from SubtargetInfo (LoongArchAsmBackend is instantiated
8+
;; too early). ie. code generation takes the relax feature from attributes,
9+
;; but ADD/SUB relocations recording losses the relax feature.
10+
;; A later commit will fix it.
11+
12+
; CHECK: Relocations [
13+
; CHECK-NEXT: Section ({{.*}}) .rela.text {
14+
; CHECK-NEXT: 0x14 R_LARCH_PCALA_HI20 sym 0x0
15+
; CHECK-NEXT: 0x14 R_LARCH_RELAX - 0x0
16+
; CHECK-NEXT: 0x18 R_LARCH_PCALA_LO12 sym 0x0
17+
; CHECK-NEXT: 0x18 R_LARCH_RELAX - 0x0
18+
; CHECK-NEXT: }
19+
; CHECK-NEXT: Section ({{.*}}) .rela.debug_info {
20+
; CHECK-NEXT: 0x8 R_LARCH_32 .debug_abbrev 0x0
21+
; CHECK-NEXT: 0x11 R_LARCH_32 .L0 0x0
22+
; CHECK-NEXT: 0x15 R_LARCH_32 .Lline_table_start0 0x0
23+
; RELAX-NEXT: 0x1B R_LARCH_ADD32 .L0 0x0
24+
; RELAX-NEXT: 0x1B R_LARCH_SUB32 .L0 0x0
25+
; CHECK-NEXT: 0x1F R_LARCH_32 .L0 0x0
26+
; RELAX-NEXT: 0x25 R_LARCH_ADD32 .L0 0x0
27+
; RELAX-NEXT: 0x25 R_LARCH_SUB32 .L0 0x0
28+
; CHECK-NEXT: }
29+
; CHECK: Section ({{.*}}) .rela.debug_frame {
30+
; CHECK-NEXT: 0x1C R_LARCH_32 .L0 0x0
31+
; CHECK-NEXT: 0x20 R_LARCH_64 .L0 0x0
32+
; RELAX-NEXT: 0x28 R_LARCH_ADD64 .L0 0x0
33+
; RELAX-NEXT: 0x28 R_LARCH_SUB64 .L0 0x0
34+
; CHECK-NEXT: 0x3F R_LARCH_ADD6 .L0 0x0
35+
; CHECK-NEXT: 0x3F R_LARCH_SUB6 .L0 0x0
36+
; CHECK-NEXT: }
37+
; CHECK-NEXT: Section ({{.*}}) .rela.debug_line {
38+
; CHECK-NEXT: 0x22 R_LARCH_32 .debug_line_str 0x0
39+
; CHECK-NEXT: 0x31 R_LARCH_32 .debug_line_str 0x2
40+
; CHECK-NEXT: 0x46 R_LARCH_32 .debug_line_str 0x9
41+
; CHECK-NEXT: 0x4F R_LARCH_64 .L0 0x0
42+
; RELAX-NEXT: 0x5F R_LARCH_ADD16 .L0 0x0
43+
; RELAX-NEXT: 0x5F R_LARCH_SUB16 .L0 0x0
44+
; CHECK-NEXT: }
45+
; CHECK-NEXT: ]
46+
47+
; ModuleID = 'test.c'
48+
source_filename = "test.c"
49+
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
50+
target triple = "loongarch64"
51+
52+
; Function Attrs: noinline nounwind optnone
53+
define dso_local signext i32 @foo() #0 !dbg !8 {
54+
call void asm sideeffect ".cfi_remember_state\0A\09.cfi_adjust_cfa_offset 16\0A\09nop\0A\09la.pcrel $$t0, sym\0A\09nop\0A\09.cfi_restore_state\0A\09", ""() #1, !dbg !12, !srcloc !13
55+
ret i32 0, !dbg !14
56+
}
57+
58+
attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="loongarch64" "target-features"="+64bit,+d,+f,+ual,+relax" }
59+
attributes #1 = { nounwind }
60+
61+
!llvm.dbg.cu = !{!0}
62+
!llvm.module.flags = !{!2, !3, !4, !5, !6}
63+
!llvm.ident = !{!7}
64+
65+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
66+
!1 = !DIFile(filename: "test.c", directory: ".", checksumkind: CSK_MD5, checksum: "f44d6d71bc4da58b4abe338ca507c007", source: "int foo()\0A{\0A asm volatile(\0A \22.cfi_remember_state\\n\\t\22\0A \22.cfi_adjust_cfa_offset 16\\n\\t\22\0A \22nop\\n\\t\22\0A \22la.pcrel $t0, sym\\n\\t\22\0A \22nop\\n\\t\22\0A \22.cfi_restore_state\\n\\t\22);\0A return 0;\0A}\0A")
67+
!2 = !{i32 7, !"Dwarf Version", i32 5}
68+
!3 = !{i32 2, !"Debug Info Version", i32 3}
69+
!4 = !{i32 1, !"wchar_size", i32 4}
70+
!5 = !{i32 7, !"direct-access-external-data", i32 0}
71+
!6 = !{i32 7, !"frame-pointer", i32 2}
72+
!7 = !{!"clang"}
73+
!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !9, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0)
74+
!9 = !DISubroutineType(types: !10)
75+
!10 = !{!11}
76+
!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
77+
!12 = !DILocation(line: 3, column: 3, scope: !8)
78+
!13 = !{i64 34, i64 56, i64 92, i64 106, i64 134, i64 148, i64 177}
79+
!14 = !DILocation(line: 10, column: 3, scope: !8)

0 commit comments

Comments
 (0)