xref: /llvm-project/llvm/test/Transforms/MergeFunc/mergefunc-struct-return.ll (revision ee2789001b8558656a13502f0de2c81dcb419430)
1; RUN: opt -passes=mergefunc -S < %s | FileCheck %s
2
3; This test makes sure that the mergefunc pass, uses extract and insert value
4; to convert the struct result type; as struct types cannot be bitcast.
5
6target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
7
8%kv1 = type { ptr, ptr }
9%kv2 = type { ptr, ptr }
10
11declare void @noop()
12
13define %kv1 @fn1() {
14; CHECK-LABEL: @fn1(
15  %tmp = alloca %kv1
16  store ptr null, ptr %tmp
17  store ptr null, ptr %tmp
18  call void @noop()
19  %v3 = load %kv1, ptr %tmp
20  ret %kv1 %v3
21}
22
23define %kv2 @fn2() {
24; CHECK-LABEL: @fn2(
25; CHECK: %1 = tail call %kv1 @fn1()
26; CHECK: %2 = extractvalue %kv1 %1, 0
27; CHECK: %3 = insertvalue %kv2 poison, ptr %2, 0
28  %tmp = alloca %kv2
29  store ptr null, ptr %tmp
30  store ptr null, ptr %tmp
31  call void @noop()
32
33  %v3 = load %kv2, ptr %tmp
34  ret %kv2 %v3
35}
36