Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/LLVMPasses/LLVMMergeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,9 @@ void SwiftMergeFunctions::removeEquivalenceClassFromTree(FunctionEntry *FE) {
// Selects proper bitcast operation,
// but a bit simpler then CastInst::getCastOpcode.
static Value *createCast(IRBuilder<> &Builder, Value *V, Type *DestTy) {
if (V->getType() == DestTy)
return V;

Type *SrcTy = V->getType();
if (SrcTy->isStructTy()) {
assert(DestTy->isStructTy());
Expand Down Expand Up @@ -1357,7 +1360,8 @@ bool SwiftMergeFunctions::replaceDirectCallers(Function *Old, Function *New,
NewArgAttrs);
newAttrList = fixUpTypesInByValAndStructRetAttributes(FType, newAttrList);
NewCI->setAttributes(newAttrList);
CI->replaceAllUsesWith(NewCI);
Value *retVal = createCast(Builder, NewCI, CI->getType());
CI->replaceAllUsesWith(retVal);
CI->eraseFromParent();
}
assert(Old->use_empty() && "should have replaced all uses of old function");
Expand Down
34 changes: 34 additions & 0 deletions test/LLVMPasses/merge_func_opaque_pointers.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; RUN: %swift-llvm-opt -swift-merge-functions -swiftmergefunc-threshold=4 -opaque-pointers %s | %FileCheck %s

; REQUIRES: PTRSIZE=64

@g1 = external global i32

define internal i64 @return_0(i32 %x, i32 %y) {
%sum = add i32 %x, %y
%sum2 = add i32 %sum, %y
%l = load i32, i32* @g1, align 4
%sum3 = add i32 %sum2, %y
ret i64 0
}

define internal ptr @return_null(i32 %x, i32 %y) {
%sum = add i32 %x, %y
%sum2 = add i32 %sum, %y
%l = load i32, i32* @g1, align 4
%sum3 = add i32 %sum2, %y
ret ptr null
}

declare void @take_results(i64, ptr)


; CHECK-LABEL: define void @call_return_null
; CHECK: %1 = call i64 @return_0Tm(i32 0, i32 0)
; CHECK: %2 = call ptr @return_0Tm(i32 0, i32 0)
define void @call_return_null() {
%r1 = call i64 @return_0(i32 0, i32 0)
%r2 = call ptr @return_null(i32 0, i32 0)
call void @take_results(i64 %r1, ptr %r2)
ret void
}