1 ; RUN: llc < %s -march=thumb -mattr=+thumb2,+t2xtpk | FileCheck %s 2 3 ; CHECK: test1 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] 9 ret i32 %tmp5 10 } 11 12 ; CHECK: test1a 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] 18 ret i32 %tmp5 19 } 20 21 ; CHECK: test2 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] 28 ret i32 %tmp57 29 } 30 31 ; CHECK: test3 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] 37 ret i32 %tmp5 38 } 39 40 ; CHECK: test4 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] 46 ret i32 %tmp46 47 } 48 49 ; CHECK: test5 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] 56 ret i32 %tmp5 57 } 58 59 ; CHECK: test5a 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] 66 ret i32 %tmp5 67 } 68 69 ; CHECK: test6 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] 77 ret i32 %tmp59 78 } 79 80 ; CHECK: test7 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] 87 ret i32 %tmp57 88 } 89 90 ; CHECK: test8 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 94 ; would matter. 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 99 ret i32 %tmp57 100 } 101 102 ; CHECK-LABEL: test9: 103 ; CHECK: pkhtb r0, r0, r1, asr #16 104 define i32 @test9(i32 %src1, i32 %src2) { 105 entry: 106 %tmp = and i32 %src1, -65536 107 %tmp2 = lshr i32 %src2, 16 108 %tmp3 = or i32 %tmp, %tmp2 109 ret i32 %tmp3 110 } 111 112 ; CHECK: test10 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 118 ret i32 %tmp57 119 } 120 121