Artur Pilipenko | 41c0005 | 2017-01-25 08:53:31 +0000 | [diff] [blame^] | 1 | ; RUN: llc < %s -mtriple=arm64-unknown | FileCheck %s |
| 2 | |
| 3 | ; i8* p; // p is 1 byte aligned |
| 4 | ; (i32) p[0] | ((i32) p[1] << 8) | ((i32) p[2] << 16) | ((i32) p[3] << 24) |
| 5 | define i32 @load_i32_by_i8_unaligned(i32* %arg) { |
| 6 | ; CHECK-LABEL: load_i32_by_i8_unaligned: |
| 7 | ; CHECK: ldr w0, [x0] |
| 8 | ; CHECK-NEXT: ret |
| 9 | %tmp = bitcast i32* %arg to i8* |
| 10 | %tmp1 = getelementptr inbounds i8, i8* %tmp, i32 0 |
| 11 | %tmp2 = load i8, i8* %tmp, align 1 |
| 12 | %tmp3 = zext i8 %tmp2 to i32 |
| 13 | %tmp4 = getelementptr inbounds i8, i8* %tmp, i32 1 |
| 14 | %tmp5 = load i8, i8* %tmp4, align 1 |
| 15 | %tmp6 = zext i8 %tmp5 to i32 |
| 16 | %tmp7 = shl nuw nsw i32 %tmp6, 8 |
| 17 | %tmp8 = or i32 %tmp7, %tmp3 |
| 18 | %tmp9 = getelementptr inbounds i8, i8* %tmp, i32 2 |
| 19 | %tmp10 = load i8, i8* %tmp9, align 1 |
| 20 | %tmp11 = zext i8 %tmp10 to i32 |
| 21 | %tmp12 = shl nuw nsw i32 %tmp11, 16 |
| 22 | %tmp13 = or i32 %tmp8, %tmp12 |
| 23 | %tmp14 = getelementptr inbounds i8, i8* %tmp, i32 3 |
| 24 | %tmp15 = load i8, i8* %tmp14, align 1 |
| 25 | %tmp16 = zext i8 %tmp15 to i32 |
| 26 | %tmp17 = shl nuw nsw i32 %tmp16, 24 |
| 27 | %tmp18 = or i32 %tmp13, %tmp17 |
| 28 | ret i32 %tmp18 |
| 29 | } |
| 30 | |
| 31 | ; i8* p; // p is 4 byte aligned |
| 32 | ; (i32) p[0] | ((i32) p[1] << 8) | ((i32) p[2] << 16) | ((i32) p[3] << 24) |
| 33 | define i32 @load_i32_by_i8_aligned(i32* %arg) { |
| 34 | ; CHECK-LABEL: load_i32_by_i8_aligned: |
| 35 | ; CHECK: ldr w0, [x0] |
| 36 | ; CHECK-NEXT: ret |
| 37 | %tmp = bitcast i32* %arg to i8* |
| 38 | %tmp1 = getelementptr inbounds i8, i8* %tmp, i32 0 |
| 39 | %tmp2 = load i8, i8* %tmp, align 4 |
| 40 | %tmp3 = zext i8 %tmp2 to i32 |
| 41 | %tmp4 = getelementptr inbounds i8, i8* %tmp, i32 1 |
| 42 | %tmp5 = load i8, i8* %tmp4, align 1 |
| 43 | %tmp6 = zext i8 %tmp5 to i32 |
| 44 | %tmp7 = shl nuw nsw i32 %tmp6, 8 |
| 45 | %tmp8 = or i32 %tmp7, %tmp3 |
| 46 | %tmp9 = getelementptr inbounds i8, i8* %tmp, i32 2 |
| 47 | %tmp10 = load i8, i8* %tmp9, align 1 |
| 48 | %tmp11 = zext i8 %tmp10 to i32 |
| 49 | %tmp12 = shl nuw nsw i32 %tmp11, 16 |
| 50 | %tmp13 = or i32 %tmp8, %tmp12 |
| 51 | %tmp14 = getelementptr inbounds i8, i8* %tmp, i32 3 |
| 52 | %tmp15 = load i8, i8* %tmp14, align 1 |
| 53 | %tmp16 = zext i8 %tmp15 to i32 |
| 54 | %tmp17 = shl nuw nsw i32 %tmp16, 24 |
| 55 | %tmp18 = or i32 %tmp13, %tmp17 |
| 56 | ret i32 %tmp18 |
| 57 | } |
| 58 | |
| 59 | ; i8* p; // p is 4 byte aligned |
| 60 | ; ((i32) p[0] << 24) | ((i32) p[1] << 16) | ((i32) p[2] << 8) | (i32) p[3] |
| 61 | define i32 @load_i32_by_i8_bswap(i32* %arg) { |
| 62 | ; CHECK-LABEL: load_i32_by_i8_bswap: |
| 63 | ; CHECK: ldr w8, [x0] |
| 64 | ; CHECK-NEXT: rev w0, w8 |
| 65 | ; CHECK-NEXT: ret |
| 66 | %tmp = bitcast i32* %arg to i8* |
| 67 | %tmp1 = load i8, i8* %tmp, align 4 |
| 68 | %tmp2 = zext i8 %tmp1 to i32 |
| 69 | %tmp3 = shl nuw nsw i32 %tmp2, 24 |
| 70 | %tmp4 = getelementptr inbounds i8, i8* %tmp, i32 1 |
| 71 | %tmp5 = load i8, i8* %tmp4, align 1 |
| 72 | %tmp6 = zext i8 %tmp5 to i32 |
| 73 | %tmp7 = shl nuw nsw i32 %tmp6, 16 |
| 74 | %tmp8 = or i32 %tmp7, %tmp3 |
| 75 | %tmp9 = getelementptr inbounds i8, i8* %tmp, i32 2 |
| 76 | %tmp10 = load i8, i8* %tmp9, align 1 |
| 77 | %tmp11 = zext i8 %tmp10 to i32 |
| 78 | %tmp12 = shl nuw nsw i32 %tmp11, 8 |
| 79 | %tmp13 = or i32 %tmp8, %tmp12 |
| 80 | %tmp14 = getelementptr inbounds i8, i8* %tmp, i32 3 |
| 81 | %tmp15 = load i8, i8* %tmp14, align 1 |
| 82 | %tmp16 = zext i8 %tmp15 to i32 |
| 83 | %tmp17 = or i32 %tmp13, %tmp16 |
| 84 | ret i32 %tmp17 |
| 85 | } |
| 86 | |
| 87 | ; i8* p; // p is 8 byte aligned |
| 88 | ; (i64) p[0] | ((i64) p[1] << 8) | ((i64) p[2] << 16) | ((i64) p[3] << 24) | ((i64) p[4] << 32) | ((i64) p[5] << 40) | ((i64) p[6] << 48) | ((i64) p[7] << 56) |
| 89 | define i64 @load_i64_by_i8(i64* %arg) { |
| 90 | ; CHECK-LABEL: load_i64_by_i8: |
| 91 | ; CHECK: ldr x0, [x0] |
| 92 | ; CHECK-NEXT: ret |
| 93 | %tmp = bitcast i64* %arg to i8* |
| 94 | %tmp1 = load i8, i8* %tmp, align 8 |
| 95 | %tmp2 = zext i8 %tmp1 to i64 |
| 96 | %tmp3 = getelementptr inbounds i8, i8* %tmp, i64 1 |
| 97 | %tmp4 = load i8, i8* %tmp3, align 1 |
| 98 | %tmp5 = zext i8 %tmp4 to i64 |
| 99 | %tmp6 = shl nuw nsw i64 %tmp5, 8 |
| 100 | %tmp7 = or i64 %tmp6, %tmp2 |
| 101 | %tmp8 = getelementptr inbounds i8, i8* %tmp, i64 2 |
| 102 | %tmp9 = load i8, i8* %tmp8, align 1 |
| 103 | %tmp10 = zext i8 %tmp9 to i64 |
| 104 | %tmp11 = shl nuw nsw i64 %tmp10, 16 |
| 105 | %tmp12 = or i64 %tmp7, %tmp11 |
| 106 | %tmp13 = getelementptr inbounds i8, i8* %tmp, i64 3 |
| 107 | %tmp14 = load i8, i8* %tmp13, align 1 |
| 108 | %tmp15 = zext i8 %tmp14 to i64 |
| 109 | %tmp16 = shl nuw nsw i64 %tmp15, 24 |
| 110 | %tmp17 = or i64 %tmp12, %tmp16 |
| 111 | %tmp18 = getelementptr inbounds i8, i8* %tmp, i64 4 |
| 112 | %tmp19 = load i8, i8* %tmp18, align 1 |
| 113 | %tmp20 = zext i8 %tmp19 to i64 |
| 114 | %tmp21 = shl nuw nsw i64 %tmp20, 32 |
| 115 | %tmp22 = or i64 %tmp17, %tmp21 |
| 116 | %tmp23 = getelementptr inbounds i8, i8* %tmp, i64 5 |
| 117 | %tmp24 = load i8, i8* %tmp23, align 1 |
| 118 | %tmp25 = zext i8 %tmp24 to i64 |
| 119 | %tmp26 = shl nuw nsw i64 %tmp25, 40 |
| 120 | %tmp27 = or i64 %tmp22, %tmp26 |
| 121 | %tmp28 = getelementptr inbounds i8, i8* %tmp, i64 6 |
| 122 | %tmp29 = load i8, i8* %tmp28, align 1 |
| 123 | %tmp30 = zext i8 %tmp29 to i64 |
| 124 | %tmp31 = shl nuw nsw i64 %tmp30, 48 |
| 125 | %tmp32 = or i64 %tmp27, %tmp31 |
| 126 | %tmp33 = getelementptr inbounds i8, i8* %tmp, i64 7 |
| 127 | %tmp34 = load i8, i8* %tmp33, align 1 |
| 128 | %tmp35 = zext i8 %tmp34 to i64 |
| 129 | %tmp36 = shl nuw i64 %tmp35, 56 |
| 130 | %tmp37 = or i64 %tmp32, %tmp36 |
| 131 | ret i64 %tmp37 |
| 132 | } |
| 133 | |
| 134 | ; i8* p; // p is 8 byte aligned |
| 135 | ; ((i64) p[0] << 56) | ((i64) p[1] << 48) | ((i64) p[2] << 40) | ((i64) p[3] << 32) | ((i64) p[4] << 24) | ((i64) p[5] << 16) | ((i64) p[6] << 8) | (i64) p[7] |
| 136 | define i64 @load_i64_by_i8_bswap(i64* %arg) { |
| 137 | ; CHECK-LABEL: load_i64_by_i8_bswap: |
| 138 | ; CHECK: ldr x8, [x0] |
| 139 | ; CHECK-NEXT: rev x0, x8 |
| 140 | ; CHECK-NEXT: ret |
| 141 | %tmp = bitcast i64* %arg to i8* |
| 142 | %tmp1 = load i8, i8* %tmp, align 8 |
| 143 | %tmp2 = zext i8 %tmp1 to i64 |
| 144 | %tmp3 = shl nuw i64 %tmp2, 56 |
| 145 | %tmp4 = getelementptr inbounds i8, i8* %tmp, i64 1 |
| 146 | %tmp5 = load i8, i8* %tmp4, align 1 |
| 147 | %tmp6 = zext i8 %tmp5 to i64 |
| 148 | %tmp7 = shl nuw nsw i64 %tmp6, 48 |
| 149 | %tmp8 = or i64 %tmp7, %tmp3 |
| 150 | %tmp9 = getelementptr inbounds i8, i8* %tmp, i64 2 |
| 151 | %tmp10 = load i8, i8* %tmp9, align 1 |
| 152 | %tmp11 = zext i8 %tmp10 to i64 |
| 153 | %tmp12 = shl nuw nsw i64 %tmp11, 40 |
| 154 | %tmp13 = or i64 %tmp8, %tmp12 |
| 155 | %tmp14 = getelementptr inbounds i8, i8* %tmp, i64 3 |
| 156 | %tmp15 = load i8, i8* %tmp14, align 1 |
| 157 | %tmp16 = zext i8 %tmp15 to i64 |
| 158 | %tmp17 = shl nuw nsw i64 %tmp16, 32 |
| 159 | %tmp18 = or i64 %tmp13, %tmp17 |
| 160 | %tmp19 = getelementptr inbounds i8, i8* %tmp, i64 4 |
| 161 | %tmp20 = load i8, i8* %tmp19, align 1 |
| 162 | %tmp21 = zext i8 %tmp20 to i64 |
| 163 | %tmp22 = shl nuw nsw i64 %tmp21, 24 |
| 164 | %tmp23 = or i64 %tmp18, %tmp22 |
| 165 | %tmp24 = getelementptr inbounds i8, i8* %tmp, i64 5 |
| 166 | %tmp25 = load i8, i8* %tmp24, align 1 |
| 167 | %tmp26 = zext i8 %tmp25 to i64 |
| 168 | %tmp27 = shl nuw nsw i64 %tmp26, 16 |
| 169 | %tmp28 = or i64 %tmp23, %tmp27 |
| 170 | %tmp29 = getelementptr inbounds i8, i8* %tmp, i64 6 |
| 171 | %tmp30 = load i8, i8* %tmp29, align 1 |
| 172 | %tmp31 = zext i8 %tmp30 to i64 |
| 173 | %tmp32 = shl nuw nsw i64 %tmp31, 8 |
| 174 | %tmp33 = or i64 %tmp28, %tmp32 |
| 175 | %tmp34 = getelementptr inbounds i8, i8* %tmp, i64 7 |
| 176 | %tmp35 = load i8, i8* %tmp34, align 1 |
| 177 | %tmp36 = zext i8 %tmp35 to i64 |
| 178 | %tmp37 = or i64 %tmp33, %tmp36 |
| 179 | ret i64 %tmp37 |
| 180 | } |