Skip to content

Commit 8221f36

Browse files
committed
Fix multiple return case
1 parent d65f9ca commit 8221f36

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,49 @@ define i64 @inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
2121
ret i64 0
2222
}
2323

24-
; INTERESTING-LABEL: @callsite_different_type_unused_0(
25-
; RESULT-LABEL: define i64 @inst_to_return_has_different_type_but_call_result_unused(
26-
; RESULT-NEXT: %load = load i32, ptr %arg
27-
; RESULT-NEXT: store i32 %load, ptr @gv
28-
; RESULT-NEXT: ret i64 0
24+
; INTERESTING-LABEL: @multiple_returns_wrong_return_type_no_callers(
25+
; RESULT-LABEL: define i32 @multiple_returns_wrong_return_type_no_callers(
26+
27+
; RESULT: bb0:
28+
; RESULT-NEXT: %load0 = load i32,
29+
; RESULT-NEXT: ret i32 %load0
30+
31+
; RESULT: bb1:
32+
; RESULT-NEXT: store i32 8, ptr null
33+
; RESULT-NEXT: ret i32 0
34+
define i64 @multiple_returns_wrong_return_type_no_callers(ptr %arg, i1 %cond, i64 %arg2) {
35+
entry:
36+
br i1 %cond, label %bb0, label %bb1
37+
38+
bb0:
39+
%load0 = load i32, ptr %arg
40+
store i32 %load0, ptr @gv
41+
ret i64 234
42+
43+
bb1:
44+
store i32 8, ptr null
45+
ret i64 %arg2
46+
47+
bb2:
48+
ret i64 34
49+
}
50+
51+
; INTERESTING-LABEL: define {{.+}} @callsite_different_type_unused_0(
52+
53+
; RESULT-LABEL: define i64 @callsite_different_type_unused_0(ptr %arg) {
54+
; RESULT-NEXT: %unused0 = call i64 @inst_to_return_has_different_type_but_call_result_unused(ptr %arg)
55+
; RESULT-NEXT: ret i64 %unused0
2956
define void @callsite_different_type_unused_0(ptr %arg) {
3057
%unused0 = call i64 @inst_to_return_has_different_type_but_call_result_unused(ptr %arg)
3158
%unused1 = call i64 @inst_to_return_has_different_type_but_call_result_unused(ptr null)
3259
ret void
3360
}
3461

3562
; TODO: Could rewrite this return from i64 to i32 since the callsite is unused.
36-
; INTERESTING-LABEL: @inst_to_return_has_different_type_but_call_result_unused(
63+
; INTERESTING-LABEL: define {{.+}} @inst_to_return_has_different_type_but_call_result_unused(
3764
; RESULT-LABEL: define i64 @inst_to_return_has_different_type_but_call_result_unused(
65+
; RESULT-NEXT: %load = load i32, ptr %arg
66+
; RESULT-NEXT: store i32 %load, ptr @gv
3867
; RESULT: ret i64 0
3968
define i64 @inst_to_return_has_different_type_but_call_result_unused(ptr %arg) {
4069
%load = load i32, ptr %arg

llvm/tools/llvm-reduce/deltas/ReduceValuesToReturn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void rewriteFuncWithReturnType(Function &OldF, Value *NewRetValue) {
5656
NewRetI ? NewRetI->getIterator() : EntryBB.end();
5757

5858
// Hack up any return values in other blocks, we can't leave them as ret void.
59-
if (OldFuncTy->getReturnType()->isVoidTy()) {
59+
if (OldFuncTy->getReturnType() != NewRetTy) {
6060
for (BasicBlock &OtherRetBB : OldF) {
6161
if (&OtherRetBB != NewRetBlock) {
6262
auto *OrigRI = dyn_cast<ReturnInst>(OtherRetBB.getTerminator());

0 commit comments

Comments
 (0)