1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=iroutliner -ir-outlining-no-cost < %s | FileCheck %s
4 ; These functions are constructed slightly differently so that they require
5 ; different output blocks for the values used outside of the region. We are
6 ; checking that two output blocks are created with different values.
8 define void @outline_outputs1() #0 {
9 ; CHECK-LABEL: @outline_outputs1(
11 ; CHECK-NEXT: [[DOTLOC:%.*]] = alloca i32, align 4
12 ; CHECK-NEXT: [[ADD_LOC:%.*]] = alloca i32, align 4
13 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
14 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
15 ; CHECK-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4
16 ; CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4
17 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[ADD_LOC]])
18 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[DOTLOC]])
19 ; CHECK-NEXT: call void @outlined_ir_func_0(ptr [[A]], ptr [[B]], ptr [[OUTPUT]], ptr [[ADD_LOC]], ptr [[DOTLOC]], i32 0)
20 ; CHECK-NEXT: [[ADD_RELOAD:%.*]] = load i32, ptr [[ADD_LOC]], align 4
21 ; CHECK-NEXT: [[DOTRELOAD:%.*]] = load i32, ptr [[DOTLOC]], align 4
22 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[ADD_LOC]])
23 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[DOTLOC]])
24 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[OUTPUT]], align 4
25 ; CHECK-NEXT: call void @outlined_ir_func_1(i32 [[DOTRELOAD]], i32 [[ADD_RELOAD]], ptr [[RESULT]])
26 ; CHECK-NEXT: ret void
29 %a = alloca i32, align 4
30 %b = alloca i32, align 4
31 %output = alloca i32, align 4
32 %result = alloca i32, align 4
33 store i32 2, ptr %a, align 4
34 store i32 3, ptr %b, align 4
35 %0 = load i32, ptr %a, align 4
36 %1 = load i32, ptr %b, align 4
39 store i32 %add, ptr %output, align 4
40 %2 = load i32, ptr %output, align 4
41 %3 = load i32, ptr %output, align 4
42 %mul = mul i32 %2, %add
43 store i32 %mul, ptr %result, align 4
47 define void @outline_outputs2() #0 {
48 ; CHECK-LABEL: @outline_outputs2(
50 ; CHECK-NEXT: [[DOTLOC:%.*]] = alloca i32, align 4
51 ; CHECK-NEXT: [[SUB_LOC:%.*]] = alloca i32, align 4
52 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
53 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
54 ; CHECK-NEXT: [[OUTPUT:%.*]] = alloca i32, align 4
55 ; CHECK-NEXT: [[RESULT:%.*]] = alloca i32, align 4
56 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[SUB_LOC]])
57 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[DOTLOC]])
58 ; CHECK-NEXT: call void @outlined_ir_func_0(ptr [[A]], ptr [[B]], ptr [[OUTPUT]], ptr [[SUB_LOC]], ptr [[DOTLOC]], i32 1)
59 ; CHECK-NEXT: [[SUB_RELOAD:%.*]] = load i32, ptr [[SUB_LOC]], align 4
60 ; CHECK-NEXT: [[DOTRELOAD:%.*]] = load i32, ptr [[DOTLOC]], align 4
61 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[SUB_LOC]])
62 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[DOTLOC]])
63 ; CHECK-NEXT: call void @outlined_ir_func_1(i32 [[DOTRELOAD]], i32 [[SUB_RELOAD]], ptr [[RESULT]])
64 ; CHECK-NEXT: ret void
67 %a = alloca i32, align 4
68 %b = alloca i32, align 4
69 %output = alloca i32, align 4
70 %result = alloca i32, align 4
71 store i32 2, ptr %a, align 4
72 store i32 3, ptr %b, align 4
73 %0 = load i32, ptr %a, align 4
74 %1 = load i32, ptr %b, align 4
77 store i32 %add, ptr %output, align 4
78 %2 = load i32, ptr %output, align 4
79 %mul = mul i32 %2, %sub
80 store i32 %mul, ptr %result, align 4
84 ; CHECK: define internal void @outlined_ir_func_0(ptr [[ARG0:%.*]], ptr [[ARG1:%.*]], ptr [[ARG2:%.*]], ptr [[ARG3:%.*]], ptr [[ARG4:%.*]], i32 [[ARG5:%.*]]) #1 {
85 ; CHECK: entry_to_outline:
86 ; CHECK-NEXT: store i32 2, ptr [[ARG0]], align 4
87 ; CHECK-NEXT: store i32 3, ptr [[ARG1]], align 4
88 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARG0]], align 4
89 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARG1]], align 4
90 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[TMP0]], [[TMP1]]
91 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[TMP0]], [[TMP1]]
92 ; CHECK-NEXT: store i32 [[ADD]], ptr [[ARG2]], align 4
93 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARG2]], align 4
95 ; CHECK: _after_outline.exitStub:
96 ; CHECK-NEXT: switch i32 [[ARG5]], label [[BLOCK:%.*]] [
97 ; CHECK-NEXT: i32 0, label %[[BLOCK_0:.*]]
98 ; CHECK-NEXT: i32 1, label %[[BLOCK_1:.*]]
100 ; CHECK: [[BLOCK_0]]:
101 ; CHECK-NEXT: store i32 [[ADD]], ptr [[ARG3]], align 4
102 ; CHECK-NEXT: store i32 [[TMP2]], ptr [[ARG4]], align 4
104 ; CHECK: [[BLOCK_1]]:
105 ; CHECK-NEXT: store i32 [[SUB]], ptr [[ARG3]], align 4
106 ; CHECK-NEXT: store i32 [[TMP2]], ptr [[ARG4]], align 4