From 33942aedc592969d6a780db6ae3a48200fe8cd70 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 15 Nov 2016 16:01:16 +0000 Subject: [PATCH] [InstCombine] add tests for bitcasted selects; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286978 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/bitcast.ll | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/Transforms/InstCombine/bitcast.ll b/test/Transforms/InstCombine/bitcast.ll index e87646a3a66..8d8c25a1095 100644 --- a/test/Transforms/InstCombine/bitcast.ll +++ b/test/Transforms/InstCombine/bitcast.ll @@ -113,6 +113,90 @@ define <4 x i32> @bitcast_xor_bitcast(<4 x i32> %a, i128 %b) { ret <4 x i32> %bc2 } +; FIXME: Change the type of the vector select to eliminate 2 bitcasts. +; https://llvm.org/bugs/show_bug.cgi?id=6137#c6 + +define <4 x float> @bitcast_vector_select(<4 x float> %x, <2 x i64> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @bitcast_vector_select( +; CHECK-NEXT: [[T4:%.*]] = bitcast <4 x float> %x to <4 x i32> +; CHECK-NEXT: [[T5:%.*]] = bitcast <2 x i64> %y to <4 x i32> +; CHECK-NEXT: [[T6:%.*]] = select <4 x i1> %cmp, <4 x i32> [[T4]], <4 x i32> [[T5]] +; CHECK-NEXT: [[T7:%.*]] = bitcast <4 x i32> [[T6]] to <4 x float> +; CHECK-NEXT: ret <4 x float> [[T7]] +; + %t4 = bitcast <4 x float> %x to <4 x i32> + %t5 = bitcast <2 x i64> %y to <4 x i32> + %t6 = select <4 x i1> %cmp, <4 x i32> %t4, <4 x i32> %t5 + %t7 = bitcast <4 x i32> %t6 to <4 x float> + ret <4 x float> %t7 +} + +; FIXME: Change the type of the scalar select to eliminate a bitcast. + +define float @bitcast_scalar_select(float %x, <4 x i8> %y, i1 %cmp) { +; CHECK-LABEL: @bitcast_scalar_select( +; CHECK-NEXT: [[T4:%.*]] = bitcast float %x to <4 x i8> +; CHECK-NEXT: [[T6:%.*]] = select i1 %cmp, <4 x i8> [[T4]], <4 x i8> %y +; CHECK-NEXT: [[T7:%.*]] = bitcast <4 x i8> [[T6]] to float +; CHECK-NEXT: ret float [[T7]] +; + %t4 = bitcast float %x to <4 x i8> + %t6 = select i1 %cmp, <4 x i8> %t4, <4 x i8> %y + %t7 = bitcast <4 x i8> %t6 to float + ret float %t7 +} + +; FIXME: Change the type of the scalar select of vectors to eliminate 2 bitcasts. + +define <4 x float> @bitcast_scalar_select_of_vectors(<4 x float> %x, <2 x i64> %y, i1 %cmp) { +; CHECK-LABEL: @bitcast_scalar_select_of_vectors( +; CHECK-NEXT: [[T4:%.*]] = bitcast <4 x float> %x to <4 x i32> +; CHECK-NEXT: [[T5:%.*]] = bitcast <2 x i64> %y to <4 x i32> +; CHECK-NEXT: [[T6:%.*]] = select i1 %cmp, <4 x i32> [[T4]], <4 x i32> [[T5]] +; CHECK-NEXT: [[T7:%.*]] = bitcast <4 x i32> [[T6]] to <4 x float> +; CHECK-NEXT: ret <4 x float> [[T7]] +; + %t4 = bitcast <4 x float> %x to <4 x i32> + %t5 = bitcast <2 x i64> %y to <4 x i32> + %t6 = select i1 %cmp, <4 x i32> %t4, <4 x i32> %t5 + %t7 = bitcast <4 x i32> %t6 to <4 x float> + ret <4 x float> %t7 +} + +; Can't change the type of the vector select if the dest type is scalar. + +define float @bitcast_vector_select_no_fold1(float %x, <2 x i16> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @bitcast_vector_select_no_fold1( +; CHECK-NEXT: [[T4:%.*]] = bitcast float %x to <4 x i8> +; CHECK-NEXT: [[T5:%.*]] = bitcast <2 x i16> %y to <4 x i8> +; CHECK-NEXT: [[T6:%.*]] = select <4 x i1> %cmp, <4 x i8> [[T4]], <4 x i8> [[T5]] +; CHECK-NEXT: [[T7:%.*]] = bitcast <4 x i8> [[T6]] to float +; CHECK-NEXT: ret float [[T7]] +; + %t4 = bitcast float %x to <4 x i8> + %t5 = bitcast <2 x i16> %y to <4 x i8> + %t6 = select <4 x i1> %cmp, <4 x i8> %t4, <4 x i8> %t5 + %t7 = bitcast <4 x i8> %t6 to float + ret float %t7 +} + +; Can't change the type of the vector select if the number of elements in the dest type is not the same. + +define <2 x float> @bitcast_vector_select_no_fold2(<2 x float> %x, <4 x i16> %y, <8 x i1> %cmp) { +; CHECK-LABEL: @bitcast_vector_select_no_fold2( +; CHECK-NEXT: [[T4:%.*]] = bitcast <2 x float> %x to <8 x i8> +; CHECK-NEXT: [[T5:%.*]] = bitcast <4 x i16> %y to <8 x i8> +; CHECK-NEXT: [[T6:%.*]] = select <8 x i1> %cmp, <8 x i8> [[T4]], <8 x i8> [[T5]] +; CHECK-NEXT: [[T7:%.*]] = bitcast <8 x i8> [[T6]] to <2 x float> +; CHECK-NEXT: ret <2 x float> [[T7]] +; + %t4 = bitcast <2 x float> %x to <8 x i8> + %t5 = bitcast <4 x i16> %y to <8 x i8> + %t6 = select <8 x i1> %cmp, <8 x i8> %t4, <8 x i8> %t5 + %t7 = bitcast <8 x i8> %t6 to <2 x float> + ret <2 x float> %t7 +} + ; Optimize bitcasts that are extracting low element of vector. This happens because of SRoA. ; rdar://7892780 define float @test2(<2 x float> %A, <2 x i32> %B) { -- 2.11.0