[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.
This commit is contained in:
Roman Lebedev 2020-07-27 15:36:07 +03:00
parent 1bac5101cd
commit 61480db601
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
3 changed files with 32 additions and 2 deletions

View File

@ -0,0 +1,30 @@
; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s
; CHECK-INTERESTINGNESS: define void @func(
; CHECK-FINAL: define void @func()
define void @func(i1 %arg) {
; CHECK-ALL: bb:
; CHECK-ALL: br label %bb4
bb:
br label %bb4
; CHECK-ALL: bb4
bb4:
; CHECK-INTERESTINGNESS; callbr void asm
; CHECK-INTERESTINGNESS-SAME; blockaddress
; CHECK-FINAL: callbr void asm sideeffect "", "X"(i8* blockaddress(@func, %bb11))
; CHECK-ALL: to label %bb5 [label %bb11]
callbr void asm sideeffect "", "X"(i8* blockaddress(@func, %bb11))
to label %bb5 [label %bb11]
; CHECK-ALL: bb5:
; CHECK-ALL: br label %bb11
bb5:
br label %bb11
; CHECK-ALL: bb11:
; CHECK-ALL: ret void
bb11:
ret void
}

View File

@ -23,7 +23,7 @@ define void @caller(i32 %arg) personality i8* bitcast (i32 (...)* @__gxx_persona
; CHECK-ALL: bb:
bb:
; CHECK-INTERESTINGNESS: %i0 = invoke i32
; CHECK-FINAL: %i0 = invoke i32 undef(i32 %arg)
; CHECK-FINAL: %i0 = invoke i32 bitcast (i32 ()* @maybe_throwing_callee to i32 (i32)*)(i32 %arg)
; CHECK-ALL: to label %bb3 unwind label %bb1
%i0 = invoke i32 @maybe_throwing_callee(i32 %arg)
to label %bb3 unwind label %bb1

View File

@ -94,7 +94,7 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
replaceFunctionCalls(*F, *ClonedFunc, ArgIndexesToKeep);
// Rename Cloned Function to Old's name
std::string FName = std::string(F->getName());
F->replaceAllUsesWith(UndefValue::get(F->getType()));
F->replaceAllUsesWith(ConstantExpr::getBitCast(ClonedFunc, F->getType()));
F->eraseFromParent();
ClonedFunc->setName(FName);
}