Skip to content

Commit 61480db

Browse files
committed
[Reduce] Argument reduction: shoe-horn new function into remaining uses of old function
Much like with function reduction, there may be remaining unhandled uses of function, in particular in blockaddress. And in constants we can't RAUW it with undef, because undef is not a function. Instead, let's try to pretent that in the remaining cases, the new signature didn't change, by bitcasting it. A new (previously crashing) test case added.
1 parent 1bac510 commit 61480db

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
2+
; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s
3+
4+
; CHECK-INTERESTINGNESS: define void @func(
5+
; CHECK-FINAL: define void @func()
6+
define void @func(i1 %arg) {
7+
; CHECK-ALL: bb:
8+
; CHECK-ALL: br label %bb4
9+
bb:
10+
br label %bb4
11+
12+
; CHECK-ALL: bb4
13+
bb4:
14+
; CHECK-INTERESTINGNESS; callbr void asm
15+
; CHECK-INTERESTINGNESS-SAME; blockaddress
16+
; CHECK-FINAL: callbr void asm sideeffect "", "X"(i8* blockaddress(@func, %bb11))
17+
; CHECK-ALL: to label %bb5 [label %bb11]
18+
callbr void asm sideeffect "", "X"(i8* blockaddress(@func, %bb11))
19+
to label %bb5 [label %bb11]
20+
21+
; CHECK-ALL: bb5:
22+
; CHECK-ALL: br label %bb11
23+
bb5:
24+
br label %bb11
25+
26+
; CHECK-ALL: bb11:
27+
; CHECK-ALL: ret void
28+
bb11:
29+
ret void
30+
}

llvm/test/Reduce/remove-invoked-functions.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ define void @caller(i32 %arg) personality i8* bitcast (i32 (...)* @__gxx_persona
2323
; CHECK-ALL: bb:
2424
bb:
2525
; CHECK-INTERESTINGNESS: %i0 = invoke i32
26-
; CHECK-FINAL: %i0 = invoke i32 undef(i32 %arg)
26+
; CHECK-FINAL: %i0 = invoke i32 bitcast (i32 ()* @maybe_throwing_callee to i32 (i32)*)(i32 %arg)
2727
; CHECK-ALL: to label %bb3 unwind label %bb1
2828
%i0 = invoke i32 @maybe_throwing_callee(i32 %arg)
2929
to label %bb3 unwind label %bb1

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
9494
replaceFunctionCalls(*F, *ClonedFunc, ArgIndexesToKeep);
9595
// Rename Cloned Function to Old's name
9696
std::string FName = std::string(F->getName());
97-
F->replaceAllUsesWith(UndefValue::get(F->getType()));
97+
F->replaceAllUsesWith(ConstantExpr::getBitCast(ClonedFunc, F->getType()));
9898
F->eraseFromParent();
9999
ClonedFunc->setName(FName);
100100
}

0 commit comments

Comments
 (0)