1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

[IPO/MergeFunctions] changes so it doesn't try to bitcast a struct return type but instead recreates it with insert/extract value.

llvm-svn: 207679
This commit is contained in:
Carlo Kok 2014-04-30 17:53:04 +00:00
parent a9ce55b419
commit 3c208bd22a
2 changed files with 56 additions and 1 deletions

View File

@ -784,8 +784,23 @@ void MergeFunctions::writeThunkOrAlias(Function *F, Function *G) {
// Helper for writeThunk,
// Selects proper bitcast operation,
// but a bit simpler then CastInst::getCastOpcode.
static Value* createCast(IRBuilder<false> &Builder, Value *V, Type *DestTy) {
static Value *createCast(IRBuilder<false> &Builder, Value *V, Type *DestTy) {
Type *SrcTy = V->getType();
if (SrcTy->isStructTy()) {
assert(DestTy->isStructTy());
assert(SrcTy->getStructNumElements() == DestTy->getStructNumElements());
Value *Result = UndefValue::get(DestTy);
for (unsigned int I = 0, E = SrcTy->getStructNumElements(); I < E; ++I) {
Value *Element = createCast(
Builder, Builder.CreateExtractValue(V, ArrayRef<unsigned int>(I)),
DestTy->getStructElementType(I));
Result =
Builder.CreateInsertValue(Result, Element, ArrayRef<unsigned int>(I));
}
return Result;
}
assert(!DestTy->isStructTy());
if (SrcTy->isIntegerTy() && DestTy->isPointerTy())
return Builder.CreateIntToPtr(V, DestTy);
else if (SrcTy->isPointerTy() && DestTy->isIntegerTy())

View File

@ -0,0 +1,40 @@
; RUN: opt -mergefunc -S < %s | FileCheck %s
; This test makes sure that the mergefunc pass, uses extract and insert value
; to convert the struct result type; as struct types cannot be bitcast.
target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
%kv1 = type { i32*, i32* }
%kv2 = type { i8*, i8* }
declare void @noop()
define %kv1 @fn1() {
; CHECK-LABEL: @fn1(
%tmp = alloca %kv1
%v1 = getelementptr %kv1* %tmp, i32 0, i32 0
store i32* null, i32** %v1
%v2 = getelementptr %kv1* %tmp, i32 0, i32 0
store i32* null, i32** %v2
call void @noop()
%v3 = load %kv1* %tmp
ret %kv1 %v3
}
define %kv2 @fn2() {
; CHECK-LABEL: @fn2(
; CHECK: %1 = tail call %kv1 @fn1()
; CHECK: %2 = extractvalue %kv1 %1, 0
; CHECK: %3 = bitcast i32* %2 to i8*
; CHECK: %4 = insertvalue %kv2 undef, i8* %3, 0
%tmp = alloca %kv2
%v1 = getelementptr %kv2* %tmp, i32 0, i32 0
store i8* null, i8** %v1
%v2 = getelementptr %kv2* %tmp, i32 0, i32 0
store i8* null, i8** %v2
call void @noop()
%v3 = load %kv2* %tmp
ret %kv2 %v3
}