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