1 ; RUN: opt -O2 %s | llvm-dis > %t1
2 ; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s
11 ; } __attribute__((preserve_access_index));
13 ; extern void output(ptr);
14 ; void test(struct info_t * args) {
15 ; int is_mask2 = args->flags & 0x10000;
16 ; struct data_t data = {};
18 ; data.d1 = is_mask2 ? 2 : args->pid;
19 ; data.d2 = (is_mask2 || (args->flags & 0x8000)) ? 1 : 2;
23 ; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c
27 %struct.info_t = type { i32, i32 }
28 %struct.data_t = type { i32, i32 }
30 ; Function Attrs: nounwind
31 define dso_local void @test(ptr readonly %args) local_unnamed_addr #0 !dbg !12 {
33 %data = alloca i64, align 8
34 call void @llvm.dbg.value(metadata ptr %args, metadata !22, metadata !DIExpression()), !dbg !29
35 %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.info_ts(ptr elementtype(%struct.info_t) %args, i32 1, i32 1), !dbg !30, !llvm.preserve.access.index !16
36 %1 = load i32, ptr %0, align 4, !dbg !30, !tbaa !31
37 %and = and i32 %1, 65536, !dbg !36
38 call void @llvm.dbg.value(metadata i32 %and, metadata !23, metadata !DIExpression()), !dbg !29
39 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %data) #5, !dbg !37
40 call void @llvm.dbg.declare(metadata ptr %data, metadata !24, metadata !DIExpression()), !dbg !38
41 store i64 0, ptr %data, align 8, !dbg !38
42 %tobool = icmp eq i32 %and, 0, !dbg !39
43 br i1 %tobool, label %cond.false, label %lor.end.critedge, !dbg !39
45 cond.false: ; preds = %entry
46 %2 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.info_ts(ptr elementtype(%struct.info_t) %args, i32 0, i32 0), !dbg !40, !llvm.preserve.access.index !16
47 %3 = load i32, ptr %2, align 4, !dbg !40, !tbaa !41
48 store i32 %3, ptr %data, align 8, !dbg !43, !tbaa !44
49 %4 = load i32, ptr %0, align 4, !dbg !46, !tbaa !31
50 %and2 = and i32 %4, 32768, !dbg !47
51 %tobool3 = icmp eq i32 %and2, 0, !dbg !48
52 %phitmp = select i1 %tobool3, i32 2, i32 1, !dbg !48
53 br label %lor.end, !dbg !48
55 lor.end.critedge: ; preds = %entry
56 store i32 2, ptr %data, align 8, !dbg !43, !tbaa !44
57 br label %lor.end, !dbg !48
59 lor.end: ; preds = %lor.end.critedge, %cond.false
60 %5 = phi i32 [ %phitmp, %cond.false ], [ 1, %lor.end.critedge ]
61 %d2 = getelementptr inbounds %struct.data_t, ptr %data, i64 0, i32 1, !dbg !49
62 store i32 %5, ptr %d2, align 4, !dbg !50, !tbaa !51
63 call void @output(ptr nonnull %data) #5, !dbg !52
64 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %data) #5, !dbg !53
68 ; CHECK: r[[LOAD:[0-9]+]] = *(u32 *)(r{{[0-9]+}} + 4)
69 ; CHECK: r[[COPY:[0-9]+]] = r[[LOAD]]
70 ; CHECK: r[[COPY]] &= 65536
71 ; CHECK: r[[LOAD]] &= 32768
73 ; Function Attrs: nounwind readnone speculatable willreturn
74 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
76 ; Function Attrs: argmemonly nounwind willreturn
77 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
79 ; Function Attrs: nounwind readnone
80 declare ptr @llvm.preserve.struct.access.index.p0.p0.info_ts(ptr, i32 immarg, i32 immarg) #3
82 declare !dbg !4 dso_local void @output(ptr) local_unnamed_addr #4
84 ; Function Attrs: argmemonly nounwind willreturn
85 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
87 ; Function Attrs: nounwind readnone speculatable willreturn
88 declare void @llvm.dbg.value(metadata, metadata, metadata) #1
90 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "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" }
91 attributes #1 = { nounwind readnone speculatable willreturn }
92 attributes #2 = { argmemonly nounwind willreturn }
93 attributes #3 = { nounwind readnone }
94 attributes #4 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "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" }
95 attributes #5 = { nounwind }
98 !llvm.module.flags = !{!8, !9, !10}
101 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 5884aae58f56786475bbc0f13ad8bd35f7f1ce69)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None)
102 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
105 !4 = !DISubprogram(name: "output", scope: !1, file: !1, line: 10, type: !5, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
106 !5 = !DISubroutineType(types: !6)
108 !7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
109 !8 = !{i32 7, !"Dwarf Version", i32 4}
110 !9 = !{i32 2, !"Debug Info Version", i32 3}
111 !10 = !{i32 1, !"wchar_size", i32 4}
112 !11 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 5884aae58f56786475bbc0f13ad8bd35f7f1ce69)"}
113 !12 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 11, type: !13, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !21)
114 !13 = !DISubroutineType(types: !14)
116 !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
117 !16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "info_t", file: !1, line: 5, size: 64, elements: !17)
119 !18 = !DIDerivedType(tag: DW_TAG_member, name: "pid", scope: !16, file: !1, line: 6, baseType: !19, size: 32)
120 !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
121 !20 = !DIDerivedType(tag: DW_TAG_member, name: "flags", scope: !16, file: !1, line: 7, baseType: !19, size: 32, offset: 32)
122 !21 = !{!22, !23, !24}
123 !22 = !DILocalVariable(name: "args", arg: 1, scope: !12, file: !1, line: 11, type: !15)
124 !23 = !DILocalVariable(name: "is_mask2", scope: !12, file: !1, line: 12, type: !19)
125 !24 = !DILocalVariable(name: "data", scope: !12, file: !1, line: 13, type: !25)
126 !25 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "data_t", file: !1, line: 1, size: 64, elements: !26)
128 !27 = !DIDerivedType(tag: DW_TAG_member, name: "d1", scope: !25, file: !1, line: 2, baseType: !19, size: 32)
129 !28 = !DIDerivedType(tag: DW_TAG_member, name: "d2", scope: !25, file: !1, line: 3, baseType: !19, size: 32, offset: 32)
130 !29 = !DILocation(line: 0, scope: !12)
131 !30 = !DILocation(line: 12, column: 24, scope: !12)
132 !31 = !{!32, !33, i64 4}
133 !32 = !{!"info_t", !33, i64 0, !33, i64 4}
134 !33 = !{!"int", !34, i64 0}
135 !34 = !{!"omnipotent char", !35, i64 0}
136 !35 = !{!"Simple C/C++ TBAA"}
137 !36 = !DILocation(line: 12, column: 30, scope: !12)
138 !37 = !DILocation(line: 13, column: 3, scope: !12)
139 !38 = !DILocation(line: 13, column: 17, scope: !12)
140 !39 = !DILocation(line: 15, column: 13, scope: !12)
141 !40 = !DILocation(line: 15, column: 34, scope: !12)
142 !41 = !{!32, !33, i64 0}
143 !42 = !DILocation(line: 15, column: 8, scope: !12)
144 !43 = !DILocation(line: 15, column: 11, scope: !12)
145 !44 = !{!45, !33, i64 0}
146 !45 = !{!"data_t", !33, i64 0, !33, i64 4}
147 !46 = !DILocation(line: 16, column: 33, scope: !12)
148 !47 = !DILocation(line: 16, column: 39, scope: !12)
149 !48 = !DILocation(line: 16, column: 23, scope: !12)
150 !49 = !DILocation(line: 16, column: 8, scope: !12)
151 !50 = !DILocation(line: 16, column: 11, scope: !12)
152 !51 = !{!45, !33, i64 4}
153 !52 = !DILocation(line: 17, column: 3, scope: !12)
154 !53 = !DILocation(line: 18, column: 1, scope: !12)