1*2556f581SChuanqi Xu; RUN: opt -function-specialization -func-specialization-avg-iters-cost=3 -func-specialization-size-threshold=10 -S < %s | FileCheck %s
286906304SChuanqi Xu
386906304SChuanqi Xu; Check that the loop depth results in a larger specialization bonus.
486906304SChuanqi Xu; CHECK: @foo.1(
586906304SChuanqi Xu; CHECK: @foo.2(
686906304SChuanqi Xu
786906304SChuanqi Xutarget datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
886906304SChuanqi Xu
986906304SChuanqi Xu@A = external dso_local constant i32, align 4
1086906304SChuanqi Xu@B = external dso_local constant i32, align 4
1186906304SChuanqi Xu@C = external dso_local constant i32, align 4
1286906304SChuanqi Xu@D = external dso_local constant i32, align 4
1386906304SChuanqi Xu
1486906304SChuanqi Xudeclare i1 @cond_begin()
1586906304SChuanqi Xudeclare i1 @cond_end()
1686906304SChuanqi Xudeclare i1 @getCond()
1786906304SChuanqi Xu
1886906304SChuanqi Xudefine internal i32 @foo(i32 %x, i32* %b, i32* %c) {
1986906304SChuanqi Xuentry:
2086906304SChuanqi Xu  br label %loop.entry
2186906304SChuanqi Xu
2286906304SChuanqi Xuloop.entry:
2386906304SChuanqi Xu  br label %loop2.entry
2486906304SChuanqi Xu
2586906304SChuanqi Xuloop2.entry:
2686906304SChuanqi Xu  br label %loop2.body
2786906304SChuanqi Xu
2886906304SChuanqi Xuloop2.body:
2986906304SChuanqi Xu  %0 = load i32, i32* %b, align 4
3086906304SChuanqi Xu  %1 = load i32, i32* %c, align 4
3186906304SChuanqi Xu  %add.0 = add nsw i32 %0, %1
3286906304SChuanqi Xu  %add = add nsw i32 %add.0, %x
3386906304SChuanqi Xu  br label %loop2.end
3486906304SChuanqi Xu
3586906304SChuanqi Xuloop2.end:
3686906304SChuanqi Xu  %cond.end = call i1 @cond_end()
3786906304SChuanqi Xu  br i1 %cond.end, label %loop2.entry, label %loop.end
3886906304SChuanqi Xu
3986906304SChuanqi Xuloop.end:
4086906304SChuanqi Xu  %cond2.end = call i1 @getCond()
4186906304SChuanqi Xu  br i1 %cond2.end, label %loop.entry, label %return
4286906304SChuanqi Xu
4386906304SChuanqi Xureturn:
4486906304SChuanqi Xu  ret i32 %add
4586906304SChuanqi Xu}
4686906304SChuanqi Xu
4786906304SChuanqi Xudefine dso_local i32 @bar(i32 %x, i32 %y) {
4886906304SChuanqi Xuentry:
4986906304SChuanqi Xu  %tobool = icmp ne i32 %x, 0
5086906304SChuanqi Xu  br i1 %tobool, label %if.then, label %if.else
5186906304SChuanqi Xu
5286906304SChuanqi Xuif.then:
5386906304SChuanqi Xu  %call = call i32 @foo(i32 %x, i32* @A, i32* @C)
5486906304SChuanqi Xu  br label %return
5586906304SChuanqi Xu
5686906304SChuanqi Xuif.else:
5786906304SChuanqi Xu  %call1 = call i32 @foo(i32 %y, i32* @B, i32* @D)
5886906304SChuanqi Xu  br label %return
5986906304SChuanqi Xu
6086906304SChuanqi Xureturn:
6186906304SChuanqi Xu  %retval.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
6286906304SChuanqi Xu  ret i32 %retval.0
6386906304SChuanqi Xu}