1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt --bpf-ir-peephole -mtriple=bpf-pc-linux -S %s | FileCheck %s
12 ; char tmp[AA + sizeof(struct t) + a];
24 ; clang -target bpf -O2 -S -emit-llvm t.c -Xclang -disable-llvm-passes
26 source_filename = "t.c"
27 target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
30 ; Function Attrs: nounwind
31 define dso_local i32 @test1() {
32 ; CHECK-LABEL: @test1(
34 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
35 ; CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca ptr, align 8
36 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[A]])
37 ; CHECK-NEXT: store i32 8, ptr [[A]], align 4
38 ; CHECK-NEXT: [[VLA:%.*]] = alloca i8, i64 68, align 1
39 ; CHECK-NEXT: call void @foo(ptr [[VLA]])
40 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[A]])
41 ; CHECK-NEXT: ret i32 0
44 %a = alloca i32, align 4
45 %saved_stack = alloca ptr, align 8
46 call void @llvm.lifetime.start.p0(i64 4, ptr %a)
47 store i32 8, ptr %a, align 4
48 %0 = call ptr @llvm.stacksave()
49 store ptr %0, ptr %saved_stack, align 8
50 %vla = alloca i8, i64 68, align 1
51 call void @foo(ptr %vla)
52 %1 = load ptr, ptr %saved_stack, align 8
53 call void @llvm.stackrestore(ptr %1)
54 call void @llvm.lifetime.end.p0(i64 4, ptr %a)
58 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
60 declare ptr @llvm.stacksave()
62 declare dso_local void @foo(ptr)
64 declare void @llvm.stackrestore(ptr)
66 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
68 define dso_local i32 @test2(i32 %b) {
69 ; CHECK-LABEL: @test2(
71 ; CHECK-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
72 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
73 ; CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca ptr, align 8
74 ; CHECK-NEXT: [[__VLA_EXPR0:%.*]] = alloca i64, align 8
75 ; CHECK-NEXT: store i32 [[B:%.*]], ptr [[B_ADDR]], align 4
76 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[A]])
77 ; CHECK-NEXT: store i32 8, ptr [[A]], align 4
78 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[B_ADDR]], align 4
79 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 8, [[TMP1]]
80 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[ADD]] to i64
81 ; CHECK-NEXT: [[VLA:%.*]] = alloca i8, i64 [[TMP2]], align 1
82 ; CHECK-NEXT: store i64 [[TMP2]], ptr [[__VLA_EXPR0]], align 8
83 ; CHECK-NEXT: call void @foo(ptr [[VLA]])
84 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[A]])
85 ; CHECK-NEXT: ret i32 0
88 %b.addr = alloca i32, align 4
89 %a = alloca i32, align 4
90 %saved_stack = alloca ptr, align 8
91 %__vla_expr0 = alloca i64, align 8
92 store i32 %b, ptr %b.addr, align 4
93 call void @llvm.lifetime.start.p0(i64 4, ptr %a)
94 store i32 8, ptr %a, align 4
95 %0 = load i32, ptr %b.addr, align 4
96 %add = add nsw i32 8, %0
97 %1 = zext i32 %add to i64
98 %2 = call ptr @llvm.stacksave()
99 store ptr %2, ptr %saved_stack, align 8
100 %vla = alloca i8, i64 %1, align 1
101 store i64 %1, ptr %__vla_expr0, align 8
102 call void @foo(ptr %vla)
103 %3 = load ptr, ptr %saved_stack, align 8
104 call void @llvm.stackrestore(ptr %3)
105 call void @llvm.lifetime.end.p0(i64 4, ptr %a)