1 ; RUN: opt -O2 -S -o %t1 < %s
2 ; RUN: llc -march=bpf -mcpu=v3 %t1 -o - | FileCheck %s
5 ; typedef unsigned long u64;
6 ; void foo(char *data, int idx, u64 *);
7 ; int test(int len, char *data) {
9 ; for (int i = 1; i < len; i++) {
11 ; d[0] = data[0] ?: '0';
18 ; clang -target bpf -O2 -S -emit-llvm -Xclang -disable-llvm-passes test.c
21 source_filename = "test.c"
22 target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
25 @.str = private unnamed_addr constant [3 x i8] c"%c\00", align 1
27 ; Function Attrs: nounwind
28 define dso_local i32 @test(i32 %len, ptr %data) #0 {
30 %len.addr = alloca i32, align 4
31 %data.addr = alloca ptr, align 8
32 %i = alloca i32, align 4
33 %d = alloca [1 x i64], align 8
34 store i32 %len, ptr %len.addr, align 4, !tbaa !3
35 store ptr %data, ptr %data.addr, align 8, !tbaa !7
36 %0 = load i32, ptr %len.addr, align 4, !tbaa !3
37 %cmp = icmp slt i32 %0, 100
38 br i1 %cmp, label %if.then, label %if.end
40 if.then: ; preds = %entry
41 call void @llvm.lifetime.start.p0(i64 4, ptr %i) #3
42 store i32 1, ptr %i, align 4, !tbaa !3
45 for.cond: ; preds = %for.inc, %if.then
46 %1 = load i32, ptr %i, align 4, !tbaa !3
47 %2 = load i32, ptr %len.addr, align 4, !tbaa !3
48 %cmp1 = icmp slt i32 %1, %2
49 br i1 %cmp1, label %for.body, label %for.cond.cleanup
51 ; CHECK: w[[LEN:[0-9]+]] = w1
52 ; CHECK: w[[IDX:[0-9]+]] += 1
53 ; CHECK-NEXT: w[[IDX]] s< w[[LEN]] goto
55 for.cond.cleanup: ; preds = %for.cond
56 call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3
59 for.body: ; preds = %for.cond
60 call void @llvm.lifetime.start.p0(i64 8, ptr %d) #3
61 %3 = load ptr, ptr %data.addr, align 8, !tbaa !7
62 %4 = load i8, ptr %3, align 1, !tbaa !9
63 %conv = sext i8 %4 to i32
64 %tobool = icmp ne i32 %conv, 0
65 br i1 %tobool, label %cond.true, label %cond.false
67 cond.true: ; preds = %for.body
70 cond.false: ; preds = %for.body
73 cond.end: ; preds = %cond.false, %cond.true
74 %cond = phi i32 [ %conv, %cond.true ], [ 48, %cond.false ]
75 %conv2 = sext i32 %cond to i64
76 store i64 %conv2, ptr %d, align 8, !tbaa !10
77 %5 = load i32, ptr %i, align 4, !tbaa !3
78 call void @foo(ptr @.str, i32 %5, ptr %d)
79 call void @llvm.lifetime.end.p0(i64 8, ptr %d) #3
82 for.inc: ; preds = %cond.end
83 %6 = load i32, ptr %i, align 4, !tbaa !3
84 %inc = add nsw i32 %6, 1
85 store i32 %inc, ptr %i, align 4, !tbaa !3
86 br label %for.cond, !llvm.loop !12
88 for.end: ; preds = %for.cond.cleanup
91 if.end: ; preds = %for.end, %entry
95 ; Function Attrs: argmemonly nofree nosync nounwind willreturn
96 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
98 declare dso_local void @foo(ptr, i32, ptr) #2
100 ; Function Attrs: argmemonly nofree nosync nounwind willreturn
101 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
103 attributes #0 = { nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
104 attributes #1 = { argmemonly nofree nosync nounwind willreturn }
105 attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
106 attributes #3 = { nounwind }
108 !llvm.module.flags = !{!0, !1}
111 !0 = !{i32 1, !"wchar_size", i32 4}
112 !1 = !{i32 7, !"frame-pointer", i32 2}
113 !2 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 8385de118443144518c9fba8b3d831d9076e746b)"}
114 !3 = !{!4, !4, i64 0}
115 !4 = !{!"int", !5, i64 0}
116 !5 = !{!"omnipotent char", !6, i64 0}
117 !6 = !{!"Simple C/C++ TBAA"}
118 !7 = !{!8, !8, i64 0}
119 !8 = !{!"any pointer", !5, i64 0}
120 !9 = !{!5, !5, i64 0}
121 !10 = !{!11, !11, i64 0}
122 !11 = !{!"long", !5, i64 0}
123 !12 = distinct !{!12, !13}
124 !13 = !{!"llvm.loop.mustprogress"}