1; Test function specialization wouldn't crash due to constant expression. 2; Note that this test case shows that function specialization pass would 3; transform the function even if no specialization happened. 4; RUN: opt -function-specialization -S < %s | FileCheck %s 5 6; CHECK: plus: 7; CHECK-NEXT: %{{.*}} = call i64 @func2(i64* getelementptr inbounds (%struct, %struct* @Global, i32 0, i32 3)) 8; CHECK: minus: 9; CHECK-NEXT: %{{.*}} = call i64 @func2(i64* getelementptr inbounds (%struct, %struct* @Global, i32 0, i32 4)) 10 11%struct = type { i8, i16, i32, i64, i64} 12@Global = internal constant %struct {i8 0, i16 1, i32 2, i64 3, i64 4} 13define internal i64 @zoo(i1 %flag) { 14entry: 15 br i1 %flag, label %plus, label %minus 16 17plus: 18 %arg = getelementptr %struct, %struct* @Global, i32 0, i32 3 19 %tmp0 = call i64 @func2(i64* %arg) 20 br label %merge 21 22minus: 23 %arg2 = getelementptr %struct, %struct* @Global, i32 0, i32 4 24 %tmp1 = call i64 @func2(i64* %arg2) 25 br label %merge 26 27merge: 28 %tmp2 = phi i64 [ %tmp0, %plus ], [ %tmp1, %minus] 29 ret i64 %tmp2 30} 31 32define internal i64 @func2(i64 *%x) { 33entry: 34 %val = ptrtoint i64* %x to i64 35 ret i64 %val 36} 37 38define internal i64 @func(i64 *%x, i64 (i64*)* %binop) { 39entry: 40 %tmp0 = call i64 %binop(i64* %x) 41 ret i64 %tmp0 42} 43 44define i64 @main() { 45 %1 = call i64 @zoo(i1 0) 46 %2 = call i64 @zoo(i1 1) 47 %3 = add i64 %1, %2 48 ret i64 %3 49}