xref: /llvm-project/llvm/test/CodeGen/BPF/CORE/intrinsic-union.ll (revision 60228733726e25d011b1f9221e005732191cc077)
1; RUN: opt -O2 %s | llvm-dis > %t1
2; RUN: llc -filetype=asm -o - %t1 | FileCheck %s
3; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck %s
4;
5; Source code:
6;   union u { int a; int b; };
7;   #define _(x) (__builtin_preserve_access_index(x))
8;   int get_value(const ptr addr);
9;   int test(union u *arg) { return get_value(_(&arg->b)); }
10; Compiler flag to generate IR:
11;   clang -target bpf -S -O2 -g -emit-llvm -Xclang -disable-llvm-passes test.c
12
13target triple = "bpf"
14
15%union.u = type { i32 }
16
17; Function Attrs: nounwind
18define dso_local i32 @test(ptr %arg) local_unnamed_addr #0 !dbg !7 {
19entry:
20  call void @llvm.dbg.value(metadata ptr %arg, metadata !17, metadata !DIExpression()), !dbg !18
21  %0 = tail call ptr @llvm.preserve.union.access.index.p0.us.p0.us(ptr %arg, i32 1), !dbg !19, !llvm.preserve.access.index !12
22  %call = tail call i32 @get_value(ptr %0) #4, !dbg !20
23  ret i32 %call, !dbg !21
24}
25; CHECK-LABEL: test
26; CHECK:       [[RELOC:.Ltmp[0-9]+]]
27; CHECK:       r2 = 0
28; CHECK:       r1 += r2
29; CHECK:       call get_value
30; CHECK:       exit
31
32; CHECK:      .section        .BTF.ext,"",@progbits
33; CHECK:      .long   16                      # FieldReloc
34; CHECK-NEXT: .long   20                      # Field reloc section string offset=20
35; CHECK-NEXT: .long   1
36; CHECK-NEXT: .long   [[RELOC]]
37; CHECK-NEXT: .long   2
38; CHECK-NEXT: .long   26
39; CHECK-NEXT: .long   0
40
41declare dso_local i32 @get_value(ptr) local_unnamed_addr #1
42
43; Function Attrs: nounwind readnone
44declare ptr @llvm.preserve.union.access.index.p0.us.p0.us(ptr, i32 immarg) #2
45
46; Function Attrs: nounwind readnone speculatable
47declare void @llvm.dbg.value(metadata, metadata, metadata) #3
48
49attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="all" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
50attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
51attributes #2 = { nounwind readnone }
52attributes #3 = { nounwind readnone speculatable }
53attributes #4 = { nounwind }
54
55!llvm.dbg.cu = !{!0}
56!llvm.module.flags = !{!3, !4, !5}
57!llvm.ident = !{!6}
58
59!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 365789)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
60!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
61!2 = !{}
62!3 = !{i32 2, !"Dwarf Version", i32 4}
63!4 = !{i32 2, !"Debug Info Version", i32 3}
64!5 = !{i32 1, !"wchar_size", i32 4}
65!6 = !{!"clang version 9.0.0 (trunk 365789)"}
66!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
67!8 = !DISubroutineType(types: !9)
68!9 = !{!10, !11}
69!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
70!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
71!12 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u", file: !1, line: 1, size: 32, elements: !13)
72!13 = !{!14, !15}
73!14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
74!15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
75!16 = !{!17}
76!17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 4, type: !11)
77!18 = !DILocation(line: 0, scope: !7)
78!19 = !DILocation(line: 4, column: 43, scope: !7)
79!20 = !DILocation(line: 4, column: 33, scope: !7)
80!21 = !DILocation(line: 4, column: 26, scope: !7)
81