[patch] mergefunc struct result
Carlo Kok
ck at remobjects.com
Fri Apr 18 11:21:10 PDT 2014
When using the merge func pass with two functions that return the same
kind of struct but with different element types merge func tries to do a
bitcast of struct to struct and fails with an assert (as you can't bitcast
a struct) given the following functions:
%kv1 = type { i32*, i32* }
%kv2 = type { i8*, i8* }
define %kv1 @fn1() ..
define %kv2 @fn2() ..
(full file in fail.ir)
The attached patch checks for two struct types & uses insert/extract to
create the right record.
To see it fail, fail.ir can be used with opt:
opt -mergefunc fail.ir -o out.ir
after the patch it generates:
define %kv1 @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() {
%1 = tail call %kv1 @fn1()
%2 = extractvalue %kv1 %1, 0
%3 = bitcast i32* %2 to i8*
%4 = insertvalue %kv2 undef, i8* %3, 0
%5 = extractvalue %kv1 %1, 1
%6 = bitcast i32* %5 to i8*
%7 = insertvalue %kv2 %4, i8* %6, 1
ret %kv2 %7
}
Where fn2 is the merged function.
--
Carlo Kok
RemObjects Software
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-mergefunc-struct-result.diff
Type: application/octet-stream
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140418/94ca0425/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fail.ir
Type: application/octet-stream
Size: 683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140418/94ca0425/attachment-0001.obj>
More information about the llvm-commits
mailing list