|
| 1 | +; Note: Make sure that instrumention intrinsic is after entry alloca. |
| 2 | +; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s |
| 3 | +; RUN: opt < %s -passes=pgo-instr-gen,instrprof -sampled-instrumentation -S | FileCheck %s --check-prefixes=SAMPLE |
| 4 | + |
| 5 | +%struct.A = type { i32, [0 x i32] } |
| 6 | +%struct.B = type { i32, [0 x double] } |
| 7 | + |
| 8 | +; CHECK-LABEL: @foo() |
| 9 | +; CHECK-NEXT: %1 = alloca %struct.A |
| 10 | +; CHECK-NEXT: %2 = alloca %struct.B |
| 11 | +; CHECK-NEXT: call void @llvm.instrprof.increment(ptr @__profn_foo |
| 12 | + |
| 13 | +; SAMPLE: @foo() |
| 14 | +; SAMPLE-NEXT: %1 = alloca %struct.A |
| 15 | +; SAMPLE-NEXT: %2 = alloca %struct.B |
| 16 | +; SAMPLE-NEXT: %[[v:[0-9]+]] = load i16, ptr @__llvm_profile_sampling |
| 17 | +; SAMPLE-NEXT: {{.*}} = icmp ule i16 %[[v]], 199 |
| 18 | + |
| 19 | +define dso_local double @foo() { |
| 20 | + %1 = alloca %struct.A, align 4 |
| 21 | + %2 = alloca %struct.B, align 8 |
| 22 | + call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) |
| 23 | + call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) |
| 24 | + call void @bar(ptr noundef nonnull %1, ptr noundef nonnull %2) |
| 25 | + %3 = load i32, ptr %1, align 4 |
| 26 | + %4 = icmp sgt i32 %3, 0 |
| 27 | + br i1 %4, label %5, label %21 |
| 28 | + |
| 29 | +5: |
| 30 | + %6 = getelementptr inbounds i8, ptr %1, i64 4 |
| 31 | + %7 = getelementptr inbounds i8, ptr %2, i64 8 |
| 32 | + %8 = zext nneg i32 %3 to i64 |
| 33 | + br label %9 |
| 34 | + |
| 35 | +9: |
| 36 | + %10 = phi i64 [ 0, %5 ], [ %19, %9 ] |
| 37 | + %11 = phi double [ 0.000000e+00, %5 ], [ %18, %9 ] |
| 38 | + %12 = getelementptr inbounds [0 x i32], ptr %6, i64 0, i64 %10 |
| 39 | + %13 = load i32, ptr %12, align 4 |
| 40 | + %14 = sitofp i32 %13 to double |
| 41 | + %15 = getelementptr inbounds [0 x double], ptr %7, i64 0, i64 %10 |
| 42 | + %16 = load double, ptr %15, align 8 |
| 43 | + %17 = fadd double %16, %14 |
| 44 | + %18 = fadd double %11, %17 |
| 45 | + %19 = add nuw nsw i64 %10, 1 |
| 46 | + %20 = icmp eq i64 %19, %8 |
| 47 | + br i1 %20, label %21, label %9 |
| 48 | + |
| 49 | +21: |
| 50 | + %22 = phi double [ 0.000000e+00, %0 ], [ %18, %9 ] |
| 51 | + call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) |
| 52 | + call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) |
| 53 | + ret double %22 |
| 54 | +} |
| 55 | + |
| 56 | +declare void @bar(ptr noundef, ptr noundef) |
0 commit comments