148 lines · plain
1; RUN: opt -O2 %s | llvm-dis > %t12; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s3; Source code:4; struct data_t {5; int d1;6; int d2;7; };8; struct info_t {9; int pid;10; int flags;11; } __attribute__((preserve_access_index));12;13; extern void output(ptr);14; void test(struct info_t * args) {15; int is_mask2 = args->flags & 0x10000;16; struct data_t data = {};17;18; data.d1 = is_mask2 ? 2 : args->pid;19; data.d2 = (is_mask2 || (args->flags & 0x8000)) ? 1 : 2;20; output(&data);21; }22; Compilation flag:23; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c24 25target triple = "bpf"26 27%struct.info_t = type { i32, i32 }28%struct.data_t = type { i32, i32 }29 30; Function Attrs: nounwind31define dso_local void @test(ptr readonly %args) local_unnamed_addr !dbg !12 {32entry:33 %data = alloca i64, align 834 call void @llvm.dbg.value(metadata ptr %args, metadata !22, metadata !DIExpression()), !dbg !2935 %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 !1636 %1 = load i32, ptr %0, align 4, !dbg !30, !tbaa !3137 %and = and i32 %1, 65536, !dbg !3638 call void @llvm.dbg.value(metadata i32 %and, metadata !23, metadata !DIExpression()), !dbg !2939 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %data), !dbg !3740 call void @llvm.dbg.declare(metadata ptr %data, metadata !24, metadata !DIExpression()), !dbg !3841 store i64 0, ptr %data, align 8, !dbg !3842 %tobool = icmp eq i32 %and, 0, !dbg !3943 br i1 %tobool, label %cond.false, label %lor.end.critedge, !dbg !3944 45cond.false: ; preds = %entry46 %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 !1647 %3 = load i32, ptr %2, align 4, !dbg !40, !tbaa !4148 store i32 %3, ptr %data, align 8, !dbg !43, !tbaa !4449 %4 = load i32, ptr %0, align 4, !dbg !46, !tbaa !3150 %and2 = and i32 %4, 32768, !dbg !4751 %tobool3 = icmp eq i32 %and2, 0, !dbg !4852 %phitmp = select i1 %tobool3, i32 2, i32 1, !dbg !4853 br label %lor.end, !dbg !4854 55lor.end.critedge: ; preds = %entry56 store i32 2, ptr %data, align 8, !dbg !43, !tbaa !4457 br label %lor.end, !dbg !4858 59lor.end: ; preds = %lor.end.critedge, %cond.false60 %5 = phi i32 [ %phitmp, %cond.false ], [ 1, %lor.end.critedge ]61 %d2 = getelementptr inbounds %struct.data_t, ptr %data, i64 0, i32 1, !dbg !4962 store i32 %5, ptr %d2, align 4, !dbg !50, !tbaa !5163 call void @output(ptr nonnull %data), !dbg !5264 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %data), !dbg !5365 ret void, !dbg !5366}67 68; CHECK: r[[LOAD:[0-9]+]] = *(u32 *)(r{{[0-9]+}} + 4)69; CHECK: r[[COPY:[0-9]+]] = r[[LOAD]]70; CHECK: r[[COPY]] &= 6553671; CHECK: r[[LOAD]] &= 3276872 73; Function Attrs: nounwind readnone speculatable willreturn74declare void @llvm.dbg.declare(metadata, metadata, metadata)75 76; Function Attrs: argmemonly nounwind willreturn77declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)78 79; Function Attrs: nounwind readnone80declare ptr @llvm.preserve.struct.access.index.p0.p0.info_ts(ptr, i32 immarg, i32 immarg)81 82declare !dbg !4 dso_local void @output(ptr) local_unnamed_addr83 84; Function Attrs: argmemonly nounwind willreturn85declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)86 87; Function Attrs: nounwind readnone speculatable willreturn88declare void @llvm.dbg.value(metadata, metadata, metadata)89 90!llvm.dbg.cu = !{!0}91!llvm.module.flags = !{!8, !9, !10}92!llvm.ident = !{!11}93 94!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)95!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")96!2 = !{}97!3 = !{!4}98!4 = !DISubprogram(name: "output", scope: !1, file: !1, line: 10, type: !5, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)99!5 = !DISubroutineType(types: !6)100!6 = !{null, !7}101!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)102!8 = !{i32 7, !"Dwarf Version", i32 4}103!9 = !{i32 2, !"Debug Info Version", i32 3}104!10 = !{i32 1, !"wchar_size", i32 4}105!11 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 5884aae58f56786475bbc0f13ad8bd35f7f1ce69)"}106!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)107!13 = !DISubroutineType(types: !14)108!14 = !{null, !15}109!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)110!16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "info_t", file: !1, line: 5, size: 64, elements: !17)111!17 = !{!18, !20}112!18 = !DIDerivedType(tag: DW_TAG_member, name: "pid", scope: !16, file: !1, line: 6, baseType: !19, size: 32)113!19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)114!20 = !DIDerivedType(tag: DW_TAG_member, name: "flags", scope: !16, file: !1, line: 7, baseType: !19, size: 32, offset: 32)115!21 = !{!22, !23, !24}116!22 = !DILocalVariable(name: "args", arg: 1, scope: !12, file: !1, line: 11, type: !15)117!23 = !DILocalVariable(name: "is_mask2", scope: !12, file: !1, line: 12, type: !19)118!24 = !DILocalVariable(name: "data", scope: !12, file: !1, line: 13, type: !25)119!25 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "data_t", file: !1, line: 1, size: 64, elements: !26)120!26 = !{!27, !28}121!27 = !DIDerivedType(tag: DW_TAG_member, name: "d1", scope: !25, file: !1, line: 2, baseType: !19, size: 32)122!28 = !DIDerivedType(tag: DW_TAG_member, name: "d2", scope: !25, file: !1, line: 3, baseType: !19, size: 32, offset: 32)123!29 = !DILocation(line: 0, scope: !12)124!30 = !DILocation(line: 12, column: 24, scope: !12)125!31 = !{!32, !33, i64 4}126!32 = !{!"info_t", !33, i64 0, !33, i64 4}127!33 = !{!"int", !34, i64 0}128!34 = !{!"omnipotent char", !35, i64 0}129!35 = !{!"Simple C/C++ TBAA"}130!36 = !DILocation(line: 12, column: 30, scope: !12)131!37 = !DILocation(line: 13, column: 3, scope: !12)132!38 = !DILocation(line: 13, column: 17, scope: !12)133!39 = !DILocation(line: 15, column: 13, scope: !12)134!40 = !DILocation(line: 15, column: 34, scope: !12)135!41 = !{!32, !33, i64 0}136!42 = !DILocation(line: 15, column: 8, scope: !12)137!43 = !DILocation(line: 15, column: 11, scope: !12)138!44 = !{!45, !33, i64 0}139!45 = !{!"data_t", !33, i64 0, !33, i64 4}140!46 = !DILocation(line: 16, column: 33, scope: !12)141!47 = !DILocation(line: 16, column: 39, scope: !12)142!48 = !DILocation(line: 16, column: 23, scope: !12)143!49 = !DILocation(line: 16, column: 8, scope: !12)144!50 = !DILocation(line: 16, column: 11, scope: !12)145!51 = !{!45, !33, i64 4}146!52 = !DILocation(line: 17, column: 3, scope: !12)147!53 = !DILocation(line: 18, column: 1, scope: !12)148