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 -function-specialization -force-function-specialization -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(i64 *%x) { 13entry: 14 %val = ptrtoint i64* %x to i64 15 ret i64 %val 16} 17 18define internal i64 @func(i64 *%x, i64 (i64*)* %binop) { 19; CHECK-LABEL: @func( 20; CHECK-NEXT: entry: 21; CHECK-NEXT: [[TMP0:%.*]] = call i64 [[BINOP:%.*]](i64* [[X:%.*]]) 22; CHECK-NEXT: ret i64 [[TMP0]] 23; 24entry: 25 %tmp0 = call i64 %binop(i64* %x) 26 ret i64 %tmp0 27} 28 29define internal i64 @zoo(i1 %flag) { 30; CHECK-LABEL: @zoo( 31; CHECK-NEXT: entry: 32; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]] 33; CHECK: plus: 34; CHECK-NEXT: [[TMP0:%.*]] = call i64 @func2.2(i64* getelementptr inbounds ([[STRUCT:%.*]], %struct* @Global, i32 0, i32 3)) 35; CHECK-NEXT: br label [[MERGE:%.*]] 36; CHECK: minus: 37; CHECK-NEXT: [[TMP1:%.*]] = call i64 @func2.1(i64* getelementptr inbounds ([[STRUCT]], %struct* @Global, i32 0, i32 4)) 38; CHECK-NEXT: br label [[MERGE]] 39; CHECK: merge: 40; CHECK-NEXT: [[TMP2:%.*]] = phi i64 [ [[TMP0]], [[PLUS]] ], [ [[TMP1]], [[MINUS]] ] 41; CHECK-NEXT: ret i64 [[TMP2]] 42; 43entry: 44 br i1 %flag, label %plus, label %minus 45 46plus: 47 %arg = getelementptr %struct, %struct* @Global, i32 0, i32 3 48 %tmp0 = call i64 @func2(i64* %arg) 49 br label %merge 50 51minus: 52 %arg2 = getelementptr %struct, %struct* @Global, i32 0, i32 4 53 %tmp1 = call i64 @func2(i64* %arg2) 54 br label %merge 55 56merge: 57 %tmp2 = phi i64 [ %tmp0, %plus ], [ %tmp1, %minus] 58 ret i64 %tmp2 59} 60 61 62define i64 @main() { 63; CHECK-LABEL: @main( 64; CHECK-NEXT: [[TMP1:%.*]] = call i64 @zoo(i1 false) 65; CHECK-NEXT: [[TMP2:%.*]] = call i64 @zoo(i1 true) 66; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[TMP1]], [[TMP2]] 67; CHECK-NEXT: ret i64 [[TMP3]] 68; 69 %1 = call i64 @zoo(i1 0) 70 %2 = call i64 @zoo(i1 1) 71 %3 = add i64 %1, %2 72 ret i64 %3 73} 74