1 ; RUN: llc -mtriple=thumb-eabi -mcpu=arm1156t2-s -mattr=+thumb2 %s -o - | FileCheck %s
4 ; CHECK: pkhbt r0, r0, r1, lsl #16
5 define i32 @test1(i32 %X, i32 %Y) {
6 %tmp1 = and i32 %X, 65535 ; <i32> [#uses=1]
7 %tmp4 = shl i32 %Y, 16 ; <i32> [#uses=1]
8 %tmp5 = or i32 %tmp4, %tmp1 ; <i32> [#uses=1]
13 ; CHECK: pkhbt r0, r0, r1, lsl #16
14 define i32 @test1a(i32 %X, i32 %Y) {
15 %tmp19 = and i32 %X, 65535 ; <i32> [#uses=1]
16 %tmp37 = shl i32 %Y, 16 ; <i32> [#uses=1]
17 %tmp5 = or i32 %tmp37, %tmp19 ; <i32> [#uses=1]
22 ; CHECK: pkhbt r0, r0, r1, lsl #12
23 define i32 @test2(i32 %X, i32 %Y) {
24 %tmp1 = and i32 %X, 65535 ; <i32> [#uses=1]
25 %tmp3 = shl i32 %Y, 12 ; <i32> [#uses=1]
26 %tmp4 = and i32 %tmp3, -65536 ; <i32> [#uses=1]
27 %tmp57 = or i32 %tmp4, %tmp1 ; <i32> [#uses=1]
32 ; CHECK: pkhbt r0, r0, r1, lsl #18
33 define i32 @test3(i32 %X, i32 %Y) {
34 %tmp19 = and i32 %X, 65535 ; <i32> [#uses=1]
35 %tmp37 = shl i32 %Y, 18 ; <i32> [#uses=1]
36 %tmp5 = or i32 %tmp37, %tmp19 ; <i32> [#uses=1]
41 ; CHECK: pkhbt r0, r0, r1
42 define i32 @test4(i32 %X, i32 %Y) {
43 %tmp1 = and i32 %X, 65535 ; <i32> [#uses=1]
44 %tmp3 = and i32 %Y, -65536 ; <i32> [#uses=1]
45 %tmp46 = or i32 %tmp3, %tmp1 ; <i32> [#uses=1]
50 ; CHECK: pkhtb r0, r0, r1, asr #16
51 define i32 @test5(i32 %X, i32 %Y) {
52 %tmp17 = and i32 %X, -65536 ; <i32> [#uses=1]
53 %tmp2 = bitcast i32 %Y to i32 ; <i32> [#uses=1]
54 %tmp4 = lshr i32 %tmp2, 16 ; <i32> [#uses=2]
55 %tmp5 = or i32 %tmp4, %tmp17 ; <i32> [#uses=1]
60 ; CHECK: pkhtb r0, r0, r1, asr #16
61 define i32 @test5a(i32 %X, i32 %Y) {
62 %tmp110 = and i32 %X, -65536 ; <i32> [#uses=1]
63 %tmp37 = lshr i32 %Y, 16 ; <i32> [#uses=1]
64 %tmp39 = bitcast i32 %tmp37 to i32 ; <i32> [#uses=1]
65 %tmp5 = or i32 %tmp39, %tmp110 ; <i32> [#uses=1]
70 ; CHECK: pkhtb r0, r0, r1, asr #12
71 define i32 @test6(i32 %X, i32 %Y) {
72 %tmp1 = and i32 %X, -65536 ; <i32> [#uses=1]
73 %tmp37 = lshr i32 %Y, 12 ; <i32> [#uses=1]
74 %tmp38 = bitcast i32 %tmp37 to i32 ; <i32> [#uses=1]
75 %tmp4 = and i32 %tmp38, 65535 ; <i32> [#uses=1]
76 %tmp59 = or i32 %tmp4, %tmp1 ; <i32> [#uses=1]
81 ; CHECK: pkhtb r0, r0, r1, asr #18
82 define i32 @test7(i32 %X, i32 %Y) {
83 %tmp1 = and i32 %X, -65536 ; <i32> [#uses=1]
84 %tmp3 = ashr i32 %Y, 18 ; <i32> [#uses=1]
85 %tmp4 = and i32 %tmp3, 65535 ; <i32> [#uses=1]
86 %tmp57 = or i32 %tmp4, %tmp1 ; <i32> [#uses=1]
91 ; CHECK-NOT: pkhtb r0, r0, r1, asr #22
92 ; pkhtb does an arithmetic shift, not a logical shift. Make sure we don't
93 ; use it for problematic cases when whether sign bits would be shifted in
95 define i32 @test8(i32 %X, i32 %Y) {
96 %tmp1 = and i32 %X, -65536
97 %tmp3 = lshr i32 %Y, 22
98 %tmp57 = or i32 %tmp3, %tmp1
102 ; CHECK-LABEL: test9:
103 ; CHECK: pkhtb r0, r0, r1, asr #16
104 define i32 @test9(i32 %src1, i32 %src2) {
106 %tmp = and i32 %src1, -65536
107 %tmp2 = lshr i32 %src2, 16
108 %tmp3 = or i32 %tmp, %tmp2
113 ; CHECK: pkhtb r0, r0, r1, asr #22
114 define i32 @test10(i32 %X, i32 %Y) {
115 %tmp1 = and i32 %X, -65536
116 %tmp3 = ashr i32 %Y, 22
117 %tmp57 = or i32 %tmp3, %tmp1