1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2 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. 6 7; RUN: opt -passes="ipsccp<func-spec>" -force-specialization -funcspec-for-literal-constant=false -S < %s | FileCheck %s 8 9%struct = type { i8, i16, i32, i64, i64} 10@Global = internal constant %struct {i8 0, i16 1, i32 2, i64 3, i64 4} 11 12define internal i64 @func2(ptr %x) { 13entry: 14 %val = ptrtoint ptr %x to i64 15 ret i64 %val 16} 17 18define internal i64 @func(ptr %x, ptr %binop) { 19; CHECK-LABEL: @func( 20; CHECK-NEXT: entry: 21; CHECK-NEXT: unreachable 22; 23entry: 24 %tmp0 = call i64 %binop(ptr %x) 25 ret i64 %tmp0 26} 27 28define internal i64 @zoo(i1 %flag) { 29; CHECK-LABEL: @zoo( 30; CHECK-NEXT: entry: 31; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]] 32; CHECK: plus: 33; CHECK-NEXT: [[TMP0:%.*]] = call i64 @func2.specialized.2(ptr getelementptr inbounds nuw (i8, ptr @Global, i64 8)) 34; CHECK-NEXT: br label [[MERGE:%.*]] 35; CHECK: minus: 36; CHECK-NEXT: [[TMP1:%.*]] = call i64 @func2.specialized.1(ptr getelementptr inbounds nuw (i8, ptr @Global, i64 16)) 37; CHECK-NEXT: br label [[MERGE]] 38; CHECK: merge: 39; CHECK-NEXT: [[TMP2:%.*]] = phi i64 [ ptrtoint (ptr getelementptr inbounds nuw (i8, ptr @Global, i64 8) to i64), [[PLUS]] ], [ ptrtoint (ptr getelementptr inbounds nuw (i8, ptr @Global, i64 16) to i64), [[MINUS]] ] 40; CHECK-NEXT: ret i64 [[TMP2]] 41; 42entry: 43 br i1 %flag, label %plus, label %minus 44 45plus: 46 %arg = getelementptr %struct, ptr @Global, i32 0, i32 3 47 %tmp0 = call i64 @func2(ptr %arg) 48 br label %merge 49 50minus: 51 %arg2 = getelementptr %struct, ptr @Global, i32 0, i32 4 52 %tmp1 = call i64 @func2(ptr %arg2) 53 br label %merge 54 55merge: 56 %tmp2 = phi i64 [ %tmp0, %plus ], [ %tmp1, %minus] 57 ret i64 %tmp2 58} 59 60 61define i64 @main() { 62; CHECK-LABEL: @main( 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]] 67; 68 %1 = call i64 @zoo(i1 0) 69 %2 = call i64 @zoo(i1 1) 70 %3 = add i64 %1, %2 71 ret i64 %3 72} 73 74