1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -passes=verify,iroutliner -ir-outlining-no-cost < %s | FileCheck %s 3 4; This test makes sure we are extracting the found similarity sections 5; correctly at the call site. 6 7define void @extract1() { 8; CHECK-LABEL: @extract1( 9; CHECK-NEXT: entry: 10; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4 11; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4 12; CHECK-NEXT: [[C:%.*]] = alloca i32, align 4 13; CHECK-NEXT: call void @outlined_ir_func_1(ptr [[A]], ptr [[B]], ptr [[C]]) 14; CHECK-NEXT: ret void 15; 16entry: 17 %a = alloca i32, align 4 18 %b = alloca i32, align 4 19 %c = alloca i32, align 4 20 store i32 2, ptr %a, align 4 21 store i32 3, ptr %b, align 4 22 store i32 4, ptr %c, align 4 23 %al = load i32, ptr %a 24 %bl = load i32, ptr %b 25 %cl = load i32, ptr %c 26 ret void 27} 28 29define void @extract2() { 30; CHECK-LABEL: @extract2( 31; CHECK-NEXT: entry: 32; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4 33; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4 34; CHECK-NEXT: [[C:%.*]] = alloca i32, align 4 35; CHECK-NEXT: call void @outlined_ir_func_1(ptr [[A]], ptr [[B]], ptr [[C]]) 36; CHECK-NEXT: ret void 37; 38entry: 39 %a = alloca i32, align 4 40 %b = alloca i32, align 4 41 %c = alloca i32, align 4 42 store i32 2, ptr %a, align 4 43 store i32 3, ptr %b, align 4 44 store i32 4, ptr %c, align 4 45 %al = load i32, ptr %a 46 %bl = load i32, ptr %b 47 %cl = load i32, ptr %c 48 ret void 49} 50 51; There are potential ouptuts in this sections, but we do not extract sections 52; with outputs right now, since they cannot be consolidated. 53define void @extract_outs1() #0 { 54; CHECK-LABEL: @extract_outs1( 55; CHECK-NEXT: entry: 56; CHECK-NEXT: [[DOTLOC:%.*]] = alloca i32, align 4 57; CHECK-NEXT: [[ADD_LOC:%.*]] = alloca i32, align 4 58; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4 59; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4 60; CHECK-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4 61; CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4 62; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[ADD_LOC]]) 63; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[DOTLOC]]) 64; CHECK-NEXT: call void @outlined_ir_func_0(ptr [[A]], ptr [[B]], ptr [[OUTPUT]], ptr [[ADD_LOC]], ptr [[DOTLOC]]) 65; CHECK-NEXT: [[ADD_RELOAD:%.*]] = load i32, ptr [[ADD_LOC]], align 4 66; CHECK-NEXT: [[DOTRELOAD:%.*]] = load i32, ptr [[DOTLOC]], align 4 67; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[ADD_LOC]]) 68; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[DOTLOC]]) 69; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[OUTPUT]], align 4 70; CHECK-NEXT: call void @outlined_ir_func_2(i32 [[DOTRELOAD]], i32 [[ADD_RELOAD]], ptr [[RESULT]]) 71; CHECK-NEXT: ret void 72; 73entry: 74 %a = alloca i32, align 4 75 %b = alloca i32, align 4 76 %output = alloca i32, align 4 77 %result = alloca i32, align 4 78 store i32 2, ptr %a, align 4 79 store i32 3, ptr %b, align 4 80 %0 = load i32, ptr %a, align 4 81 %1 = load i32, ptr %b, align 4 82 %add = add i32 %0, %1 83 store i32 %add, ptr %output, align 4 84 %2 = load i32, ptr %output, align 4 85 %3 = load i32, ptr %output, align 4 86 %mul = mul i32 %2, %add 87 store i32 %mul, ptr %result, align 4 88 ret void 89} 90 91; There are potential ouptuts in this sections, but we do not extract sections 92; with outputs right now, since they cannot be consolidated. 93define void @extract_outs2() #0 { 94; CHECK-LABEL: @extract_outs2( 95; CHECK-NEXT: entry: 96; CHECK-NEXT: [[DOTLOC:%.*]] = alloca i32, align 4 97; CHECK-NEXT: [[ADD_LOC:%.*]] = alloca i32, align 4 98; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4 99; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4 100; CHECK-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4 101; CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4 102; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[ADD_LOC]]) 103; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[DOTLOC]]) 104; CHECK-NEXT: call void @outlined_ir_func_0(ptr [[A]], ptr [[B]], ptr [[OUTPUT]], ptr [[ADD_LOC]], ptr [[DOTLOC]]) 105; CHECK-NEXT: [[ADD_RELOAD:%.*]] = load i32, ptr [[ADD_LOC]], align 4 106; CHECK-NEXT: [[DOTRELOAD:%.*]] = load i32, ptr [[DOTLOC]], align 4 107; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[ADD_LOC]]) 108; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[DOTLOC]]) 109; CHECK-NEXT: call void @outlined_ir_func_2(i32 [[DOTRELOAD]], i32 [[ADD_RELOAD]], ptr [[RESULT]]) 110; CHECK-NEXT: ret void 111; 112entry: 113 %a = alloca i32, align 4 114 %b = alloca i32, align 4 115 %output = alloca i32, align 4 116 %result = alloca i32, align 4 117 store i32 2, ptr %a, align 4 118 store i32 3, ptr %b, align 4 119 %0 = load i32, ptr %a, align 4 120 %1 = load i32, ptr %b, align 4 121 %add = add i32 %0, %1 122 store i32 %add, ptr %output, align 4 123 %2 = load i32, ptr %output, align 4 124 %mul = mul i32 %2, %add 125 store i32 %mul, ptr %result, align 4 126 ret void 127} 128