diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-07-30 20:45:05 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-07-30 20:45:05 +0000 |
commit | f34dc428fa577d6d5d71ab3a1f9765b4e5da5a4f (patch) | |
tree | a86bb2efc2858086c526b79eb798b2de2a04d3cb /test | |
parent | 80bec28b6645676a7cd9408d780b4c805774ef42 (diff) | |
download | external_llvm-f34dc428fa577d6d5d71ab3a1f9765b4e5da5a4f.zip external_llvm-f34dc428fa577d6d5d71ab3a1f9765b4e5da5a4f.tar.gz external_llvm-f34dc428fa577d6d5d71ab3a1f9765b4e5da5a4f.tar.bz2 |
Change behavior of calling bitcasted alias functions.
It will now only convert the arguments / return value and call
the underlying function if the types are able to be bitcasted.
This avoids using fp<->int conversions that would occur before.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187444 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll | 21 | ||||
-rw-r--r-- | test/Transforms/InstCombine/2008-01-06-VoidCast.ll | 10 | ||||
-rw-r--r-- | test/Transforms/InstCombine/apint-call-cast-target.ll | 7 | ||||
-rw-r--r-- | test/Transforms/InstCombine/bitcast-alias-function.ll | 229 | ||||
-rw-r--r-- | test/Transforms/InstCombine/call-cast-target.ll | 10 | ||||
-rw-r--r-- | test/Transforms/InstCombine/call.ll | 77 |
6 files changed, 295 insertions, 59 deletions
diff --git a/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll b/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll index 6588a91..22c0782 100644 --- a/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll +++ b/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll @@ -4,22 +4,27 @@ ; CHECK-NOT: bitcast define void @a() { - ret void + ret void } define signext i32 @b(i32* inreg %x) { - ret i32 0 + ret i32 0 } define void @c(...) { - ret void + ret void } define void @g(i32* %y) { - call void bitcast (void ()* @a to void (i32*)*)( i32* noalias %y ) - call <2 x i32> bitcast (i32 (i32*)* @b to <2 x i32> (i32*)*)( i32* inreg null ) ; <<2 x i32>>:1 [#uses=0] +; CHECK-LABEL: @g( +; CHECK: call i64 bitcast (i32 (i32*)* @b to i64 (i32)*)(i32 0) %x = call i64 bitcast (i32 (i32*)* @b to i64 (i32)*)( i32 0 ) ; <i64> [#uses=0] - call void bitcast (void (...)* @c to void (i32)*)( i32 0 ) - call void bitcast (void (...)* @c to void (i32)*)( i32 zeroext 0 ) - ret void + +; The rest should not have bitcasts remaining +; CHECK-NOT: bitcast + call void bitcast (void ()* @a to void (i32*)*)( i32* noalias %y ) + call <2 x i32> bitcast (i32 (i32*)* @b to <2 x i32> (i32*)*)( i32* inreg null ) ; <<2 x i32>>:1 [#uses=0] + call void bitcast (void (...)* @c to void (i32)*)( i32 0 ) + call void bitcast (void (...)* @c to void (i32)*)( i32 zeroext 0 ) + ret void } diff --git a/test/Transforms/InstCombine/2008-01-06-VoidCast.ll b/test/Transforms/InstCombine/2008-01-06-VoidCast.ll index ebd5c42..5dcaa38 100644 --- a/test/Transforms/InstCombine/2008-01-06-VoidCast.ll +++ b/test/Transforms/InstCombine/2008-01-06-VoidCast.ll @@ -1,10 +1,12 @@ ; RUN: opt < %s -instcombine -S | FileCheck %s define void @f(i16 %y) { - ret void + ret void } -; CHECK-NOT: bitcast + define i32 @g(i32 %y) { - %x = call i32 bitcast (void (i16)* @f to i32 (i32)*)( i32 %y ) ; <i32> [#uses=1] - ret i32 %x +; CHECK-LABEL: @g( +; CHECK: call i32 bitcast + %x = call i32 bitcast (void (i16)* @f to i32 (i32)*)( i32 %y ) ; <i32> [#uses=1] + ret i32 %x } diff --git a/test/Transforms/InstCombine/apint-call-cast-target.ll b/test/Transforms/InstCombine/apint-call-cast-target.ll index 7d7c8fa..4e98f9b 100644 --- a/test/Transforms/InstCombine/apint-call-cast-target.ll +++ b/test/Transforms/InstCombine/apint-call-cast-target.ll @@ -3,16 +3,17 @@ target datalayout = "e-p:32:32" target triple = "i686-pc-linux-gnu" -; CHECK-NOT: bitcast -; CHECK: call -; CHECK-NOT: bitcast define i32 @main() { +; CHECK-LABEL: @main( +; CHECK: call i32 bitcast entry: %tmp = call i32 bitcast (i7* (i999*)* @ctime to i32 (i99*)*)( i99* null ) ret i32 %tmp } define i7* @ctime(i999*) { +; CHECK-LABEL: @ctime( +; CHECK: call i7* bitcast entry: %tmp = call i7* bitcast (i32 ()* @main to i7* ()*)( ) ret i7* %tmp diff --git a/test/Transforms/InstCombine/bitcast-alias-function.ll b/test/Transforms/InstCombine/bitcast-alias-function.ll new file mode 100644 index 0000000..a6b56f9 --- /dev/null +++ b/test/Transforms/InstCombine/bitcast-alias-function.ll @@ -0,0 +1,229 @@ +; RUN: opt -S -instcombine -o - %s | FileCheck %s +target datalayout = "e-p:32:32:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v64:64:64-v128:128:128-a0:0:64" + + + +; Cases that should be bitcast + +; Test cast between scalars with same bit sizes +@alias_i32_to_f32 = alias bitcast (i32 (i32)* @func_i32 to float (float)*) + +; Test cast between vectors with same number of elements and bit sizes +@alias_v2i32_to_v2f32 = alias bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <2 x float> (<2 x float>)*) + +; Test cast from vector to scalar with same number of bits +@alias_v2f32_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <2 x float> (<2 x float>)*) + +; Test cast from scalar to vector with same number of bits +@alias_i64_to_v2f32 = alias bitcast (<2 x float> (<2 x float>)* @func_v2f32 to i64 (i64)*) + +; Test cast between vectors of pointers +@alias_v2i32p_to_v2i64p = alias bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to <2 x i64*> (<2 x i64*>)*) + + +; Cases that should be invalid and unchanged + +; Test cast between scalars with different bit sizes +@alias_i64_to_f32 = alias bitcast (i64 (i64)* @func_i64 to float (float)*) + +; Test cast between vectors with different bit sizes but the +; same number of elements +@alias_v2i64_to_v2f32 = alias bitcast (<2 x i64> (<2 x i64>)* @func_v2i64 to <2 x float> (<2 x float>)*) + +; Test cast between vectors with same number of bits and different +; numbers of elements +@alias_v2i32_to_v4f32 = alias bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <4 x float> (<4 x float>)*) + +; Test cast between scalar and vector with different number of bits +@alias_i64_to_v4f32 = alias bitcast (<4 x float> (<4 x float>)* @func_v4f32 to i64 (i64)*) + +; Test cast between vector and scalar with different number of bits +@alias_v4f32_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <4 x float> (<4 x float>)*) + +; Test cast from scalar to vector of pointers with same number of bits +; We don't know the pointer size at this point, so this can't be done +@alias_i64_to_v2i32p = alias bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to i64 (i64)*) + +; Test cast between vector of pointers and scalar with different number of bits +@alias_v4i32p_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <4 x i32*> (<4 x i32*>)*) + + + +define internal <2 x i32> @func_v2i32(<2 x i32> %v) noinline nounwind { +entry: + ret <2 x i32> %v +} + +define internal <2 x float> @func_v2f32(<2 x float> %v) noinline nounwind { +entry: + ret <2 x float> %v +} + +define internal <4 x float> @func_v4f32(<4 x float> %v) noinline nounwind { +entry: + ret <4 x float> %v +} + +define internal i32 @func_i32(i32 %v) noinline nounwind { +entry: + ret i32 %v +} + +define internal i64 @func_i64(i64 %v) noinline nounwind { +entry: + ret i64 %v +} + +define internal <2 x i64> @func_v2i64(<2 x i64> %v) noinline nounwind { +entry: + ret <2 x i64> %v +} + +define internal <2 x i32*> @func_v2i32p(<2 x i32*> %v) noinline nounwind { +entry: + ret <2 x i32*> %v +} + +; Valid cases, only bitcast for argument / return type and call underlying function + +; Sizes match, should only bitcast +define void @bitcast_alias_scalar(float* noalias %source, float* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_scalar +; CHECK: bitcast float %tmp to i32 +; CHECK-NOT: fptoui +; CHECK-NOT: uitofp +; CHECK: bitcast i32 %call to float + %tmp = load float* %source, align 8 + %call = call float @alias_i32_to_f32(float %tmp) nounwind + store float %call, float* %dest, align 8 + ret void +} + +; Sizes match, should only bitcast +define void @bitcast_alias_vector(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_vector +; CHECK: bitcast <2 x float> %tmp to <2 x i32> +; CHECK-NOT: fptoui +; CHECK-NOT: uitofp +; CHECK: bitcast <2 x i32> %call to <2 x float> + %tmp = load <2 x float>* %source, align 8 + %call = call <2 x float> @alias_v2i32_to_v2f32(<2 x float> %tmp) nounwind + store <2 x float> %call, <2 x float>* %dest, align 8 + ret void +} + +; Sizes match, should only bitcast +define void @bitcast_alias_vector_scalar_same_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_vector_scalar_same_size +; CHECK: bitcast <2 x float> %tmp to i64 +; CHECK: %call = call i64 @func_i64 +; CHECK: bitcast i64 %call to <2 x float> + %tmp = load <2 x float>* %source, align 8 + %call = call <2 x float> @alias_v2f32_to_i64(<2 x float> %tmp) nounwind + store <2 x float> %call, <2 x float>* %dest, align 8 + ret void +} + +define void @bitcast_alias_scalar_vector_same_size(i64* noalias %source, i64* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_scalar_vector_same_size +; CHECK: bitcast i64 %tmp to <2 x float> +; CHECK: call <2 x float> @func_v2f32 +; CHECK: bitcast <2 x float> %call to i64 + %tmp = load i64* %source, align 8 + %call = call i64 @alias_i64_to_v2f32(i64 %tmp) nounwind + store i64 %call, i64* %dest, align 8 + ret void +} + +define void @bitcast_alias_vector_ptrs_same_size(<2 x i64*>* noalias %source, <2 x i64*>* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_vector_ptrs_same_size +; CHECK: bitcast <2 x i64*> %tmp to <2 x i32*> +; CHECK: call <2 x i32*> @func_v2i32p +; CHECK: bitcast <2 x i32*> %call to <2 x i64*> + %tmp = load <2 x i64*>* %source, align 8 + %call = call <2 x i64*> @alias_v2i32p_to_v2i64p(<2 x i64*> %tmp) nounwind + store <2 x i64*> %call, <2 x i64*>* %dest, align 8 + ret void +} + +; Invalid cases: + +define void @bitcast_alias_mismatch_scalar_size(float* noalias %source, float* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_mismatch_scalar_size +; CHECK-NOT: fptoui +; CHECK: @alias_i64_to_f32 +; CHECK-NOT: uitofp + %tmp = load float* %source, align 8 + %call = call float @alias_i64_to_f32(float %tmp) nounwind + store float %call, float* %dest, align 8 + ret void +} + +define void @bitcast_alias_mismatch_vector_element_and_bit_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_mismatch_vector_element_and_bit_size +; CHECK-NOT: fptoui <2 x float> %tmp to <2 x i64> +; CHECK: @alias_v2i64_to_v2f32 +; CHECK-NOT: uitofp <2 x i64> %call to <2 x float> + %tmp = load <2 x float>* %source, align 8 + %call = call <2 x float> @alias_v2i64_to_v2f32(<2 x float> %tmp) nounwind + store <2 x float> %call, <2 x float>* %dest, align 8 + ret void +} + +define void @bitcast_alias_vector_mismatched_number_elements(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_vector_mismatched_number_elements +; CHECK: %call = call <4 x float> @alias_v2i32_to_v4f32 + %tmp = load <4 x float>* %source, align 8 + %call = call <4 x float> @alias_v2i32_to_v4f32(<4 x float> %tmp) nounwind + store <4 x float> %call, <4 x float>* %dest, align 8 + ret void +} + +define void @bitcast_alias_vector_scalar_mismatched_bit_size(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_vector_scalar_mismatched_bit_size +; CHECK: %call = call <4 x float> @alias_v4f32_to_i64 + %tmp = load <4 x float>* %source, align 8 + %call = call <4 x float> @alias_v4f32_to_i64(<4 x float> %tmp) nounwind + store <4 x float> %call, <4 x float>* %dest, align 8 + ret void +} + +define void @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size(<4 x i32*>* noalias %source, <4 x i32*>* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size +; CHECK: @alias_v4i32p_to_i64 + %tmp = load <4 x i32*>* %source, align 8 + %call = call <4 x i32*> @alias_v4i32p_to_i64(<4 x i32*> %tmp) nounwind + store <4 x i32*> %call, <4 x i32*>* %dest, align 8 + ret void +} + +define void @bitcast_alias_scalar_vector_ptrs_same_size(i64* noalias %source, i64* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_scalar_vector_ptrs_same_size +; CHECK: @alias_i64_to_v2i32p + %tmp = load i64* %source, align 8 + %call = call i64 @alias_i64_to_v2i32p(i64 %tmp) nounwind + store i64 %call, i64* %dest, align 8 + ret void +} + +define void @bitcast_alias_scalar_vector_mismatched_bit_size(i64* noalias %source, i64* noalias %dest) nounwind { +entry: +; CHECK-LABEL: @bitcast_alias_scalar_vector_mismatched_bit_size +; CHECK: call i64 @alias_i64_to_v4f32 + %tmp = load i64* %source, align 8 + %call = call i64 @alias_i64_to_v4f32(i64 %tmp) nounwind + store i64 %call, i64* %dest, align 8 + ret void +} + diff --git a/test/Transforms/InstCombine/call-cast-target.ll b/test/Transforms/InstCombine/call-cast-target.ll index 1907421..315c516 100644 --- a/test/Transforms/InstCombine/call-cast-target.ll +++ b/test/Transforms/InstCombine/call-cast-target.ll @@ -3,14 +3,12 @@ target datalayout = "e-p:32:32" target triple = "i686-pc-linux-gnu" -; CHECK-NOT: bitcast -; CHECK: call -; CHECK-NOT: bitcast - define i32 @main() { +; CHECK-LABEL: @main +; CHECK: call i32 bitcast entry: - %tmp = call i32 bitcast (i8* (i32*)* @ctime to i32 (i32*)*)( i32* null ) ; <i32> [#uses=1] - ret i32 %tmp + %tmp = call i32 bitcast (i8* (i32*)* @ctime to i32 (i32*)*)( i32* null ) ; <i32> [#uses=1] + ret i32 %tmp } declare i8* @ctime(i32*) diff --git a/test/Transforms/InstCombine/call.ll b/test/Transforms/InstCombine/call.ll index 974a871..55833fb 100644 --- a/test/Transforms/InstCombine/call.ll +++ b/test/Transforms/InstCombine/call.ll @@ -7,92 +7,94 @@ target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:1 declare void @test1a(i8*) define void @test1(i32* %A) { - call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A ) - ret void +; CHECK-LABEL: @test1( ; CHECK: %1 = bitcast i32* %A to i8* ; CHECK: call void @test1a(i8* %1) ; CHECK: ret void + call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A ) + ret void } -; More complex case, translate argument because of resolution. This is safe +; More complex case, translate argument because of resolution. This is safe ; because we have the body of the function define void @test2a(i8 %A) { - ret void +; CHECK-LABEL: @test2a( ; CHECK: ret void + ret void } define i32 @test2(i32 %A) { - call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A ) - ret i32 %A -; CHECK: %1 = trunc i32 %A to i8 -; CHECK: call void @test2a(i8 %1) +; CHECK-LABEL: @test2( +; CHECK: call void bitcast ; CHECK: ret i32 %A + call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A ) + ret i32 %A } -; Resolving this should insert a cast from sbyte to int, following the C +; Resolving this should insert a cast from sbyte to int, following the C ; promotion rules. define void @test3a(i8, ...) {unreachable } define void @test3(i8 %A, i8 %B) { - call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B -) - ret void +; CHECK-LABEL: @test3( ; CHECK: %1 = zext i8 %B to i32 ; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %1) ; CHECK: ret void + call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B) + ret void } - ; test conversion of return value... define i8 @test4a() { - ret i8 0 +; CHECK-LABEL: @test4a( ; CHECK: ret i8 0 + ret i8 0 } define i32 @test4() { - %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1] - ret i32 %X -; CHECK: %X = call i8 @test4a() -; CHECK: %1 = zext i8 %X to i32 -; CHECK: ret i32 %1 +; CHECK-LABEL: @test4( +; CHECK: call i32 bitcast + %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1] + ret i32 %X } - -; test conversion of return value... no value conversion occurs so we can do +; test conversion of return value... no value conversion occurs so we can do ; this with just a prototype... declare i32 @test5a() define i32 @test5() { - %X = call i32 @test5a( ) ; <i32> [#uses=1] - ret i32 %X +; CHECK-LABEL: @test5( ; CHECK: %X = call i32 @test5a() ; CHECK: ret i32 %X + %X = call i32 @test5a( ) ; <i32> [#uses=1] + ret i32 %X } - ; test addition of new arguments... declare i32 @test6a(i32) define i32 @test6() { - %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( ) - ret i32 %X +; CHECK-LABEL: @test6( ; CHECK: %X = call i32 @test6a(i32 0) ; CHECK: ret i32 %X + %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( ) + ret i32 %X } - ; test removal of arguments, only can happen with a function body define void @test7a() { - ret void +; CHECK-LABEL: @test7a( ; CHECK: ret void + ret void } define void @test7() { - call void bitcast (void ()* @test7a to void (i32)*)( i32 5 ) - ret void +; CHECK-LABEL: @test7( ; CHECK: call void @test7a() ; CHECK: ret void + call void bitcast (void ()* @test7a to void (i32)*)( i32 5 ) + ret void } @@ -100,6 +102,11 @@ define void @test7() { declare void @test8a() define i8* @test8() { +; 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. invoke void @test8a() to label %invoke.cont unwind label %try.handler @@ -114,19 +121,13 @@ try.handler: ; preds = %entry declare i32 @__gxx_personality_v0(...) -; 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. -; CHECK: @test8() { -; CHECK-NEXT: invoke void @test8a() - - -; Don't turn this into a direct call, because test9x is just a prototype and +; Don't turn this into a direct call, because test9x is just a prototype and ; doing so will make it varargs. ; rdar://9038601 declare i8* @test9x(i8*, i8*, ...) noredzone define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone { +; CHECK-LABEL: @test9 entry: %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone ret i8* %call |