1 ; RUN: opt -O2 -march=bpfeb < %s | llvm-dis | FileCheck %s
2 ; RUN: opt -O2 -march=bpfel < %s | llvm-dis | FileCheck %s
5 ; #define _(x) (__builtin_preserve_access_index(x))
6 ; int get_value(const int *arg);
7 ; int test(int b, int *arg) {
8 ; int v1 = b ? get_value(_(&arg[4])) : 0;
9 ; int v2 = b ? get_value(_(&arg[4])) : 0;
13 ; clang -target bpf -O0 -g -S -emit-llvm -Xclang -disable-O0-optnone test.c
15 ; Function Attrs: noinline nounwind
16 define dso_local i32 @test(i32 %b, i32* %arg) #0 !dbg !10 {
18 %b.addr = alloca i32, align 4
19 %arg.addr = alloca i32*, align 8
20 %v1 = alloca i32, align 4
21 %v2 = alloca i32, align 4
22 store i32 %b, i32* %b.addr, align 4
23 call void @llvm.dbg.declare(metadata i32* %b.addr, metadata !13, metadata !DIExpression()), !dbg !14
24 store i32* %arg, i32** %arg.addr, align 8
25 call void @llvm.dbg.declare(metadata i32** %arg.addr, metadata !15, metadata !DIExpression()), !dbg !16
26 call void @llvm.dbg.declare(metadata i32* %v1, metadata !17, metadata !DIExpression()), !dbg !18
27 %0 = load i32, i32* %b.addr, align 4, !dbg !19
28 %tobool = icmp ne i32 %0, 0, !dbg !19
29 br i1 %tobool, label %cond.true, label %cond.false, !dbg !19
31 cond.true: ; preds = %entry
32 %1 = load i32*, i32** %arg.addr, align 8, !dbg !20
33 %2 = call i32* @llvm.preserve.array.access.index.p0i32.p0i32(i32* %1, i32 0, i32 4), !dbg !20, !llvm.preserve.access.index !4
34 %3 = bitcast i32* %2 to i8*, !dbg !20
35 %4 = bitcast i8* %3 to i32*, !dbg !20
36 %call = call i32 @get_value(i32* %4), !dbg !21
37 br label %cond.end, !dbg !19
39 cond.false: ; preds = %entry
40 br label %cond.end, !dbg !19
42 cond.end: ; preds = %cond.false, %cond.true
43 %cond = phi i32 [ %call, %cond.true ], [ 0, %cond.false ], !dbg !19
44 store i32 %cond, i32* %v1, align 4, !dbg !18
45 call void @llvm.dbg.declare(metadata i32* %v2, metadata !22, metadata !DIExpression()), !dbg !23
46 %5 = load i32, i32* %b.addr, align 4, !dbg !24
47 %tobool1 = icmp ne i32 %5, 0, !dbg !24
48 br i1 %tobool1, label %cond.true2, label %cond.false4, !dbg !24
50 cond.true2: ; preds = %cond.end
51 %6 = load i32*, i32** %arg.addr, align 8, !dbg !25
52 %7 = call i32* @llvm.preserve.array.access.index.p0i32.p0i32(i32* %6, i32 0, i32 4), !dbg !25, !llvm.preserve.access.index !4
53 %8 = bitcast i32* %7 to i8*, !dbg !25
54 %9 = bitcast i8* %8 to i32*, !dbg !25
55 %call3 = call i32 @get_value(i32* %9), !dbg !26
56 br label %cond.end5, !dbg !24
58 ; CHECK: tail call i32* @llvm.preserve.array.access.index.p0i32.p0i32(i32* %{{[0-9a-z]+}}, i32 0, i32 4), !dbg !{{[0-9]+}}, !llvm.preserve.access.index !{{[0-9]+}}
59 ; CHECK-NOT: tail call i32* @llvm.preserve.array.access.index
61 cond.false4: ; preds = %cond.end
62 br label %cond.end5, !dbg !24
64 cond.end5: ; preds = %cond.false4, %cond.true2
65 %cond6 = phi i32 [ %call3, %cond.true2 ], [ 0, %cond.false4 ], !dbg !24
66 store i32 %cond6, i32* %v2, align 4, !dbg !23
67 %10 = load i32, i32* %v1, align 4, !dbg !27
68 %11 = load i32, i32* %v2, align 4, !dbg !28
69 %add = add nsw i32 %10, %11, !dbg !29
70 ret i32 %add, !dbg !30
73 ; Function Attrs: nounwind readnone speculatable willreturn
74 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
76 declare dso_local i32 @get_value(i32*) #2
78 ; Function Attrs: nounwind readnone
79 declare i32* @llvm.preserve.array.access.index.p0i32.p0i32(i32*, i32 immarg, i32 immarg) #3
81 attributes #0 = { noinline 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" }
82 attributes #1 = { nounwind readnone speculatable willreturn }
83 attributes #2 = { "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" }
84 attributes #3 = { nounwind readnone }
87 !llvm.module.flags = !{!6, !7, !8}
90 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 4618b07fe2cede1b73512d1c260cf4981661f47f)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
91 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/cast")
94 !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
95 !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
96 !6 = !{i32 2, !"Dwarf Version", i32 4}
97 !7 = !{i32 2, !"Debug Info Version", i32 3}
98 !8 = !{i32 1, !"wchar_size", i32 4}
99 !9 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 4618b07fe2cede1b73512d1c260cf4981661f47f)"}
100 !10 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, type: !11, scopeLine: 3, flags: DIFlagPrototyped, isDefinition: true, unit: !0, retainedNodes: !2)
101 !11 = !DISubroutineType(types: !12)
103 !13 = !DILocalVariable(name: "b", arg: 1, scope: !10, file: !1, line: 3, type: !5)
104 !14 = !DILocation(line: 3, column: 14, scope: !10)
105 !15 = !DILocalVariable(name: "arg", arg: 2, scope: !10, file: !1, line: 3, type: !4)
106 !16 = !DILocation(line: 3, column: 22, scope: !10)
107 !17 = !DILocalVariable(name: "v1", scope: !10, file: !1, line: 4, type: !5)
108 !18 = !DILocation(line: 4, column: 7, scope: !10)
109 !19 = !DILocation(line: 4, column: 12, scope: !10)
110 !20 = !DILocation(line: 4, column: 26, scope: !10)
111 !21 = !DILocation(line: 4, column: 16, scope: !10)
112 !22 = !DILocalVariable(name: "v2", scope: !10, file: !1, line: 5, type: !5)
113 !23 = !DILocation(line: 5, column: 7, scope: !10)
114 !24 = !DILocation(line: 5, column: 12, scope: !10)
115 !25 = !DILocation(line: 5, column: 26, scope: !10)
116 !26 = !DILocation(line: 5, column: 16, scope: !10)
117 !27 = !DILocation(line: 6, column: 10, scope: !10)
118 !28 = !DILocation(line: 6, column: 15, scope: !10)
119 !29 = !DILocation(line: 6, column: 13, scope: !10)
120 !30 = !DILocation(line: 6, column: 3, scope: !10)