1; RUN: opt < %s -instcombine -S | FileCheck %s 2 3; Bitcasts between vectors and scalars are valid. 4; PR4487 5define i32 @test1(i64 %a) { 6 %t1 = bitcast i64 %a to <2 x i32> 7 %t2 = bitcast i64 %a to <2 x i32> 8 %t3 = xor <2 x i32> %t1, %t2 9 %t4 = extractelement <2 x i32> %t3, i32 0 10 ret i32 %t4 11 12; CHECK: @test1 13; CHECK: ret i32 0 14} 15 16; Optimize bitcasts that are extracting low element of vector. This happens 17; because of SRoA. 18; rdar://7892780 19define float @test2(<2 x float> %A, <2 x i32> %B) { 20 %tmp28 = bitcast <2 x float> %A to i64 ; <i64> [#uses=2] 21 %tmp23 = trunc i64 %tmp28 to i32 ; <i32> [#uses=1] 22 %tmp24 = bitcast i32 %tmp23 to float ; <float> [#uses=1] 23 24 %tmp = bitcast <2 x i32> %B to i64 25 %tmp2 = trunc i64 %tmp to i32 ; <i32> [#uses=1] 26 %tmp4 = bitcast i32 %tmp2 to float ; <float> [#uses=1] 27 28 %add = fadd float %tmp24, %tmp4 29 ret float %add 30 31; CHECK: @test2 32; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 0 33; CHECK-NEXT: bitcast <2 x i32> %B to <2 x float> 34; CHECK-NEXT: %tmp4 = extractelement <2 x float> {{.*}}, i32 0 35; CHECK-NEXT: %add = fadd float %tmp24, %tmp4 36; CHECK-NEXT: ret float %add 37} 38 39; Optimize bitcasts that are extracting other elements of a vector. This 40; happens because of SRoA. 41; rdar://7892780 42define float @test3(<2 x float> %A, <2 x i64> %B) { 43 %tmp28 = bitcast <2 x float> %A to i64 44 %tmp29 = lshr i64 %tmp28, 32 45 %tmp23 = trunc i64 %tmp29 to i32 46 %tmp24 = bitcast i32 %tmp23 to float 47 48 %tmp = bitcast <2 x i64> %B to i128 49 %tmp1 = lshr i128 %tmp, 64 50 %tmp2 = trunc i128 %tmp1 to i32 51 %tmp4 = bitcast i32 %tmp2 to float 52 53 %add = fadd float %tmp24, %tmp4 54 ret float %add 55 56; CHECK: @test3 57; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 1 58; CHECK-NEXT: bitcast <2 x i64> %B to <4 x float> 59; CHECK-NEXT: %tmp4 = extractelement <4 x float> {{.*}}, i32 2 60; CHECK-NEXT: %add = fadd float %tmp24, %tmp4 61; CHECK-NEXT: ret float %add 62} 63 64 65define <2 x i32> @test4(i32 %A, i32 %B){ 66 %tmp38 = zext i32 %A to i64 67 %tmp32 = zext i32 %B to i64 68 %tmp33 = shl i64 %tmp32, 32 69 %ins35 = or i64 %tmp33, %tmp38 70 %tmp43 = bitcast i64 %ins35 to <2 x i32> 71 ret <2 x i32> %tmp43 72 ; CHECK: @test4 73 ; CHECK-NEXT: insertelement <2 x i32> undef, i32 %A, i32 0 74 ; CHECK-NEXT: insertelement <2 x i32> {{.*}}, i32 %B, i32 1 75 ; CHECK-NEXT: ret <2 x i32> 76 77} 78 79; rdar://8360454 80define <2 x float> @test5(float %A, float %B) { 81 %tmp37 = bitcast float %A to i32 82 %tmp38 = zext i32 %tmp37 to i64 83 %tmp31 = bitcast float %B to i32 84 %tmp32 = zext i32 %tmp31 to i64 85 %tmp33 = shl i64 %tmp32, 32 86 %ins35 = or i64 %tmp33, %tmp38 87 %tmp43 = bitcast i64 %ins35 to <2 x float> 88 ret <2 x float> %tmp43 89 ; CHECK: @test5 90 ; CHECK-NEXT: insertelement <2 x float> undef, float %A, i32 0 91 ; CHECK-NEXT: insertelement <2 x float> {{.*}}, float %B, i32 1 92 ; CHECK-NEXT: ret <2 x float> 93} 94 95define <2 x float> @test6(float %A){ 96 %tmp23 = bitcast float %A to i32 ; <i32> [#uses=1] 97 %tmp24 = zext i32 %tmp23 to i64 ; <i64> [#uses=1] 98 %tmp25 = shl i64 %tmp24, 32 ; <i64> [#uses=1] 99 %mask20 = or i64 %tmp25, 1109917696 ; <i64> [#uses=1] 100 %tmp35 = bitcast i64 %mask20 to <2 x float> ; <<2 x float>> [#uses=1] 101 ret <2 x float> %tmp35 102; CHECK: @test6 103; CHECK-NEXT: insertelement <2 x float> <float 4.200000e+01, float undef>, float %A, i32 1 104; CHECK: ret 105} 106