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