2008-06-11 00:13:38 +08:00
|
|
|
; Ignore stderr, we expect warnings there
|
2009-10-12 16:51:28 +08:00
|
|
|
; RUN: opt < %s -instcombine 2> /dev/null -S | FileCheck %s
|
2003-06-19 06:48:11 +08:00
|
|
|
|
2013-09-18 05:10:14 +08:00
|
|
|
target datalayout = "E-p:64:64:64-p1:16:16:16-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
|
2003-06-19 06:48:11 +08:00
|
|
|
|
|
|
|
; Simple case, argument translatable without changing the value
|
2008-03-25 12:26:08 +08:00
|
|
|
declare void @test1a(i8*)
|
|
|
|
|
|
|
|
define void @test1(i32* %A) {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2011-09-28 04:39:19 +08:00
|
|
|
; CHECK: %1 = bitcast i32* %A to i8*
|
|
|
|
; CHECK: call void @test1a(i8* %1)
|
2009-10-12 16:46:47 +08:00
|
|
|
; CHECK: ret void
|
2013-07-31 04:45:05 +08:00
|
|
|
call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
|
|
|
|
ret void
|
2003-06-19 06:48:11 +08:00
|
|
|
}
|
|
|
|
|
2013-09-18 05:10:14 +08:00
|
|
|
|
|
|
|
; Should not do because of change in address space of the parameter
|
|
|
|
define void @test1_as1_illegal(i32 addrspace(1)* %A) {
|
|
|
|
; CHECK-LABEL: @test1_as1_illegal(
|
|
|
|
; CHECK: call void bitcast
|
|
|
|
call void bitcast (void (i8*)* @test1a to void (i32 addrspace(1)*)*)(i32 addrspace(1)* %A)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Test1, but the argument has a different sized address-space
|
|
|
|
declare void @test1a_as1(i8 addrspace(1)*)
|
|
|
|
|
|
|
|
; This one is OK to perform
|
|
|
|
define void @test1_as1(i32 addrspace(1)* %A) {
|
|
|
|
; CHECK-LABEL: @test1_as1(
|
|
|
|
; CHECK: %1 = bitcast i32 addrspace(1)* %A to i8 addrspace(1)*
|
|
|
|
; CHECK: call void @test1a_as1(i8 addrspace(1)* %1)
|
|
|
|
; CHECK: ret void
|
|
|
|
call void bitcast (void (i8 addrspace(1)*)* @test1a_as1 to void (i32 addrspace(1)*)*)(i32 addrspace(1)* %A )
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2013-07-31 04:45:05 +08:00
|
|
|
; More complex case, translate argument because of resolution. This is safe
|
2003-06-19 06:48:11 +08:00
|
|
|
; because we have the body of the function
|
2008-03-25 12:26:08 +08:00
|
|
|
define void @test2a(i8 %A) {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test2a(
|
2009-10-12 16:46:47 +08:00
|
|
|
; CHECK: ret void
|
2013-07-31 04:45:05 +08:00
|
|
|
ret void
|
2003-06-19 06:48:11 +08:00
|
|
|
}
|
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test2(i32 %A) {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
|
|
|
; CHECK: call void bitcast
|
2009-10-12 16:46:47 +08:00
|
|
|
; CHECK: ret i32 %A
|
2013-07-31 04:45:05 +08:00
|
|
|
call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
|
|
|
|
ret i32 %A
|
2008-03-25 12:26:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-31 04:45:05 +08:00
|
|
|
; Resolving this should insert a cast from sbyte to int, following the C
|
2012-02-03 08:00:50 +08:00
|
|
|
; promotion rules.
|
|
|
|
define void @test3a(i8, ...) {unreachable }
|
|
|
|
|
|
|
|
define void @test3(i8 %A, i8 %B) {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
2012-02-03 08:00:50 +08:00
|
|
|
; CHECK: %1 = zext i8 %B to i32
|
[opaque pointer type] Add textual IR support for explicit type parameter to the call instruction
See r230786 and r230794 for similar changes to gep and load
respectively.
Call is a bit different because it often doesn't have a single explicit
type - usually the type is deduced from the arguments, and just the
return type is explicit. In those cases there's no need to change the
IR.
When that's not the case, the IR usually contains the pointer type of
the first operand - but since typed pointers are going away, that
representation is insufficient so I'm just stripping the "pointerness"
of the explicit type away.
This does make the IR a bit weird - it /sort of/ reads like the type of
the first operand: "call void () %x(" but %x is actually of type "void
()*" and will eventually be just of type "ptr". But this seems not too
bad and I don't think it would benefit from repeating the type
("void (), void () * %x(" and then eventually "void (), ptr %x(") as has
been done with gep and load.
This also has a side benefit: since the explicit type is no longer a
pointer, there's no ambiguity between an explicit type and a function
that returns a function pointer. Previously this case needed an explicit
type (eg: a function returning a void() function was written as
"call void () () * @x(" rather than "call void () * @x(" because of the
ambiguity between a function returning a pointer to a void() function
and a function returning void).
No ambiguity means even function pointer return types can just be
written alone, without writing the whole function's type.
This leaves /only/ the varargs case where the explicit type is required.
Given the special type syntax in call instructions, the regex-fu used
for migration was a bit more involved in its own unique way (as every
one of these is) so here it is. Use it in conjunction with the apply.sh
script and associated find/xargs commands I've provided in rr230786 to
migrate your out of tree tests. Do let me know if any of this doesn't
cover your cases & we can iterate on a more general script/regexes to
help others with out of tree tests.
About 9 test cases couldn't be automatically migrated - half of those
were functions returning function pointers, where I just had to manually
delete the function argument types now that we didn't need an explicit
function type there. The other half were typedefs of function types used
in calls - just had to manually drop the * from those.
import fileinput
import sys
import re
pat = re.compile(r'((?:=|:|^|\s)call\s(?:[^@]*?))(\s*$|\s*(?:(?:\[\[[a-zA-Z0-9_]+\]\]|[@%](?:(")?[\\\?@a-zA-Z0-9_.]*?(?(3)"|)|{{.*}}))(?:\(|$)|undef|inttoptr|bitcast|null|asm).*$)')
addrspace_end = re.compile(r"addrspace\(\d+\)\s*\*$")
func_end = re.compile("(?:void.*|\)\s*)\*$")
def conv(match, line):
if not match or re.search(addrspace_end, match.group(1)) or not re.search(func_end, match.group(1)):
return line
return line[:match.start()] + match.group(1)[:match.group(1).rfind('*')].rstrip() + match.group(2) + line[match.end():]
for line in sys.stdin:
sys.stdout.write(conv(re.search(pat, line), line))
llvm-svn: 235145
2015-04-17 07:24:18 +08:00
|
|
|
; CHECK: call void (i8, ...) @test3a(i8 %A, i32 %1)
|
2012-02-03 08:00:50 +08:00
|
|
|
; CHECK: ret void
|
2013-07-31 04:45:05 +08:00
|
|
|
call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B)
|
|
|
|
ret void
|
2012-02-03 08:00:50 +08:00
|
|
|
}
|
|
|
|
|
2003-06-19 06:48:11 +08:00
|
|
|
; test conversion of return value...
|
2008-03-25 12:26:08 +08:00
|
|
|
define i8 @test4a() {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test4a(
|
2009-10-12 16:46:47 +08:00
|
|
|
; CHECK: ret i8 0
|
2013-07-31 04:45:05 +08:00
|
|
|
ret i8 0
|
2008-03-25 12:26:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test4() {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test4(
|
|
|
|
; CHECK: call i32 bitcast
|
|
|
|
%X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1]
|
|
|
|
ret i32 %X
|
2003-06-19 06:48:11 +08:00
|
|
|
}
|
|
|
|
|
2013-07-31 04:45:05 +08:00
|
|
|
; test conversion of return value... no value conversion occurs so we can do
|
2003-06-19 06:48:11 +08:00
|
|
|
; this with just a prototype...
|
2008-03-25 12:26:08 +08:00
|
|
|
declare i32 @test5a()
|
|
|
|
|
|
|
|
define i32 @test5() {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test5(
|
2009-10-12 16:46:47 +08:00
|
|
|
; CHECK: %X = call i32 @test5a()
|
|
|
|
; CHECK: ret i32 %X
|
2013-07-31 04:45:05 +08:00
|
|
|
%X = call i32 @test5a( ) ; <i32> [#uses=1]
|
|
|
|
ret i32 %X
|
2003-06-19 06:48:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; test addition of new arguments...
|
2008-03-25 12:26:08 +08:00
|
|
|
declare i32 @test6a(i32)
|
|
|
|
|
|
|
|
define i32 @test6() {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test6(
|
2011-05-18 09:28:27 +08:00
|
|
|
; CHECK: %X = call i32 @test6a(i32 0)
|
|
|
|
; CHECK: ret i32 %X
|
2013-07-31 04:45:05 +08:00
|
|
|
%X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
|
|
|
|
ret i32 %X
|
2003-06-19 06:48:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; test removal of arguments, only can happen with a function body
|
2008-03-25 12:26:08 +08:00
|
|
|
define void @test7a() {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test7a(
|
2009-10-12 16:46:47 +08:00
|
|
|
; CHECK: ret void
|
2013-07-31 04:45:05 +08:00
|
|
|
ret void
|
2003-06-19 06:48:11 +08:00
|
|
|
}
|
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
define void @test7() {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test7(
|
2009-10-12 16:46:47 +08:00
|
|
|
; CHECK: call void @test7a()
|
|
|
|
; CHECK: ret void
|
2013-07-31 04:45:05 +08:00
|
|
|
call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
|
|
|
|
ret void
|
2008-03-25 12:26:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-02 02:11:34 +08:00
|
|
|
; rdar://7590304
|
|
|
|
declare void @test8a()
|
|
|
|
|
2015-06-18 04:52:32 +08:00
|
|
|
define i8* @test8() personality i32 (...)* @__gxx_personality_v0 {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test8(
|
|
|
|
; CHECK-NEXT: invoke void @test8a()
|
|
|
|
; Don't turn this into "unreachable": the callee and caller don't agree in
|
|
|
|
; calling conv, but the implementation of test8a may actually end up using the
|
|
|
|
; right calling conv.
|
2010-06-17 23:18:27 +08:00
|
|
|
invoke void @test8a()
|
2010-02-02 02:11:34 +08:00
|
|
|
to label %invoke.cont unwind label %try.handler
|
|
|
|
|
|
|
|
invoke.cont: ; preds = %entry
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
try.handler: ; preds = %entry
|
2015-06-18 04:52:32 +08:00
|
|
|
%exn = landingpad {i8*, i32}
|
2011-09-01 09:28:25 +08:00
|
|
|
cleanup
|
2010-02-02 02:11:34 +08:00
|
|
|
ret i8* null
|
|
|
|
}
|
|
|
|
|
2011-09-01 09:28:25 +08:00
|
|
|
declare i32 @__gxx_personality_v0(...)
|
|
|
|
|
2011-02-24 13:10:56 +08:00
|
|
|
|
2013-07-31 04:45:05 +08:00
|
|
|
; Don't turn this into a direct call, because test9x is just a prototype and
|
2011-02-24 13:10:56 +08:00
|
|
|
; doing so will make it varargs.
|
|
|
|
; rdar://9038601
|
|
|
|
declare i8* @test9x(i8*, i8*, ...) noredzone
|
|
|
|
define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
|
2013-07-31 04:45:05 +08:00
|
|
|
; CHECK-LABEL: @test9
|
2011-02-24 13:10:56 +08:00
|
|
|
entry:
|
|
|
|
%call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
|
|
|
|
ret i8* %call
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test9(
|
2011-02-24 13:10:56 +08:00
|
|
|
; CHECK: call i8* bitcast
|
|
|
|
}
|
|
|
|
|
2013-09-18 05:10:14 +08:00
|
|
|
|
|
|
|
; Parameter that's a vector of pointers
|
|
|
|
declare void @test10a(<2 x i8*>)
|
|
|
|
|
|
|
|
define void @test10(<2 x i32*> %A) {
|
|
|
|
; CHECK-LABEL: @test10(
|
|
|
|
; CHECK: %1 = bitcast <2 x i32*> %A to <2 x i8*>
|
|
|
|
; CHECK: call void @test10a(<2 x i8*> %1)
|
|
|
|
; CHECK: ret void
|
|
|
|
call void bitcast (void (<2 x i8*>)* @test10a to void (<2 x i32*>)*)(<2 x i32*> %A)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Don't transform because different address spaces
|
|
|
|
declare void @test10a_mixed_as(<2 x i8 addrspace(1)*>)
|
|
|
|
|
|
|
|
define void @test10_mixed_as(<2 x i8*> %A) {
|
|
|
|
; CHECK-LABEL: @test10_mixed_as(
|
|
|
|
; CHECK: call void bitcast
|
|
|
|
call void bitcast (void (<2 x i8 addrspace(1)*>)* @test10a_mixed_as to void (<2 x i8*>)*)(<2 x i8*> %A)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Return type that's a pointer
|
|
|
|
define i8* @test11a() {
|
|
|
|
ret i8* zeroinitializer
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32* @test11() {
|
|
|
|
; CHECK-LABEL: @test11(
|
|
|
|
; CHECK: %X = call i8* @test11a()
|
|
|
|
; CHECK: %1 = bitcast i8* %X to i32*
|
|
|
|
%X = call i32* bitcast (i8* ()* @test11a to i32* ()*)()
|
|
|
|
ret i32* %X
|
|
|
|
}
|
|
|
|
|
|
|
|
; Return type that's a pointer with a different address space
|
|
|
|
define i8 addrspace(1)* @test11a_mixed_as() {
|
|
|
|
ret i8 addrspace(1)* zeroinitializer
|
|
|
|
}
|
|
|
|
|
|
|
|
define i8* @test11_mixed_as() {
|
|
|
|
; CHECK-LABEL: @test11_mixed_as(
|
|
|
|
; CHECK: call i8* bitcast
|
|
|
|
%X = call i8* bitcast (i8 addrspace(1)* ()* @test11a_mixed_as to i8* ()*)()
|
|
|
|
ret i8* %X
|
|
|
|
}
|
|
|
|
|
|
|
|
; Return type that's a vector of pointers
|
|
|
|
define <2 x i8*> @test12a() {
|
|
|
|
ret <2 x i8*> zeroinitializer
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i32*> @test12() {
|
|
|
|
; CHECK-LABEL: @test12(
|
|
|
|
; CHECK: %X = call <2 x i8*> @test12a()
|
|
|
|
; CHECK: %1 = bitcast <2 x i8*> %X to <2 x i32*>
|
|
|
|
%X = call <2 x i32*> bitcast (<2 x i8*> ()* @test12a to <2 x i32*> ()*)()
|
|
|
|
ret <2 x i32*> %X
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i8 addrspace(1)*> @test12a_mixed_as() {
|
|
|
|
ret <2 x i8 addrspace(1)*> zeroinitializer
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i8*> @test12_mixed_as() {
|
|
|
|
; CHECK-LABEL: @test12_mixed_as(
|
|
|
|
; CHECK: call <2 x i8*> bitcast
|
|
|
|
%X = call <2 x i8*> bitcast (<2 x i8 addrspace(1)*> ()* @test12a_mixed_as to <2 x i8*> ()*)()
|
|
|
|
ret <2 x i8*> %X
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; Mix parameter that's a vector of integers and pointers of the same size
|
|
|
|
declare void @test13a(<2 x i64>)
|
|
|
|
|
|
|
|
define void @test13(<2 x i32*> %A) {
|
|
|
|
; CHECK-LABEL: @test13(
|
|
|
|
; CHECK: call void bitcast
|
|
|
|
call void bitcast (void (<2 x i64>)* @test13a to void (<2 x i32*>)*)(<2 x i32*> %A)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Mix parameter that's a vector of integers and pointers of the same
|
|
|
|
; size, but the other way around
|
|
|
|
declare void @test14a(<2 x i8*>)
|
|
|
|
|
|
|
|
define void @test14(<2 x i64> %A) {
|
|
|
|
; CHECK-LABEL: @test14(
|
|
|
|
; CHECK: call void bitcast
|
|
|
|
call void bitcast (void (<2 x i8*>)* @test14a to void (<2 x i64>)*)(<2 x i64> %A)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; Return type that's a vector
|
|
|
|
define <2 x i16> @test15a() {
|
|
|
|
ret <2 x i16> zeroinitializer
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test15() {
|
|
|
|
; CHECK-LABEL: @test15(
|
|
|
|
; CHECK: %X = call <2 x i16> @test15a()
|
|
|
|
; CHECK: %1 = bitcast <2 x i16> %X to i32
|
|
|
|
%X = call i32 bitcast (<2 x i16> ()* @test15a to i32 ()*)( )
|
|
|
|
ret i32 %X
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test16a() {
|
|
|
|
ret i32 0
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i16> @test16() {
|
|
|
|
; CHECK-LABEL: @test16(
|
|
|
|
; CHECK: %X = call i32 @test16a()
|
|
|
|
; CHECK: %1 = bitcast i32 %X to <2 x i16>
|
|
|
|
%X = call <2 x i16> bitcast (i32 ()* @test16a to <2 x i16> ()*)( )
|
|
|
|
ret <2 x i16> %X
|
|
|
|
}
|
2016-07-22 12:54:44 +08:00
|
|
|
|
|
|
|
declare i32 @pr28655(i32 returned %V)
|
|
|
|
|
|
|
|
define i32 @test17() {
|
|
|
|
entry:
|
|
|
|
%C = call i32 @pr28655(i32 0)
|
|
|
|
ret i32 %C
|
|
|
|
}
|
|
|
|
; CHECK-LABEL: @test17(
|
|
|
|
; CHECK: call i32 @pr28655(i32 0)
|
|
|
|
; CHECK: ret i32 0
|
2018-01-03 21:35:43 +08:00
|
|
|
|
|
|
|
define void @non_vararg(i8*, i32) {
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test_cast_to_vararg(i8* %this) {
|
|
|
|
; CHECK-LABEL: test_cast_to_vararg
|
|
|
|
; CHECK: call void @non_vararg(i8* %this, i32 42)
|
|
|
|
call void (i8*, ...) bitcast (void (i8*, i32)* @non_vararg to void (i8*, ...)*)(i8* %this, i32 42)
|
|
|
|
ret void
|
|
|
|
}
|