|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | +; RUN: llc < %s -mtriple=x86_64-pc-linux-gnu -mattr=+zu | FileCheck %s --check-prefixes=CHECK,ZU |
| 3 | +; RUN: llc < %s -mtriple=x86_64-pc-linux-gnu | FileCheck %s --check-prefixes=CHECK,NOZU |
| 4 | + |
| 5 | +; Test generation of 16b imulzu when -mattr=+zu is specified. |
| 6 | +; The mulzu_* tests check for basic generation, which is limited to cases where a |
| 7 | +; zero-extend of the result can be folded into imulzu. |
| 8 | +; The remaining tests are modifications of selected test/CodeGen/X86/imul.ll tests with |
| 9 | +; 16b multiplies, to check that common strength reductions in ISel are still performed |
| 10 | +; when -mattr=+zu is in effect. |
| 11 | +; |
| 12 | +; FIXME: several cases from imul.ll covering DAG combines, in particular those using LEA, |
| 13 | +; are not ported as X86's IsDesirableToPromoteOp has no way to accurately identify when |
| 14 | +; promotion will permit a better sequence than an unpromoted imulzu. |
| 15 | +; These cases should be added when they are implemented. |
| 16 | + |
| 17 | +define i32 @mulzu_16_32(i16 %A) { |
| 18 | +; ZU-LABEL: mulzu_16_32: |
| 19 | +; ZU: # %bb.0: |
| 20 | +; ZU-NEXT: imulzuw $1234, %di, %ax # imm = 0x4D2 |
| 21 | +; ZU-NEXT: retq |
| 22 | +; |
| 23 | +; NOZU-LABEL: mulzu_16_32: |
| 24 | +; NOZU: # %bb.0: |
| 25 | +; NOZU-NEXT: imull $1234, %edi, %eax # imm = 0x4D2 |
| 26 | +; NOZU-NEXT: movzwl %ax, %eax |
| 27 | +; NOZU-NEXT: retq |
| 28 | + %mul = mul i16 %A, 1234 |
| 29 | + %r = zext i16 %mul to i32 |
| 30 | + ret i32 %r |
| 31 | +} |
| 32 | + |
| 33 | +define i64 @mulzu_16_64(i16 %A) { |
| 34 | +; ZU-LABEL: mulzu_16_64: |
| 35 | +; ZU: # %bb.0: |
| 36 | +; ZU-NEXT: imulzuw $1234, %di, %ax # imm = 0x4D2 |
| 37 | +; ZU-NEXT: retq |
| 38 | +; |
| 39 | +; NOZU-LABEL: mulzu_16_64: |
| 40 | +; NOZU: # %bb.0: |
| 41 | +; NOZU-NEXT: imull $1234, %edi, %eax # imm = 0x4D2 |
| 42 | +; NOZU-NEXT: movzwl %ax, %eax |
| 43 | +; NOZU-NEXT: retq |
| 44 | + %mul = mul i16 %A, 1234 |
| 45 | + %r = zext i16 %mul to i64 |
| 46 | + ret i64 %r |
| 47 | +} |
| 48 | + |
| 49 | +define i32 @mulzu_16_32_mem(ptr %P) { |
| 50 | +; ZU-LABEL: mulzu_16_32_mem: |
| 51 | +; ZU: # %bb.0: |
| 52 | +; ZU-NEXT: imulzuw $1234, (%rdi), %ax # imm = 0x4D2 |
| 53 | +; ZU-NEXT: retq |
| 54 | +; |
| 55 | +; NOZU-LABEL: mulzu_16_32_mem: |
| 56 | +; NOZU: # %bb.0: |
| 57 | +; NOZU-NEXT: movzwl (%rdi), %eax |
| 58 | +; NOZU-NEXT: imull $1234, %eax, %eax # imm = 0x4D2 |
| 59 | +; NOZU-NEXT: movzwl %ax, %eax |
| 60 | +; NOZU-NEXT: retq |
| 61 | + %gep = getelementptr i16, ptr %P, i64 0 |
| 62 | + %A = load i16, ptr %gep |
| 63 | + %mul = mul i16 %A, 1234 |
| 64 | + %r = zext i16 %mul to i32 |
| 65 | + ret i32 %r |
| 66 | +} |
| 67 | + |
| 68 | +define i64 @mulzu_16_64_mem(ptr %P) { |
| 69 | +; ZU-LABEL: mulzu_16_64_mem: |
| 70 | +; ZU: # %bb.0: |
| 71 | +; ZU-NEXT: imulzuw $1234, (%rdi), %ax # imm = 0x4D2 |
| 72 | +; ZU-NEXT: retq |
| 73 | +; |
| 74 | +; NOZU-LABEL: mulzu_16_64_mem: |
| 75 | +; NOZU: # %bb.0: |
| 76 | +; NOZU-NEXT: movzwl (%rdi), %eax |
| 77 | +; NOZU-NEXT: imull $1234, %eax, %eax # imm = 0x4D2 |
| 78 | +; NOZU-NEXT: movzwl %ax, %eax |
| 79 | +; NOZU-NEXT: retq |
| 80 | + %gep = getelementptr i16, ptr %P, i64 0 |
| 81 | + %A = load i16, ptr %gep |
| 82 | + %mul = mul i16 %A, 1234 |
| 83 | + %r = zext i16 %mul to i64 |
| 84 | + ret i64 %r |
| 85 | +} |
| 86 | + |
| 87 | +; The following mulzu cases check that imulzu is not |
| 88 | +; generated in the absence of a single zext user. The ZU/NOZU |
| 89 | +; cases should match. |
| 90 | + |
| 91 | +define void @mulzu_16_store(i16 %A, ptr %R) { |
| 92 | +; CHECK-LABEL: mulzu_16_store: |
| 93 | +; CHECK: # %bb.0: |
| 94 | +; CHECK-NEXT: imull $1234, %edi, %eax # imm = 0x4D2 |
| 95 | +; CHECK-NEXT: movw %ax, (%rsi) |
| 96 | +; CHECK-NEXT: retq |
| 97 | + %gep = getelementptr i16, ptr %R, i64 0 |
| 98 | + %mul = mul i16 %A, 1234 |
| 99 | + store i16 %mul, ptr %gep |
| 100 | + ret void |
| 101 | +} |
| 102 | + |
| 103 | +define i32 @mulzu_16_store_32(i16 %A, ptr %R) { |
| 104 | +; CHECK-LABEL: mulzu_16_store_32: |
| 105 | +; CHECK: # %bb.0: |
| 106 | +; CHECK-NEXT: imull $1234, %edi, %eax # imm = 0x4D2 |
| 107 | +; CHECK-NEXT: movw %ax, (%rsi) |
| 108 | +; CHECK-NEXT: movzwl %ax, %eax |
| 109 | +; CHECK-NEXT: retq |
| 110 | + %gep = getelementptr i16, ptr %R, i64 0 |
| 111 | + %mul = mul i16 %A, 1234 |
| 112 | + store i16 %mul, ptr %gep |
| 113 | + %r = zext i16 %mul to i32 |
| 114 | + ret i32 %r |
| 115 | +} |
| 116 | + |
| 117 | +define i64 @mulzu_16_store_64(i16 %A, ptr %R) { |
| 118 | +; CHECK-LABEL: mulzu_16_store_64: |
| 119 | +; CHECK: # %bb.0: |
| 120 | +; CHECK-NEXT: imull $1234, %edi, %eax # imm = 0x4D2 |
| 121 | +; CHECK-NEXT: movw %ax, (%rsi) |
| 122 | +; CHECK-NEXT: movzwl %ax, %eax |
| 123 | +; CHECK-NEXT: retq |
| 124 | + %gep = getelementptr i16, ptr %R, i64 0 |
| 125 | + %mul = mul i16 %A, 1234 |
| 126 | + store i16 %mul, ptr %gep |
| 127 | + %r = zext i16 %mul to i64 |
| 128 | + ret i64 %r |
| 129 | +} |
| 130 | + |
| 131 | +define i32 @mulzu_sext_16_32(i16 %A) { |
| 132 | +; CHECK-LABEL: mulzu_sext_16_32: |
| 133 | +; CHECK: # %bb.0: |
| 134 | +; CHECK-NEXT: imull $1234, %edi, %eax # imm = 0x4D2 |
| 135 | +; CHECK-NEXT: cwtl |
| 136 | +; CHECK-NEXT: retq |
| 137 | + %mul = mul i16 %A, 1234 |
| 138 | + %r = sext i16 %mul to i32 |
| 139 | + ret i32 %r |
| 140 | +} |
| 141 | + |
| 142 | +define i64 @mulzu_sext_16_64(i16 %A) { |
| 143 | +; CHECK-LABEL: mulzu_sext_16_64: |
| 144 | +; CHECK: # %bb.0: |
| 145 | +; CHECK-NEXT: imull $1234, %edi, %eax # imm = 0x4D2 |
| 146 | +; CHECK-NEXT: movswq %ax, %rax |
| 147 | +; CHECK-NEXT: retq |
| 148 | + %mul = mul i16 %A, 1234 |
| 149 | + %r = sext i16 %mul to i64 |
| 150 | + ret i64 %r |
| 151 | +} |
| 152 | + |
| 153 | +; Tests ported from test/CodeGen/X86/imul.ll follow from this point. |
| 154 | +; The generated code, which strength-reduces multiplies by certain |
| 155 | +; constants, should be unaffected by enabling zu. |
| 156 | + |
| 157 | +define i16 @mul4_16(i16 %A) { |
| 158 | +; |
| 159 | +; CHECK-LABEL: mul4_16: |
| 160 | +; CHECK: # %bb.0: |
| 161 | +; CHECK-NEXT: # kill: def $edi killed $edi def $rdi |
| 162 | +; CHECK-NEXT: leal (,%rdi,4), %eax |
| 163 | +; CHECK-NEXT: # kill: def $ax killed $ax killed $eax |
| 164 | +; CHECK-NEXT: retq |
| 165 | + %mul = mul i16 %A, 4 |
| 166 | + ret i16 %mul |
| 167 | +} |
| 168 | + |
| 169 | +define i16 @mul4096_16(i16 %A) { |
| 170 | +; |
| 171 | +; CHECK-LABEL: mul4096_16: |
| 172 | +; CHECK: # %bb.0: |
| 173 | +; CHECK-NEXT: movl %edi, %eax |
| 174 | +; CHECK-NEXT: shll $12, %eax |
| 175 | +; CHECK-NEXT: # kill: def $ax killed $ax killed $eax |
| 176 | +; CHECK-NEXT: retq |
| 177 | + %mul = mul i16 %A, 4096 |
| 178 | + ret i16 %mul |
| 179 | +} |
| 180 | + |
| 181 | +define i16 @mulmin4096_16(i16 %A) { |
| 182 | +; |
| 183 | +; CHECK-LABEL: mulmin4096_16: |
| 184 | +; CHECK: # %bb.0: |
| 185 | +; CHECK-NEXT: movl %edi, %eax |
| 186 | +; CHECK-NEXT: shll $12, %eax |
| 187 | +; CHECK-NEXT: negl %eax |
| 188 | +; CHECK-NEXT: # kill: def $ax killed $ax killed $eax |
| 189 | +; CHECK-NEXT: retq |
| 190 | + %mul = mul i16 %A, -4096 |
| 191 | + ret i16 %mul |
| 192 | +} |
| 193 | + |
| 194 | +define i16 @mul4_16_minsize(i16 %A) minsize { |
| 195 | +; |
| 196 | +; CHECK-LABEL: mul4_16_minsize: |
| 197 | +; CHECK: # %bb.0: |
| 198 | +; CHECK-NEXT: # kill: def $edi killed $edi def $rdi |
| 199 | +; CHECK-NEXT: leal (,%rdi,4), %eax |
| 200 | +; CHECK-NEXT: # kill: def $ax killed $ax killed $eax |
| 201 | +; CHECK-NEXT: retq |
| 202 | + %mul = mul i16 %A, 4 |
| 203 | + ret i16 %mul |
| 204 | +} |
| 205 | + |
| 206 | +define i16 @mul0_16(i16 %A) { |
| 207 | +; |
| 208 | +; CHECK-LABEL: mul0_16: |
| 209 | +; CHECK: # %bb.0: |
| 210 | +; CHECK-NEXT: xorl %eax, %eax |
| 211 | +; CHECK-NEXT: retq |
| 212 | + %mul = mul i16 %A, 0 |
| 213 | + ret i16 %mul |
| 214 | +} |
| 215 | + |
| 216 | +define i16 @mul4294967295_16(i16 %A) { |
| 217 | +; |
| 218 | +; CHECK-LABEL: mul4294967295_16: |
| 219 | +; CHECK: # %bb.0: |
| 220 | +; CHECK-NEXT: movl %edi, %eax |
| 221 | +; CHECK-NEXT: negl %eax |
| 222 | +; CHECK-NEXT: # kill: def $ax killed $ax killed $eax |
| 223 | +; CHECK-NEXT: retq |
| 224 | + %mul = mul i16 %A, 4294967295 |
| 225 | + ret i16 %mul |
| 226 | +} |
0 commit comments