1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
3 ; Test function specialization wouldn't crash due to constant expression.
4 ; Note that this test case shows that function specialization pass would
5 ; transform the function even if no specialization happened.
7 ; RUN: opt -passes="ipsccp<func-spec>" -force-specialization -S < %s | FileCheck %s
9 %struct = type { i8, i16, i32, i64, i64}
10 @Global = internal constant %struct {i8 0, i16 1, i32 2, i64 3, i64 4}
12 define internal i64 @func2(ptr %x) {
14 %val = ptrtoint ptr %x to i64
18 define internal i64 @func(ptr %x, ptr %binop) {
21 ; CHECK-NEXT: unreachable
24 %tmp0 = call i64 %binop(ptr %x)
28 define internal i64 @zoo(i1 %flag) {
31 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]]
33 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @func2.specialized.2(ptr getelementptr inbounds ([[STRUCT:%.*]], ptr @Global, i64 0, i32 3))
34 ; CHECK-NEXT: br label [[MERGE:%.*]]
36 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @func2.specialized.1(ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 4))
37 ; CHECK-NEXT: br label [[MERGE]]
39 ; CHECK-NEXT: [[TMP2:%.*]] = phi i64 [ ptrtoint (ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 3) to i64), [[PLUS]] ], [ ptrtoint (ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 4) to i64), [[MINUS]] ]
40 ; CHECK-NEXT: ret i64 [[TMP2]]
43 br i1 %flag, label %plus, label %minus
46 %arg = getelementptr %struct, ptr @Global, i32 0, i32 3
47 %tmp0 = call i64 @func2(ptr %arg)
51 %arg2 = getelementptr %struct, ptr @Global, i32 0, i32 4
52 %tmp1 = call i64 @func2(ptr %arg2)
56 %tmp2 = phi i64 [ %tmp0, %plus ], [ %tmp1, %minus]
63 ; CHECK-NEXT: [[TMP1:%.*]] = call i64 @zoo(i1 false)
64 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @zoo(i1 true)
65 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[TMP1]], [[TMP2]]
66 ; CHECK-NEXT: ret i64 [[TMP3]]
68 %1 = call i64 @zoo(i1 0)
69 %2 = call i64 @zoo(i1 1)