mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 23:32:27 +00:00
[IPO/MergeFunctions] changes so it doesn't try to bitcast a struct return type but instead recreates it with insert/extract value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207679 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
bf741d2bdd
commit
78ecea93a3
@ -784,8 +784,23 @@ void MergeFunctions::writeThunkOrAlias(Function *F, Function *G) {
|
|||||||
// Helper for writeThunk,
|
// Helper for writeThunk,
|
||||||
// Selects proper bitcast operation,
|
// Selects proper bitcast operation,
|
||||||
// but a bit simpler then CastInst::getCastOpcode.
|
// 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();
|
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())
|
if (SrcTy->isIntegerTy() && DestTy->isPointerTy())
|
||||||
return Builder.CreateIntToPtr(V, DestTy);
|
return Builder.CreateIntToPtr(V, DestTy);
|
||||||
else if (SrcTy->isPointerTy() && DestTy->isIntegerTy())
|
else if (SrcTy->isPointerTy() && DestTy->isIntegerTy())
|
||||||
|
40
test/Transforms/MergeFunc/mergefunc-struct-return.ll
Normal file
40
test/Transforms/MergeFunc/mergefunc-struct-return.ll
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user