1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
2; RUN: opt -S -O3 -o - %s | FileCheck %s
3
4; PR44154: LLVM c3b06d0c393e caused the body of @main to be replaced with
5; unreachable. Check that we perform the expected calls and optimizations.
6
7target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8target triple = "x86_64-unknown-linux-gnu"
9
10define i32 @main(i32 %argc, i8** %argv) #0 {
11; CHECK-LABEL: define {{[^@]+}}@main
12; CHECK-SAME: (i32 [[ARGC:%.*]], i8** nocapture readnone [[ARGV:%.*]]) local_unnamed_addr #0
13; CHECK-NEXT:  entry:
14; CHECK-NEXT:    [[TMP0:%.*]] = icmp slt i32 [[ARGC]], 2
15; CHECK-NEXT:    [[SPEC_SELECT:%.*]] = select i1 [[TMP0]], i32 0, i32 [[ARGC]]
16; CHECK-NEXT:    ret i32 [[SPEC_SELECT]]
17;
18entry:
19  %0 = getelementptr inbounds i8*, i8** %argv, i32 0
20  %ptr = load i8*, i8** %0
21  %1 = call i32 @compute(i8* %ptr, i32 %argc)
22  %2 = icmp slt i32 %argc, 2
23  br i1 %2, label %done, label %do_work
24
25do_work:
26  %3 = icmp eq i8* %ptr, null
27  br i1 %3, label %null, label %done
28
29null:
30  call void @call_if_null(i8* %ptr)
31  br label %done
32
33done:
34  %retval = phi i32 [0, %entry], [%1, %do_work], [%1, %null]
35  ret i32 %retval
36}
37
38define i32 @compute(i8* nonnull %ptr, i32 %x) #1 {
39; CHECK-LABEL: define {{[^@]+}}@compute
40; CHECK-SAME: (i8* nocapture nonnull readnone [[PTR:%.*]], i32 returned [[X:%.*]]) local_unnamed_addr #1
41; CHECK-NEXT:    ret i32 [[X]]
42;
43  ret i32 %x
44}
45
46declare void @call_if_null(i8* %ptr) #0
47
48attributes #0 = { nounwind }
49attributes #1 = { noinline nounwind readonly }
50