Chris Lattner | 87be16a | 2010-10-05 06:04:14 +0000 | [diff] [blame] | 1 | //===- X86InstrCompiler.td - Compiler Pseudos and Patterns -*- tablegen -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file describes the various pseudo instructions used by the compiler, |
| 11 | // as well as Pat patterns used during instruction selection. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | 41efbfa | 2010-10-05 06:37:31 +0000 | [diff] [blame] | 15 | //===----------------------------------------------------------------------===// |
| 16 | // Pattern Matching Support |
| 17 | |
| 18 | def GetLo32XForm : SDNodeXForm<imm, [{ |
| 19 | // Transformation function: get the low 32 bits. |
| 20 | return getI32Imm((unsigned)N->getZExtValue()); |
| 21 | }]>; |
| 22 | |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | // Random Pseudo Instructions. |
| 26 | |
Chris Lattner | 8af88ef | 2010-10-05 06:10:16 +0000 | [diff] [blame] | 27 | // PIC base construction. This expands to code that looks like this: |
| 28 | // call $next_inst |
| 29 | // popl %destreg" |
| 30 | let neverHasSideEffects = 1, isNotDuplicable = 1, Uses = [ESP] in |
| 31 | def MOVPC32r : Ii32<0xE8, Pseudo, (outs GR32:$reg), (ins i32imm:$label), |
| 32 | "", []>; |
| 33 | |
| 34 | |
| 35 | // ADJCALLSTACKDOWN/UP implicitly use/def ESP because they may be expanded into |
| 36 | // a stack adjustment and the codegen must know that they may modify the stack |
| 37 | // pointer before prolog-epilog rewriting occurs. |
| 38 | // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become |
| 39 | // sub / add which can clobber EFLAGS. |
| 40 | let Defs = [ESP, EFLAGS], Uses = [ESP] in { |
| 41 | def ADJCALLSTACKDOWN32 : I<0, Pseudo, (outs), (ins i32imm:$amt), |
| 42 | "#ADJCALLSTACKDOWN", |
| 43 | [(X86callseq_start timm:$amt)]>, |
| 44 | Requires<[In32BitMode]>; |
| 45 | def ADJCALLSTACKUP32 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2), |
| 46 | "#ADJCALLSTACKUP", |
| 47 | [(X86callseq_end timm:$amt1, timm:$amt2)]>, |
| 48 | Requires<[In32BitMode]>; |
| 49 | } |
| 50 | |
| 51 | // ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into |
| 52 | // a stack adjustment and the codegen must know that they may modify the stack |
| 53 | // pointer before prolog-epilog rewriting occurs. |
| 54 | // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become |
| 55 | // sub / add which can clobber EFLAGS. |
| 56 | let Defs = [RSP, EFLAGS], Uses = [RSP] in { |
| 57 | def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt), |
| 58 | "#ADJCALLSTACKDOWN", |
| 59 | [(X86callseq_start timm:$amt)]>, |
| 60 | Requires<[In64BitMode]>; |
| 61 | def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2), |
| 62 | "#ADJCALLSTACKUP", |
| 63 | [(X86callseq_end timm:$amt1, timm:$amt2)]>, |
| 64 | Requires<[In64BitMode]>; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | |
| 69 | // x86-64 va_start lowering magic. |
| 70 | let usesCustomInserter = 1 in { |
| 71 | def VASTART_SAVE_XMM_REGS : I<0, Pseudo, |
| 72 | (outs), |
| 73 | (ins GR8:$al, |
| 74 | i64imm:$regsavefi, i64imm:$offset, |
| 75 | variable_ops), |
| 76 | "#VASTART_SAVE_XMM_REGS $al, $regsavefi, $offset", |
| 77 | [(X86vastart_save_xmm_regs GR8:$al, |
| 78 | imm:$regsavefi, |
| 79 | imm:$offset)]>; |
| 80 | |
| 81 | // Dynamic stack allocation yields _alloca call for Cygwin/Mingw targets. Calls |
| 82 | // to _alloca is needed to probe the stack when allocating more than 4k bytes in |
| 83 | // one go. Touching the stack at 4K increments is necessary to ensure that the |
| 84 | // guard pages used by the OS virtual memory manager are allocated in correct |
| 85 | // sequence. |
| 86 | // The main point of having separate instruction are extra unmodelled effects |
| 87 | // (compared to ordinary calls) like stack pointer change. |
| 88 | |
| 89 | let Defs = [EAX, ESP, EFLAGS], Uses = [ESP] in |
| 90 | def MINGW_ALLOCA : I<0, Pseudo, (outs), (ins), |
| 91 | "# dynamic stack allocation", |
| 92 | [(X86MingwAlloca)]>; |
| 93 | } |
| 94 | |
| 95 | |
Chris Lattner | 87be16a | 2010-10-05 06:04:14 +0000 | [diff] [blame] | 96 | |
| 97 | //===----------------------------------------------------------------------===// |
| 98 | // EH Pseudo Instructions |
| 99 | // |
| 100 | let isTerminator = 1, isReturn = 1, isBarrier = 1, |
| 101 | hasCtrlDep = 1, isCodeGenOnly = 1 in { |
| 102 | def EH_RETURN : I<0xC3, RawFrm, (outs), (ins GR32:$addr), |
| 103 | "ret\t#eh_return, addr: $addr", |
| 104 | [(X86ehret GR32:$addr)]>; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | let isTerminator = 1, isReturn = 1, isBarrier = 1, |
| 109 | hasCtrlDep = 1, isCodeGenOnly = 1 in { |
| 110 | def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr), |
| 111 | "ret\t#eh_return, addr: $addr", |
| 112 | [(X86ehret GR64:$addr)]>; |
| 113 | |
| 114 | } |
| 115 | |
Chris Lattner | 8af88ef | 2010-10-05 06:10:16 +0000 | [diff] [blame] | 116 | //===----------------------------------------------------------------------===// |
| 117 | // Alias Instructions |
| 118 | //===----------------------------------------------------------------------===// |
| 119 | |
| 120 | // Alias instructions that map movr0 to xor. |
| 121 | // FIXME: remove when we can teach regalloc that xor reg, reg is ok. |
| 122 | // FIXME: Set encoding to pseudo. |
| 123 | let Defs = [EFLAGS], isReMaterializable = 1, isAsCheapAsAMove = 1, |
| 124 | isCodeGenOnly = 1 in { |
| 125 | def MOV8r0 : I<0x30, MRMInitReg, (outs GR8 :$dst), (ins), "", |
| 126 | [(set GR8:$dst, 0)]>; |
| 127 | |
| 128 | // We want to rewrite MOV16r0 in terms of MOV32r0, because it's a smaller |
| 129 | // encoding and avoids a partial-register update sometimes, but doing so |
| 130 | // at isel time interferes with rematerialization in the current register |
| 131 | // allocator. For now, this is rewritten when the instruction is lowered |
| 132 | // to an MCInst. |
| 133 | def MOV16r0 : I<0x31, MRMInitReg, (outs GR16:$dst), (ins), |
| 134 | "", |
| 135 | [(set GR16:$dst, 0)]>, OpSize; |
| 136 | |
| 137 | // FIXME: Set encoding to pseudo. |
| 138 | def MOV32r0 : I<0x31, MRMInitReg, (outs GR32:$dst), (ins), "", |
| 139 | [(set GR32:$dst, 0)]>; |
| 140 | } |
| 141 | |
Chris Lattner | 010496c | 2010-10-05 06:22:35 +0000 | [diff] [blame] | 142 | // We want to rewrite MOV64r0 in terms of MOV32r0, because it's sometimes a |
| 143 | // smaller encoding, but doing so at isel time interferes with rematerialization |
| 144 | // in the current register allocator. For now, this is rewritten when the |
| 145 | // instruction is lowered to an MCInst. |
| 146 | // FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove |
| 147 | // when we have a better way to specify isel priority. |
| 148 | let Defs = [EFLAGS], |
| 149 | AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in |
| 150 | def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins), "", |
| 151 | [(set GR64:$dst, 0)]>; |
| 152 | |
| 153 | // Materialize i64 constant where top 32-bits are zero. This could theoretically |
| 154 | // use MOV32ri with a SUBREG_TO_REG to represent the zero-extension, however |
| 155 | // that would make it more difficult to rematerialize. |
| 156 | let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in |
| 157 | def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src), |
| 158 | "", [(set GR64:$dst, i64immZExt32:$src)]>; |
| 159 | |
Chris Lattner | 35649fc | 2010-10-05 06:33:16 +0000 | [diff] [blame] | 160 | |
| 161 | // Use sbb to materialize carry flag into a GPR. |
| 162 | // FIXME: This are pseudo ops that should be replaced with Pat<> patterns. |
| 163 | // However, Pat<> can't replicate the destination reg into the inputs of the |
| 164 | // result. |
| 165 | // FIXME: Change this to have encoding Pseudo when X86MCCodeEmitter replaces |
| 166 | // X86CodeEmitter. |
| 167 | let Defs = [EFLAGS], Uses = [EFLAGS], isCodeGenOnly = 1 in |
| 168 | def SETB_C64r : RI<0x19, MRMInitReg, (outs GR64:$dst), (ins), "", |
| 169 | [(set GR64:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>; |
| 170 | |
| 171 | def : Pat<(i64 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))), |
| 172 | (SETB_C64r)>; |
| 173 | |
Chris Lattner | 010496c | 2010-10-05 06:22:35 +0000 | [diff] [blame] | 174 | |
Chris Lattner | d3f033d | 2010-10-05 06:27:48 +0000 | [diff] [blame] | 175 | //===----------------------------------------------------------------------===// |
| 176 | // String Pseudo Instructions |
| 177 | // |
| 178 | let Defs = [ECX,EDI,ESI], Uses = [ECX,EDI,ESI], isCodeGenOnly = 1 in { |
| 179 | def REP_MOVSB : I<0xA4, RawFrm, (outs), (ins), "{rep;movsb|rep movsb}", |
| 180 | [(X86rep_movs i8)]>, REP; |
| 181 | def REP_MOVSW : I<0xA5, RawFrm, (outs), (ins), "{rep;movsw|rep movsw}", |
| 182 | [(X86rep_movs i16)]>, REP, OpSize; |
| 183 | def REP_MOVSD : I<0xA5, RawFrm, (outs), (ins), "{rep;movsl|rep movsd}", |
| 184 | [(X86rep_movs i32)]>, REP; |
| 185 | } |
| 186 | |
| 187 | let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI], isCodeGenOnly = 1 in |
| 188 | def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}", |
| 189 | [(X86rep_movs i64)]>, REP; |
| 190 | |
| 191 | |
| 192 | // FIXME: Should use "(X86rep_stos AL)" as the pattern. |
| 193 | let Defs = [ECX,EDI], Uses = [AL,ECX,EDI], isCodeGenOnly = 1 in |
| 194 | def REP_STOSB : I<0xAA, RawFrm, (outs), (ins), "{rep;stosb|rep stosb}", |
| 195 | [(X86rep_stos i8)]>, REP; |
| 196 | let Defs = [ECX,EDI], Uses = [AX,ECX,EDI], isCodeGenOnly = 1 in |
| 197 | def REP_STOSW : I<0xAB, RawFrm, (outs), (ins), "{rep;stosw|rep stosw}", |
| 198 | [(X86rep_stos i16)]>, REP, OpSize; |
| 199 | let Defs = [ECX,EDI], Uses = [EAX,ECX,EDI], isCodeGenOnly = 1 in |
| 200 | def REP_STOSD : I<0xAB, RawFrm, (outs), (ins), "{rep;stosl|rep stosd}", |
| 201 | [(X86rep_stos i32)]>, REP; |
| 202 | |
| 203 | let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI], isCodeGenOnly = 1 in |
| 204 | def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}", |
| 205 | [(X86rep_stos i64)]>, REP; |
Chris Lattner | 010496c | 2010-10-05 06:22:35 +0000 | [diff] [blame] | 206 | |
| 207 | |
Chris Lattner | 8af88ef | 2010-10-05 06:10:16 +0000 | [diff] [blame] | 208 | //===----------------------------------------------------------------------===// |
| 209 | // Thread Local Storage Instructions |
| 210 | // |
| 211 | |
| 212 | // ELF TLS Support |
| 213 | // All calls clobber the non-callee saved registers. ESP is marked as |
| 214 | // a use to prevent stack-pointer assignments that appear immediately |
| 215 | // before calls from potentially appearing dead. |
| 216 | let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, |
| 217 | MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7, |
| 218 | XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, |
| 219 | XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS], |
| 220 | Uses = [ESP] in |
| 221 | def TLS_addr32 : I<0, Pseudo, (outs), (ins i32mem:$sym), |
| 222 | "leal\t$sym, %eax; " |
| 223 | "call\t___tls_get_addr@PLT", |
| 224 | [(X86tlsaddr tls32addr:$sym)]>, |
| 225 | Requires<[In32BitMode]>; |
| 226 | |
| 227 | // All calls clobber the non-callee saved registers. RSP is marked as |
| 228 | // a use to prevent stack-pointer assignments that appear immediately |
| 229 | // before calls from potentially appearing dead. |
| 230 | let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11, |
| 231 | FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1, |
| 232 | MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7, |
| 233 | XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, |
| 234 | XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS], |
| 235 | Uses = [RSP] in |
| 236 | def TLS_addr64 : I<0, Pseudo, (outs), (ins i64mem:$sym), |
| 237 | ".byte\t0x66; " |
| 238 | "leaq\t$sym(%rip), %rdi; " |
| 239 | ".word\t0x6666; " |
| 240 | "rex64; " |
| 241 | "call\t__tls_get_addr@PLT", |
| 242 | [(X86tlsaddr tls64addr:$sym)]>, |
| 243 | Requires<[In64BitMode]>; |
| 244 | |
| 245 | // Darwin TLS Support |
| 246 | // For i386, the address of the thunk is passed on the stack, on return the |
| 247 | // address of the variable is in %eax. %ecx is trashed during the function |
| 248 | // call. All other registers are preserved. |
| 249 | let Defs = [EAX, ECX], |
| 250 | Uses = [ESP], |
| 251 | usesCustomInserter = 1 in |
| 252 | def TLSCall_32 : I<0, Pseudo, (outs), (ins i32mem:$sym), |
| 253 | "# TLSCall_32", |
| 254 | [(X86TLSCall addr:$sym)]>, |
| 255 | Requires<[In32BitMode]>; |
| 256 | |
| 257 | // For x86_64, the address of the thunk is passed in %rdi, on return |
| 258 | // the address of the variable is in %rax. All other registers are preserved. |
| 259 | let Defs = [RAX], |
| 260 | Uses = [RDI], |
| 261 | usesCustomInserter = 1 in |
| 262 | def TLSCall_64 : I<0, Pseudo, (outs), (ins i64mem:$sym), |
| 263 | "# TLSCall_64", |
| 264 | [(X86TLSCall addr:$sym)]>, |
| 265 | Requires<[In64BitMode]>; |
Chris Lattner | 87be16a | 2010-10-05 06:04:14 +0000 | [diff] [blame] | 266 | |
| 267 | //===----------------------------------------------------------------------===// |
Chris Lattner | 010496c | 2010-10-05 06:22:35 +0000 | [diff] [blame] | 268 | // Atomic Instruction Pseudo Instructions |
| 269 | //===----------------------------------------------------------------------===// |
| 270 | |
| 271 | // Atomic exchange, and, or, xor |
| 272 | let Constraints = "$val = $dst", Defs = [EFLAGS], |
| 273 | usesCustomInserter = 1 in { |
| 274 | |
| 275 | def ATOMAND8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val), |
| 276 | "#ATOMAND8 PSEUDO!", |
| 277 | [(set GR8:$dst, (atomic_load_and_8 addr:$ptr, GR8:$val))]>; |
| 278 | def ATOMOR8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val), |
| 279 | "#ATOMOR8 PSEUDO!", |
| 280 | [(set GR8:$dst, (atomic_load_or_8 addr:$ptr, GR8:$val))]>; |
| 281 | def ATOMXOR8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val), |
| 282 | "#ATOMXOR8 PSEUDO!", |
| 283 | [(set GR8:$dst, (atomic_load_xor_8 addr:$ptr, GR8:$val))]>; |
| 284 | def ATOMNAND8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val), |
| 285 | "#ATOMNAND8 PSEUDO!", |
| 286 | [(set GR8:$dst, (atomic_load_nand_8 addr:$ptr, GR8:$val))]>; |
| 287 | |
| 288 | def ATOMAND16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val), |
| 289 | "#ATOMAND16 PSEUDO!", |
| 290 | [(set GR16:$dst, (atomic_load_and_16 addr:$ptr, GR16:$val))]>; |
| 291 | def ATOMOR16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val), |
| 292 | "#ATOMOR16 PSEUDO!", |
| 293 | [(set GR16:$dst, (atomic_load_or_16 addr:$ptr, GR16:$val))]>; |
| 294 | def ATOMXOR16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val), |
| 295 | "#ATOMXOR16 PSEUDO!", |
| 296 | [(set GR16:$dst, (atomic_load_xor_16 addr:$ptr, GR16:$val))]>; |
| 297 | def ATOMNAND16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val), |
| 298 | "#ATOMNAND16 PSEUDO!", |
| 299 | [(set GR16:$dst, (atomic_load_nand_16 addr:$ptr, GR16:$val))]>; |
| 300 | def ATOMMIN16: I<0, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val), |
| 301 | "#ATOMMIN16 PSEUDO!", |
| 302 | [(set GR16:$dst, (atomic_load_min_16 addr:$ptr, GR16:$val))]>; |
| 303 | def ATOMMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val), |
| 304 | "#ATOMMAX16 PSEUDO!", |
| 305 | [(set GR16:$dst, (atomic_load_max_16 addr:$ptr, GR16:$val))]>; |
| 306 | def ATOMUMIN16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val), |
| 307 | "#ATOMUMIN16 PSEUDO!", |
| 308 | [(set GR16:$dst, (atomic_load_umin_16 addr:$ptr, GR16:$val))]>; |
| 309 | def ATOMUMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val), |
| 310 | "#ATOMUMAX16 PSEUDO!", |
| 311 | [(set GR16:$dst, (atomic_load_umax_16 addr:$ptr, GR16:$val))]>; |
| 312 | |
| 313 | |
| 314 | def ATOMAND32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val), |
| 315 | "#ATOMAND32 PSEUDO!", |
| 316 | [(set GR32:$dst, (atomic_load_and_32 addr:$ptr, GR32:$val))]>; |
| 317 | def ATOMOR32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val), |
| 318 | "#ATOMOR32 PSEUDO!", |
| 319 | [(set GR32:$dst, (atomic_load_or_32 addr:$ptr, GR32:$val))]>; |
| 320 | def ATOMXOR32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val), |
| 321 | "#ATOMXOR32 PSEUDO!", |
| 322 | [(set GR32:$dst, (atomic_load_xor_32 addr:$ptr, GR32:$val))]>; |
| 323 | def ATOMNAND32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val), |
| 324 | "#ATOMNAND32 PSEUDO!", |
| 325 | [(set GR32:$dst, (atomic_load_nand_32 addr:$ptr, GR32:$val))]>; |
| 326 | def ATOMMIN32: I<0, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val), |
| 327 | "#ATOMMIN32 PSEUDO!", |
| 328 | [(set GR32:$dst, (atomic_load_min_32 addr:$ptr, GR32:$val))]>; |
| 329 | def ATOMMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val), |
| 330 | "#ATOMMAX32 PSEUDO!", |
| 331 | [(set GR32:$dst, (atomic_load_max_32 addr:$ptr, GR32:$val))]>; |
| 332 | def ATOMUMIN32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val), |
| 333 | "#ATOMUMIN32 PSEUDO!", |
| 334 | [(set GR32:$dst, (atomic_load_umin_32 addr:$ptr, GR32:$val))]>; |
| 335 | def ATOMUMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val), |
| 336 | "#ATOMUMAX32 PSEUDO!", |
| 337 | [(set GR32:$dst, (atomic_load_umax_32 addr:$ptr, GR32:$val))]>; |
| 338 | |
| 339 | |
| 340 | |
| 341 | def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val), |
| 342 | "#ATOMAND64 PSEUDO!", |
| 343 | [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>; |
| 344 | def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val), |
| 345 | "#ATOMOR64 PSEUDO!", |
| 346 | [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>; |
| 347 | def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val), |
| 348 | "#ATOMXOR64 PSEUDO!", |
| 349 | [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>; |
| 350 | def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val), |
| 351 | "#ATOMNAND64 PSEUDO!", |
| 352 | [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>; |
| 353 | def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val), |
| 354 | "#ATOMMIN64 PSEUDO!", |
| 355 | [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>; |
| 356 | def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val), |
| 357 | "#ATOMMAX64 PSEUDO!", |
| 358 | [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>; |
| 359 | def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val), |
| 360 | "#ATOMUMIN64 PSEUDO!", |
| 361 | [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>; |
| 362 | def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val), |
| 363 | "#ATOMUMAX64 PSEUDO!", |
| 364 | [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>; |
| 365 | } |
| 366 | |
| 367 | let Constraints = "$val1 = $dst1, $val2 = $dst2", |
| 368 | Defs = [EFLAGS, EAX, EBX, ECX, EDX], |
| 369 | Uses = [EAX, EBX, ECX, EDX], |
| 370 | mayLoad = 1, mayStore = 1, |
| 371 | usesCustomInserter = 1 in { |
| 372 | def ATOMAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2), |
| 373 | (ins i64mem:$ptr, GR32:$val1, GR32:$val2), |
| 374 | "#ATOMAND6432 PSEUDO!", []>; |
| 375 | def ATOMOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2), |
| 376 | (ins i64mem:$ptr, GR32:$val1, GR32:$val2), |
| 377 | "#ATOMOR6432 PSEUDO!", []>; |
| 378 | def ATOMXOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2), |
| 379 | (ins i64mem:$ptr, GR32:$val1, GR32:$val2), |
| 380 | "#ATOMXOR6432 PSEUDO!", []>; |
| 381 | def ATOMNAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2), |
| 382 | (ins i64mem:$ptr, GR32:$val1, GR32:$val2), |
| 383 | "#ATOMNAND6432 PSEUDO!", []>; |
| 384 | def ATOMADD6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2), |
| 385 | (ins i64mem:$ptr, GR32:$val1, GR32:$val2), |
| 386 | "#ATOMADD6432 PSEUDO!", []>; |
| 387 | def ATOMSUB6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2), |
| 388 | (ins i64mem:$ptr, GR32:$val1, GR32:$val2), |
| 389 | "#ATOMSUB6432 PSEUDO!", []>; |
| 390 | def ATOMSWAP6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2), |
| 391 | (ins i64mem:$ptr, GR32:$val1, GR32:$val2), |
| 392 | "#ATOMSWAP6432 PSEUDO!", []>; |
| 393 | } |
| 394 | |
| 395 | //===----------------------------------------------------------------------===// |
| 396 | // Normal-Instructions-With-Lock-Prefix Pseudo Instructions |
| 397 | //===----------------------------------------------------------------------===// |
| 398 | |
| 399 | // FIXME: Use normal instructions and add lock prefix dynamically. |
| 400 | |
| 401 | // Memory barriers |
| 402 | |
| 403 | // TODO: Get this to fold the constant into the instruction. |
| 404 | def OR32mrLocked : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$zero), |
| 405 | "lock\n\t" |
| 406 | "or{l}\t{$zero, $dst|$dst, $zero}", |
| 407 | []>, Requires<[In32BitMode]>, LOCK; |
| 408 | |
| 409 | let hasSideEffects = 1 in |
| 410 | def Int_MemBarrier : I<0, Pseudo, (outs), (ins), |
| 411 | "#MEMBARRIER", |
| 412 | [(X86MemBarrier)]>, Requires<[HasSSE2]>; |
| 413 | |
| 414 | // TODO: Get this to fold the constant into the instruction. |
| 415 | let hasSideEffects = 1, Defs = [ESP] in |
| 416 | def Int_MemBarrierNoSSE64 : RI<0x09, MRM1r, (outs), (ins GR64:$zero), |
| 417 | "lock\n\t" |
| 418 | "or{q}\t{$zero, (%rsp)|(%rsp), $zero}", |
| 419 | [(X86MemBarrierNoSSE GR64:$zero)]>, |
| 420 | Requires<[In64BitMode]>, LOCK; |
| 421 | |
| 422 | |
| 423 | // Optimized codegen when the non-memory output is not used. |
| 424 | let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in { |
| 425 | def LOCK_ADD8mr : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2), |
| 426 | "lock\n\t" |
| 427 | "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 428 | def LOCK_ADD16mr : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2), |
| 429 | "lock\n\t" |
| 430 | "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK; |
| 431 | def LOCK_ADD32mr : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), |
| 432 | "lock\n\t" |
| 433 | "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 434 | def LOCK_ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), |
| 435 | "lock\n\t" |
| 436 | "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 437 | |
| 438 | def LOCK_ADD8mi : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2), |
| 439 | "lock\n\t" |
| 440 | "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 441 | def LOCK_ADD16mi : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2), |
| 442 | "lock\n\t" |
| 443 | "add{w}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 444 | def LOCK_ADD32mi : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2), |
| 445 | "lock\n\t" |
| 446 | "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 447 | def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs), |
| 448 | (ins i64mem:$dst, i64i32imm :$src2), |
| 449 | "lock\n\t" |
| 450 | "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 451 | |
| 452 | def LOCK_ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2), |
| 453 | "lock\n\t" |
| 454 | "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK; |
| 455 | def LOCK_ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2), |
| 456 | "lock\n\t" |
| 457 | "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 458 | def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs), |
| 459 | (ins i64mem:$dst, i64i8imm :$src2), |
| 460 | "lock\n\t" |
| 461 | "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 462 | |
| 463 | def LOCK_SUB8mr : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2), |
| 464 | "lock\n\t" |
| 465 | "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 466 | def LOCK_SUB16mr : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2), |
| 467 | "lock\n\t" |
| 468 | "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK; |
| 469 | def LOCK_SUB32mr : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), |
| 470 | "lock\n\t" |
| 471 | "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 472 | def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2), |
| 473 | "lock\n\t" |
| 474 | "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 475 | |
| 476 | |
| 477 | def LOCK_SUB8mi : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), |
| 478 | "lock\n\t" |
| 479 | "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 480 | def LOCK_SUB16mi : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), |
| 481 | "lock\n\t" |
| 482 | "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK; |
| 483 | def LOCK_SUB32mi : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), |
| 484 | "lock\n\t" |
| 485 | "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 486 | def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs), |
| 487 | (ins i64mem:$dst, i64i32imm:$src2), |
| 488 | "lock\n\t" |
| 489 | "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 490 | |
| 491 | |
| 492 | def LOCK_SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), |
| 493 | "lock\n\t" |
| 494 | "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK; |
| 495 | def LOCK_SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2), |
| 496 | "lock\n\t" |
| 497 | "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 498 | def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs), |
| 499 | (ins i64mem:$dst, i64i8imm :$src2), |
| 500 | "lock\n\t" |
| 501 | "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK; |
| 502 | |
| 503 | def LOCK_INC8m : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), |
| 504 | "lock\n\t" |
| 505 | "inc{b}\t$dst", []>, LOCK; |
| 506 | def LOCK_INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), |
| 507 | "lock\n\t" |
| 508 | "inc{w}\t$dst", []>, OpSize, LOCK; |
| 509 | def LOCK_INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), |
| 510 | "lock\n\t" |
| 511 | "inc{l}\t$dst", []>, LOCK; |
| 512 | def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), |
| 513 | "lock\n\t" |
| 514 | "inc{q}\t$dst", []>, LOCK; |
| 515 | |
| 516 | def LOCK_DEC8m : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), |
| 517 | "lock\n\t" |
| 518 | "dec{b}\t$dst", []>, LOCK; |
| 519 | def LOCK_DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), |
| 520 | "lock\n\t" |
| 521 | "dec{w}\t$dst", []>, OpSize, LOCK; |
| 522 | def LOCK_DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), |
| 523 | "lock\n\t" |
| 524 | "dec{l}\t$dst", []>, LOCK; |
| 525 | def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), |
| 526 | "lock\n\t" |
| 527 | "dec{q}\t$dst", []>, LOCK; |
| 528 | } |
| 529 | |
| 530 | // Atomic compare and swap. |
| 531 | let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in { |
| 532 | def LCMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$ptr), |
| 533 | "lock\n\t" |
| 534 | "cmpxchg8b\t$ptr", |
| 535 | [(X86cas8 addr:$ptr)]>, TB, LOCK; |
| 536 | } |
| 537 | let Defs = [AL, EFLAGS], Uses = [AL] in { |
| 538 | def LCMPXCHG8 : I<0xB0, MRMDestMem, (outs), (ins i8mem:$ptr, GR8:$swap), |
| 539 | "lock\n\t" |
| 540 | "cmpxchg{b}\t{$swap, $ptr|$ptr, $swap}", |
| 541 | [(X86cas addr:$ptr, GR8:$swap, 1)]>, TB, LOCK; |
| 542 | } |
| 543 | |
| 544 | let Defs = [AX, EFLAGS], Uses = [AX] in { |
| 545 | def LCMPXCHG16 : I<0xB1, MRMDestMem, (outs), (ins i16mem:$ptr, GR16:$swap), |
| 546 | "lock\n\t" |
| 547 | "cmpxchg{w}\t{$swap, $ptr|$ptr, $swap}", |
| 548 | [(X86cas addr:$ptr, GR16:$swap, 2)]>, TB, OpSize, LOCK; |
| 549 | } |
| 550 | |
| 551 | let Defs = [EAX, EFLAGS], Uses = [EAX] in { |
| 552 | def LCMPXCHG32 : I<0xB1, MRMDestMem, (outs), (ins i32mem:$ptr, GR32:$swap), |
| 553 | "lock\n\t" |
| 554 | "cmpxchg{l}\t{$swap, $ptr|$ptr, $swap}", |
| 555 | [(X86cas addr:$ptr, GR32:$swap, 4)]>, TB, LOCK; |
| 556 | } |
| 557 | |
| 558 | let Defs = [RAX, EFLAGS], Uses = [RAX] in { |
| 559 | def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap), |
| 560 | "lock\n\t" |
| 561 | "cmpxchgq\t$swap,$ptr", |
| 562 | [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK; |
| 563 | } |
| 564 | |
| 565 | // Atomic exchange and add |
| 566 | let Constraints = "$val = $dst", Defs = [EFLAGS] in { |
| 567 | def LXADD8 : I<0xC0, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr), |
| 568 | "lock\n\t" |
| 569 | "xadd{b}\t{$val, $ptr|$ptr, $val}", |
| 570 | [(set GR8:$dst, (atomic_load_add_8 addr:$ptr, GR8:$val))]>, |
| 571 | TB, LOCK; |
| 572 | def LXADD16 : I<0xC1, MRMSrcMem, (outs GR16:$dst), (ins GR16:$val, i16mem:$ptr), |
| 573 | "lock\n\t" |
| 574 | "xadd{w}\t{$val, $ptr|$ptr, $val}", |
| 575 | [(set GR16:$dst, (atomic_load_add_16 addr:$ptr, GR16:$val))]>, |
| 576 | TB, OpSize, LOCK; |
| 577 | def LXADD32 : I<0xC1, MRMSrcMem, (outs GR32:$dst), (ins GR32:$val, i32mem:$ptr), |
| 578 | "lock\n\t" |
| 579 | "xadd{l}\t{$val, $ptr|$ptr, $val}", |
| 580 | [(set GR32:$dst, (atomic_load_add_32 addr:$ptr, GR32:$val))]>, |
| 581 | TB, LOCK; |
| 582 | def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins GR64:$val,i64mem:$ptr), |
| 583 | "lock\n\t" |
| 584 | "xadd\t$val, $ptr", |
| 585 | [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>, |
| 586 | TB, LOCK; |
| 587 | } |
| 588 | |
Chris Lattner | 5673e1d | 2010-10-05 06:41:40 +0000 | [diff] [blame^] | 589 | //===----------------------------------------------------------------------===// |
| 590 | // Conditional Move Pseudo Instructions. |
| 591 | //===----------------------------------------------------------------------===// |
| 592 | |
| 593 | |
| 594 | // CMOV* - Used to implement the SSE SELECT DAG operation. Expanded after |
| 595 | // instruction selection into a branch sequence. |
| 596 | let Uses = [EFLAGS], usesCustomInserter = 1 in { |
| 597 | def CMOV_FR32 : I<0, Pseudo, |
| 598 | (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond), |
| 599 | "#CMOV_FR32 PSEUDO!", |
| 600 | [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond, |
| 601 | EFLAGS))]>; |
| 602 | def CMOV_FR64 : I<0, Pseudo, |
| 603 | (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond), |
| 604 | "#CMOV_FR64 PSEUDO!", |
| 605 | [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond, |
| 606 | EFLAGS))]>; |
| 607 | def CMOV_V4F32 : I<0, Pseudo, |
| 608 | (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond), |
| 609 | "#CMOV_V4F32 PSEUDO!", |
| 610 | [(set VR128:$dst, |
| 611 | (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond, |
| 612 | EFLAGS)))]>; |
| 613 | def CMOV_V2F64 : I<0, Pseudo, |
| 614 | (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond), |
| 615 | "#CMOV_V2F64 PSEUDO!", |
| 616 | [(set VR128:$dst, |
| 617 | (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond, |
| 618 | EFLAGS)))]>; |
| 619 | def CMOV_V2I64 : I<0, Pseudo, |
| 620 | (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond), |
| 621 | "#CMOV_V2I64 PSEUDO!", |
| 622 | [(set VR128:$dst, |
| 623 | (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond, |
| 624 | EFLAGS)))]>; |
| 625 | } |
| 626 | |
Chris Lattner | 010496c | 2010-10-05 06:22:35 +0000 | [diff] [blame] | 627 | |
| 628 | //===----------------------------------------------------------------------===// |
| 629 | // DAG Pattern Matching Rules |
Chris Lattner | 87be16a | 2010-10-05 06:04:14 +0000 | [diff] [blame] | 630 | //===----------------------------------------------------------------------===// |
| 631 | |
| 632 | // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable |
| 633 | def : Pat<(i32 (X86Wrapper tconstpool :$dst)), (MOV32ri tconstpool :$dst)>; |
| 634 | def : Pat<(i32 (X86Wrapper tjumptable :$dst)), (MOV32ri tjumptable :$dst)>; |
| 635 | def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)),(MOV32ri tglobaltlsaddr:$dst)>; |
| 636 | def : Pat<(i32 (X86Wrapper tglobaladdr :$dst)), (MOV32ri tglobaladdr :$dst)>; |
| 637 | def : Pat<(i32 (X86Wrapper texternalsym:$dst)), (MOV32ri texternalsym:$dst)>; |
| 638 | def : Pat<(i32 (X86Wrapper tblockaddress:$dst)), (MOV32ri tblockaddress:$dst)>; |
| 639 | |
| 640 | def : Pat<(add GR32:$src1, (X86Wrapper tconstpool:$src2)), |
| 641 | (ADD32ri GR32:$src1, tconstpool:$src2)>; |
| 642 | def : Pat<(add GR32:$src1, (X86Wrapper tjumptable:$src2)), |
| 643 | (ADD32ri GR32:$src1, tjumptable:$src2)>; |
| 644 | def : Pat<(add GR32:$src1, (X86Wrapper tglobaladdr :$src2)), |
| 645 | (ADD32ri GR32:$src1, tglobaladdr:$src2)>; |
| 646 | def : Pat<(add GR32:$src1, (X86Wrapper texternalsym:$src2)), |
| 647 | (ADD32ri GR32:$src1, texternalsym:$src2)>; |
| 648 | def : Pat<(add GR32:$src1, (X86Wrapper tblockaddress:$src2)), |
| 649 | (ADD32ri GR32:$src1, tblockaddress:$src2)>; |
| 650 | |
| 651 | def : Pat<(store (i32 (X86Wrapper tglobaladdr:$src)), addr:$dst), |
| 652 | (MOV32mi addr:$dst, tglobaladdr:$src)>; |
| 653 | def : Pat<(store (i32 (X86Wrapper texternalsym:$src)), addr:$dst), |
| 654 | (MOV32mi addr:$dst, texternalsym:$src)>; |
| 655 | def : Pat<(store (i32 (X86Wrapper tblockaddress:$src)), addr:$dst), |
| 656 | (MOV32mi addr:$dst, tblockaddress:$src)>; |
| 657 | |
| 658 | |
| 659 | |
| 660 | // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small |
| 661 | // code model mode, should use 'movabs'. FIXME: This is really a hack, the |
| 662 | // 'movabs' predicate should handle this sort of thing. |
| 663 | def : Pat<(i64 (X86Wrapper tconstpool :$dst)), |
| 664 | (MOV64ri tconstpool :$dst)>, Requires<[FarData]>; |
| 665 | def : Pat<(i64 (X86Wrapper tjumptable :$dst)), |
| 666 | (MOV64ri tjumptable :$dst)>, Requires<[FarData]>; |
| 667 | def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)), |
| 668 | (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>; |
| 669 | def : Pat<(i64 (X86Wrapper texternalsym:$dst)), |
| 670 | (MOV64ri texternalsym:$dst)>, Requires<[FarData]>; |
| 671 | def : Pat<(i64 (X86Wrapper tblockaddress:$dst)), |
| 672 | (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>; |
| 673 | |
| 674 | // In static codegen with small code model, we can get the address of a label |
| 675 | // into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of |
| 676 | // the MOV64ri64i32 should accept these. |
| 677 | def : Pat<(i64 (X86Wrapper tconstpool :$dst)), |
| 678 | (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>; |
| 679 | def : Pat<(i64 (X86Wrapper tjumptable :$dst)), |
| 680 | (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>; |
| 681 | def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)), |
| 682 | (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>; |
| 683 | def : Pat<(i64 (X86Wrapper texternalsym:$dst)), |
| 684 | (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>; |
| 685 | def : Pat<(i64 (X86Wrapper tblockaddress:$dst)), |
| 686 | (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>; |
| 687 | |
| 688 | // In kernel code model, we can get the address of a label |
| 689 | // into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of |
| 690 | // the MOV64ri32 should accept these. |
| 691 | def : Pat<(i64 (X86Wrapper tconstpool :$dst)), |
| 692 | (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>; |
| 693 | def : Pat<(i64 (X86Wrapper tjumptable :$dst)), |
| 694 | (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>; |
| 695 | def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)), |
| 696 | (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>; |
| 697 | def : Pat<(i64 (X86Wrapper texternalsym:$dst)), |
| 698 | (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>; |
| 699 | def : Pat<(i64 (X86Wrapper tblockaddress:$dst)), |
| 700 | (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>; |
| 701 | |
| 702 | // If we have small model and -static mode, it is safe to store global addresses |
| 703 | // directly as immediates. FIXME: This is really a hack, the 'imm' predicate |
| 704 | // for MOV64mi32 should handle this sort of thing. |
| 705 | def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst), |
| 706 | (MOV64mi32 addr:$dst, tconstpool:$src)>, |
| 707 | Requires<[NearData, IsStatic]>; |
| 708 | def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst), |
| 709 | (MOV64mi32 addr:$dst, tjumptable:$src)>, |
| 710 | Requires<[NearData, IsStatic]>; |
| 711 | def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst), |
| 712 | (MOV64mi32 addr:$dst, tglobaladdr:$src)>, |
| 713 | Requires<[NearData, IsStatic]>; |
| 714 | def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst), |
| 715 | (MOV64mi32 addr:$dst, texternalsym:$src)>, |
| 716 | Requires<[NearData, IsStatic]>; |
| 717 | def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst), |
| 718 | (MOV64mi32 addr:$dst, tblockaddress:$src)>, |
| 719 | Requires<[NearData, IsStatic]>; |
| 720 | |
| 721 | |
| 722 | |
| 723 | // Calls |
| 724 | |
| 725 | // tls has some funny stuff here... |
| 726 | // This corresponds to movabs $foo@tpoff, %rax |
| 727 | def : Pat<(i64 (X86Wrapper tglobaltlsaddr :$dst)), |
| 728 | (MOV64ri tglobaltlsaddr :$dst)>; |
| 729 | // This corresponds to add $foo@tpoff, %rax |
| 730 | def : Pat<(add GR64:$src1, (X86Wrapper tglobaltlsaddr :$dst)), |
| 731 | (ADD64ri32 GR64:$src1, tglobaltlsaddr :$dst)>; |
| 732 | // This corresponds to mov foo@tpoff(%rbx), %eax |
| 733 | def : Pat<(load (i64 (X86Wrapper tglobaltlsaddr :$dst))), |
| 734 | (MOV64rm tglobaltlsaddr :$dst)>; |
| 735 | |
| 736 | |
| 737 | // Direct PC relative function call for small code model. 32-bit displacement |
| 738 | // sign extended to 64-bit. |
| 739 | def : Pat<(X86call (i64 tglobaladdr:$dst)), |
| 740 | (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>; |
| 741 | def : Pat<(X86call (i64 texternalsym:$dst)), |
| 742 | (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>; |
| 743 | |
| 744 | def : Pat<(X86call (i64 tglobaladdr:$dst)), |
| 745 | (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>; |
| 746 | def : Pat<(X86call (i64 texternalsym:$dst)), |
| 747 | (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>; |
| 748 | |
| 749 | // tailcall stuff |
| 750 | def : Pat<(X86tcret GR32_TC:$dst, imm:$off), |
| 751 | (TCRETURNri GR32_TC:$dst, imm:$off)>, |
| 752 | Requires<[In32BitMode]>; |
| 753 | |
| 754 | // FIXME: This is disabled for 32-bit PIC mode because the global base |
| 755 | // register which is part of the address mode may be assigned a |
| 756 | // callee-saved register. |
| 757 | def : Pat<(X86tcret (load addr:$dst), imm:$off), |
| 758 | (TCRETURNmi addr:$dst, imm:$off)>, |
| 759 | Requires<[In32BitMode, IsNotPIC]>; |
| 760 | |
| 761 | def : Pat<(X86tcret (i32 tglobaladdr:$dst), imm:$off), |
| 762 | (TCRETURNdi texternalsym:$dst, imm:$off)>, |
| 763 | Requires<[In32BitMode]>; |
| 764 | |
| 765 | def : Pat<(X86tcret (i32 texternalsym:$dst), imm:$off), |
| 766 | (TCRETURNdi texternalsym:$dst, imm:$off)>, |
| 767 | Requires<[In32BitMode]>; |
| 768 | |
| 769 | def : Pat<(X86tcret GR64_TC:$dst, imm:$off), |
| 770 | (TCRETURNri64 GR64_TC:$dst, imm:$off)>, |
| 771 | Requires<[In64BitMode]>; |
| 772 | |
| 773 | def : Pat<(X86tcret (load addr:$dst), imm:$off), |
| 774 | (TCRETURNmi64 addr:$dst, imm:$off)>, |
| 775 | Requires<[In64BitMode]>; |
| 776 | |
| 777 | def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off), |
| 778 | (TCRETURNdi64 tglobaladdr:$dst, imm:$off)>, |
| 779 | Requires<[In64BitMode]>; |
| 780 | |
| 781 | def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off), |
| 782 | (TCRETURNdi64 texternalsym:$dst, imm:$off)>, |
| 783 | Requires<[In64BitMode]>; |
| 784 | |
| 785 | // Normal calls, with various flavors of addresses. |
| 786 | def : Pat<(X86call (i32 tglobaladdr:$dst)), |
| 787 | (CALLpcrel32 tglobaladdr:$dst)>; |
| 788 | def : Pat<(X86call (i32 texternalsym:$dst)), |
| 789 | (CALLpcrel32 texternalsym:$dst)>; |
| 790 | def : Pat<(X86call (i32 imm:$dst)), |
| 791 | (CALLpcrel32 imm:$dst)>, Requires<[CallImmAddr]>; |
| 792 | |
| 793 | // X86 specific add which produces a flag. |
| 794 | def : Pat<(addc GR32:$src1, GR32:$src2), |
| 795 | (ADD32rr GR32:$src1, GR32:$src2)>; |
| 796 | def : Pat<(addc GR32:$src1, (load addr:$src2)), |
| 797 | (ADD32rm GR32:$src1, addr:$src2)>; |
| 798 | def : Pat<(addc GR32:$src1, imm:$src2), |
| 799 | (ADD32ri GR32:$src1, imm:$src2)>; |
| 800 | def : Pat<(addc GR32:$src1, i32immSExt8:$src2), |
| 801 | (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>; |
| 802 | |
| 803 | def : Pat<(addc GR64:$src1, GR64:$src2), |
| 804 | (ADD64rr GR64:$src1, GR64:$src2)>; |
| 805 | def : Pat<(addc GR64:$src1, (load addr:$src2)), |
| 806 | (ADD64rm GR64:$src1, addr:$src2)>; |
| 807 | def : Pat<(addc GR64:$src1, i64immSExt8:$src2), |
| 808 | (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>; |
| 809 | def : Pat<(addc GR64:$src1, i64immSExt32:$src2), |
| 810 | (ADD64ri32 GR64:$src1, imm:$src2)>; |
| 811 | |
| 812 | def : Pat<(subc GR32:$src1, GR32:$src2), |
| 813 | (SUB32rr GR32:$src1, GR32:$src2)>; |
| 814 | def : Pat<(subc GR32:$src1, (load addr:$src2)), |
| 815 | (SUB32rm GR32:$src1, addr:$src2)>; |
| 816 | def : Pat<(subc GR32:$src1, imm:$src2), |
| 817 | (SUB32ri GR32:$src1, imm:$src2)>; |
| 818 | def : Pat<(subc GR32:$src1, i32immSExt8:$src2), |
| 819 | (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>; |
| 820 | |
| 821 | def : Pat<(subc GR64:$src1, GR64:$src2), |
| 822 | (SUB64rr GR64:$src1, GR64:$src2)>; |
| 823 | def : Pat<(subc GR64:$src1, (load addr:$src2)), |
| 824 | (SUB64rm GR64:$src1, addr:$src2)>; |
| 825 | def : Pat<(subc GR64:$src1, i64immSExt8:$src2), |
| 826 | (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>; |
| 827 | def : Pat<(subc GR64:$src1, imm:$src2), |
| 828 | (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>; |
| 829 | |
| 830 | // Comparisons. |
| 831 | |
| 832 | // TEST R,R is smaller than CMP R,0 |
| 833 | def : Pat<(X86cmp GR8:$src1, 0), |
| 834 | (TEST8rr GR8:$src1, GR8:$src1)>; |
| 835 | def : Pat<(X86cmp GR16:$src1, 0), |
| 836 | (TEST16rr GR16:$src1, GR16:$src1)>; |
| 837 | def : Pat<(X86cmp GR32:$src1, 0), |
| 838 | (TEST32rr GR32:$src1, GR32:$src1)>; |
| 839 | def : Pat<(X86cmp GR64:$src1, 0), |
| 840 | (TEST64rr GR64:$src1, GR64:$src1)>; |
| 841 | |
| 842 | // Conditional moves with folded loads with operands swapped and conditions |
| 843 | // inverted. |
| 844 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_B, EFLAGS), |
| 845 | (CMOVAE16rm GR16:$src2, addr:$src1)>; |
| 846 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_B, EFLAGS), |
| 847 | (CMOVAE32rm GR32:$src2, addr:$src1)>; |
| 848 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_AE, EFLAGS), |
| 849 | (CMOVB16rm GR16:$src2, addr:$src1)>; |
| 850 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_AE, EFLAGS), |
| 851 | (CMOVB32rm GR32:$src2, addr:$src1)>; |
| 852 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_E, EFLAGS), |
| 853 | (CMOVNE16rm GR16:$src2, addr:$src1)>; |
| 854 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_E, EFLAGS), |
| 855 | (CMOVNE32rm GR32:$src2, addr:$src1)>; |
| 856 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NE, EFLAGS), |
| 857 | (CMOVE16rm GR16:$src2, addr:$src1)>; |
| 858 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NE, EFLAGS), |
| 859 | (CMOVE32rm GR32:$src2, addr:$src1)>; |
| 860 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_BE, EFLAGS), |
| 861 | (CMOVA16rm GR16:$src2, addr:$src1)>; |
| 862 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_BE, EFLAGS), |
| 863 | (CMOVA32rm GR32:$src2, addr:$src1)>; |
| 864 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_A, EFLAGS), |
| 865 | (CMOVBE16rm GR16:$src2, addr:$src1)>; |
| 866 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_A, EFLAGS), |
| 867 | (CMOVBE32rm GR32:$src2, addr:$src1)>; |
| 868 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_L, EFLAGS), |
| 869 | (CMOVGE16rm GR16:$src2, addr:$src1)>; |
| 870 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_L, EFLAGS), |
| 871 | (CMOVGE32rm GR32:$src2, addr:$src1)>; |
| 872 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_GE, EFLAGS), |
| 873 | (CMOVL16rm GR16:$src2, addr:$src1)>; |
| 874 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_GE, EFLAGS), |
| 875 | (CMOVL32rm GR32:$src2, addr:$src1)>; |
| 876 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_LE, EFLAGS), |
| 877 | (CMOVG16rm GR16:$src2, addr:$src1)>; |
| 878 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_LE, EFLAGS), |
| 879 | (CMOVG32rm GR32:$src2, addr:$src1)>; |
| 880 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_G, EFLAGS), |
| 881 | (CMOVLE16rm GR16:$src2, addr:$src1)>; |
| 882 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_G, EFLAGS), |
| 883 | (CMOVLE32rm GR32:$src2, addr:$src1)>; |
| 884 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_P, EFLAGS), |
| 885 | (CMOVNP16rm GR16:$src2, addr:$src1)>; |
| 886 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_P, EFLAGS), |
| 887 | (CMOVNP32rm GR32:$src2, addr:$src1)>; |
| 888 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NP, EFLAGS), |
| 889 | (CMOVP16rm GR16:$src2, addr:$src1)>; |
| 890 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NP, EFLAGS), |
| 891 | (CMOVP32rm GR32:$src2, addr:$src1)>; |
| 892 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_S, EFLAGS), |
| 893 | (CMOVNS16rm GR16:$src2, addr:$src1)>; |
| 894 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_S, EFLAGS), |
| 895 | (CMOVNS32rm GR32:$src2, addr:$src1)>; |
| 896 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NS, EFLAGS), |
| 897 | (CMOVS16rm GR16:$src2, addr:$src1)>; |
| 898 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NS, EFLAGS), |
| 899 | (CMOVS32rm GR32:$src2, addr:$src1)>; |
| 900 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_O, EFLAGS), |
| 901 | (CMOVNO16rm GR16:$src2, addr:$src1)>; |
| 902 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_O, EFLAGS), |
| 903 | (CMOVNO32rm GR32:$src2, addr:$src1)>; |
| 904 | def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NO, EFLAGS), |
| 905 | (CMOVO16rm GR16:$src2, addr:$src1)>; |
| 906 | def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NO, EFLAGS), |
| 907 | (CMOVO32rm GR32:$src2, addr:$src1)>; |
| 908 | |
| 909 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS), |
| 910 | (CMOVAE64rm GR64:$src2, addr:$src1)>; |
| 911 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS), |
| 912 | (CMOVB64rm GR64:$src2, addr:$src1)>; |
| 913 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS), |
| 914 | (CMOVNE64rm GR64:$src2, addr:$src1)>; |
| 915 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS), |
| 916 | (CMOVE64rm GR64:$src2, addr:$src1)>; |
| 917 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS), |
| 918 | (CMOVA64rm GR64:$src2, addr:$src1)>; |
| 919 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS), |
| 920 | (CMOVBE64rm GR64:$src2, addr:$src1)>; |
| 921 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS), |
| 922 | (CMOVGE64rm GR64:$src2, addr:$src1)>; |
| 923 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS), |
| 924 | (CMOVL64rm GR64:$src2, addr:$src1)>; |
| 925 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS), |
| 926 | (CMOVG64rm GR64:$src2, addr:$src1)>; |
| 927 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS), |
| 928 | (CMOVLE64rm GR64:$src2, addr:$src1)>; |
| 929 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS), |
| 930 | (CMOVNP64rm GR64:$src2, addr:$src1)>; |
| 931 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS), |
| 932 | (CMOVP64rm GR64:$src2, addr:$src1)>; |
| 933 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS), |
| 934 | (CMOVNS64rm GR64:$src2, addr:$src1)>; |
| 935 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS), |
| 936 | (CMOVS64rm GR64:$src2, addr:$src1)>; |
| 937 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS), |
| 938 | (CMOVNO64rm GR64:$src2, addr:$src1)>; |
| 939 | def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS), |
| 940 | (CMOVO64rm GR64:$src2, addr:$src1)>; |
| 941 | |
| 942 | |
| 943 | // zextload bool -> zextload byte |
| 944 | def : Pat<(zextloadi8i1 addr:$src), (MOV8rm addr:$src)>; |
| 945 | def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>; |
| 946 | def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>; |
| 947 | def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>; |
| 948 | |
| 949 | // extload bool -> extload byte |
| 950 | // When extloading from 16-bit and smaller memory locations into 64-bit |
| 951 | // registers, use zero-extending loads so that the entire 64-bit register is |
| 952 | // defined, avoiding partial-register updates. |
| 953 | |
| 954 | def : Pat<(extloadi8i1 addr:$src), (MOV8rm addr:$src)>; |
| 955 | def : Pat<(extloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>; |
| 956 | def : Pat<(extloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>; |
| 957 | def : Pat<(extloadi16i8 addr:$src), (MOVZX16rm8 addr:$src)>; |
| 958 | def : Pat<(extloadi32i8 addr:$src), (MOVZX32rm8 addr:$src)>; |
| 959 | def : Pat<(extloadi32i16 addr:$src), (MOVZX32rm16 addr:$src)>; |
| 960 | |
| 961 | def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>; |
| 962 | def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>; |
| 963 | def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>; |
| 964 | // For other extloads, use subregs, since the high contents of the register are |
| 965 | // defined after an extload. |
| 966 | def : Pat<(extloadi64i32 addr:$src), |
| 967 | (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src), |
| 968 | sub_32bit)>; |
| 969 | |
| 970 | // anyext. Define these to do an explicit zero-extend to |
| 971 | // avoid partial-register updates. |
| 972 | def : Pat<(i16 (anyext GR8 :$src)), (MOVZX16rr8 GR8 :$src)>; |
| 973 | def : Pat<(i32 (anyext GR8 :$src)), (MOVZX32rr8 GR8 :$src)>; |
| 974 | |
| 975 | // Except for i16 -> i32 since isel expect i16 ops to be promoted to i32. |
| 976 | def : Pat<(i32 (anyext GR16:$src)), |
| 977 | (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR16:$src, sub_16bit)>; |
| 978 | |
| 979 | def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>; |
| 980 | def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>; |
| 981 | def : Pat<(i64 (anyext GR32:$src)), |
| 982 | (SUBREG_TO_REG (i64 0), GR32:$src, sub_32bit)>; |
| 983 | |
| 984 | //===----------------------------------------------------------------------===// |
| 985 | // Some peepholes |
| 986 | //===----------------------------------------------------------------------===// |
| 987 | |
| 988 | // Odd encoding trick: -128 fits into an 8-bit immediate field while |
| 989 | // +128 doesn't, so in this special case use a sub instead of an add. |
| 990 | def : Pat<(add GR16:$src1, 128), |
| 991 | (SUB16ri8 GR16:$src1, -128)>; |
| 992 | def : Pat<(store (add (loadi16 addr:$dst), 128), addr:$dst), |
| 993 | (SUB16mi8 addr:$dst, -128)>; |
| 994 | |
| 995 | def : Pat<(add GR32:$src1, 128), |
| 996 | (SUB32ri8 GR32:$src1, -128)>; |
| 997 | def : Pat<(store (add (loadi32 addr:$dst), 128), addr:$dst), |
| 998 | (SUB32mi8 addr:$dst, -128)>; |
| 999 | |
| 1000 | def : Pat<(add GR64:$src1, 128), |
| 1001 | (SUB64ri8 GR64:$src1, -128)>; |
| 1002 | def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst), |
| 1003 | (SUB64mi8 addr:$dst, -128)>; |
| 1004 | |
| 1005 | // The same trick applies for 32-bit immediate fields in 64-bit |
| 1006 | // instructions. |
| 1007 | def : Pat<(add GR64:$src1, 0x0000000080000000), |
| 1008 | (SUB64ri32 GR64:$src1, 0xffffffff80000000)>; |
| 1009 | def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst), |
| 1010 | (SUB64mi32 addr:$dst, 0xffffffff80000000)>; |
| 1011 | |
| 1012 | // Use a 32-bit and with implicit zero-extension instead of a 64-bit and if it |
| 1013 | // has an immediate with at least 32 bits of leading zeros, to avoid needing to |
| 1014 | // materialize that immediate in a register first. |
| 1015 | def : Pat<(and GR64:$src, i64immZExt32:$imm), |
| 1016 | (SUBREG_TO_REG |
| 1017 | (i64 0), |
| 1018 | (AND32ri |
| 1019 | (EXTRACT_SUBREG GR64:$src, sub_32bit), |
| 1020 | (i32 (GetLo32XForm imm:$imm))), |
| 1021 | sub_32bit)>; |
| 1022 | |
| 1023 | |
| 1024 | // r & (2^16-1) ==> movz |
| 1025 | def : Pat<(and GR32:$src1, 0xffff), |
| 1026 | (MOVZX32rr16 (EXTRACT_SUBREG GR32:$src1, sub_16bit))>; |
| 1027 | // r & (2^8-1) ==> movz |
| 1028 | def : Pat<(and GR32:$src1, 0xff), |
| 1029 | (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src1, |
| 1030 | GR32_ABCD)), |
| 1031 | sub_8bit))>, |
| 1032 | Requires<[In32BitMode]>; |
| 1033 | // r & (2^8-1) ==> movz |
| 1034 | def : Pat<(and GR16:$src1, 0xff), |
| 1035 | (MOVZX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src1, |
| 1036 | GR16_ABCD)), |
| 1037 | sub_8bit))>, |
| 1038 | Requires<[In32BitMode]>; |
| 1039 | |
| 1040 | // r & (2^32-1) ==> movz |
| 1041 | def : Pat<(and GR64:$src, 0x00000000FFFFFFFF), |
| 1042 | (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, sub_32bit))>; |
| 1043 | // r & (2^16-1) ==> movz |
| 1044 | def : Pat<(and GR64:$src, 0xffff), |
| 1045 | (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, sub_16bit)))>; |
| 1046 | // r & (2^8-1) ==> movz |
| 1047 | def : Pat<(and GR64:$src, 0xff), |
| 1048 | (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, sub_8bit)))>; |
| 1049 | // r & (2^8-1) ==> movz |
| 1050 | def : Pat<(and GR32:$src1, 0xff), |
| 1051 | (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, sub_8bit))>, |
| 1052 | Requires<[In64BitMode]>; |
| 1053 | // r & (2^8-1) ==> movz |
| 1054 | def : Pat<(and GR16:$src1, 0xff), |
| 1055 | (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, sub_8bit)))>, |
| 1056 | Requires<[In64BitMode]>; |
| 1057 | |
| 1058 | |
| 1059 | // sext_inreg patterns |
| 1060 | def : Pat<(sext_inreg GR32:$src, i16), |
| 1061 | (MOVSX32rr16 (EXTRACT_SUBREG GR32:$src, sub_16bit))>; |
| 1062 | def : Pat<(sext_inreg GR32:$src, i8), |
| 1063 | (MOVSX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, |
| 1064 | GR32_ABCD)), |
| 1065 | sub_8bit))>, |
| 1066 | Requires<[In32BitMode]>; |
| 1067 | def : Pat<(sext_inreg GR16:$src, i8), |
| 1068 | (MOVSX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, |
| 1069 | GR16_ABCD)), |
| 1070 | sub_8bit))>, |
| 1071 | Requires<[In32BitMode]>; |
| 1072 | |
| 1073 | def : Pat<(sext_inreg GR64:$src, i32), |
| 1074 | (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, sub_32bit))>; |
| 1075 | def : Pat<(sext_inreg GR64:$src, i16), |
| 1076 | (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, sub_16bit))>; |
| 1077 | def : Pat<(sext_inreg GR64:$src, i8), |
| 1078 | (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, sub_8bit))>; |
| 1079 | def : Pat<(sext_inreg GR32:$src, i8), |
| 1080 | (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, sub_8bit))>, |
| 1081 | Requires<[In64BitMode]>; |
| 1082 | def : Pat<(sext_inreg GR16:$src, i8), |
| 1083 | (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, sub_8bit)))>, |
| 1084 | Requires<[In64BitMode]>; |
| 1085 | |
| 1086 | |
| 1087 | // trunc patterns |
| 1088 | def : Pat<(i16 (trunc GR32:$src)), |
| 1089 | (EXTRACT_SUBREG GR32:$src, sub_16bit)>; |
| 1090 | def : Pat<(i8 (trunc GR32:$src)), |
| 1091 | (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)), |
| 1092 | sub_8bit)>, |
| 1093 | Requires<[In32BitMode]>; |
| 1094 | def : Pat<(i8 (trunc GR16:$src)), |
| 1095 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1096 | sub_8bit)>, |
| 1097 | Requires<[In32BitMode]>; |
| 1098 | def : Pat<(i32 (trunc GR64:$src)), |
| 1099 | (EXTRACT_SUBREG GR64:$src, sub_32bit)>; |
| 1100 | def : Pat<(i16 (trunc GR64:$src)), |
| 1101 | (EXTRACT_SUBREG GR64:$src, sub_16bit)>; |
| 1102 | def : Pat<(i8 (trunc GR64:$src)), |
| 1103 | (EXTRACT_SUBREG GR64:$src, sub_8bit)>; |
| 1104 | def : Pat<(i8 (trunc GR32:$src)), |
| 1105 | (EXTRACT_SUBREG GR32:$src, sub_8bit)>, |
| 1106 | Requires<[In64BitMode]>; |
| 1107 | def : Pat<(i8 (trunc GR16:$src)), |
| 1108 | (EXTRACT_SUBREG GR16:$src, sub_8bit)>, |
| 1109 | Requires<[In64BitMode]>; |
| 1110 | |
| 1111 | // h-register tricks |
| 1112 | def : Pat<(i8 (trunc (srl_su GR16:$src, (i8 8)))), |
| 1113 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1114 | sub_8bit_hi)>, |
| 1115 | Requires<[In32BitMode]>; |
| 1116 | def : Pat<(i8 (trunc (srl_su GR32:$src, (i8 8)))), |
| 1117 | (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)), |
| 1118 | sub_8bit_hi)>, |
| 1119 | Requires<[In32BitMode]>; |
| 1120 | def : Pat<(srl GR16:$src, (i8 8)), |
| 1121 | (EXTRACT_SUBREG |
| 1122 | (MOVZX32rr8 |
| 1123 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1124 | sub_8bit_hi)), |
| 1125 | sub_16bit)>, |
| 1126 | Requires<[In32BitMode]>; |
| 1127 | def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))), |
| 1128 | (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, |
| 1129 | GR16_ABCD)), |
| 1130 | sub_8bit_hi))>, |
| 1131 | Requires<[In32BitMode]>; |
| 1132 | def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))), |
| 1133 | (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, |
| 1134 | GR16_ABCD)), |
| 1135 | sub_8bit_hi))>, |
| 1136 | Requires<[In32BitMode]>; |
| 1137 | def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)), |
| 1138 | (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, |
| 1139 | GR32_ABCD)), |
| 1140 | sub_8bit_hi))>, |
| 1141 | Requires<[In32BitMode]>; |
| 1142 | def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)), |
| 1143 | (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, |
| 1144 | GR32_ABCD)), |
| 1145 | sub_8bit_hi))>, |
| 1146 | Requires<[In32BitMode]>; |
| 1147 | |
| 1148 | // h-register tricks. |
| 1149 | // For now, be conservative on x86-64 and use an h-register extract only if the |
| 1150 | // value is immediately zero-extended or stored, which are somewhat common |
| 1151 | // cases. This uses a bunch of code to prevent a register requiring a REX prefix |
| 1152 | // from being allocated in the same instruction as the h register, as there's |
| 1153 | // currently no way to describe this requirement to the register allocator. |
| 1154 | |
| 1155 | // h-register extract and zero-extend. |
| 1156 | def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)), |
| 1157 | (SUBREG_TO_REG |
| 1158 | (i64 0), |
| 1159 | (MOVZX32_NOREXrr8 |
| 1160 | (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)), |
| 1161 | sub_8bit_hi)), |
| 1162 | sub_32bit)>; |
| 1163 | def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)), |
| 1164 | (MOVZX32_NOREXrr8 |
| 1165 | (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)), |
| 1166 | sub_8bit_hi))>, |
| 1167 | Requires<[In64BitMode]>; |
| 1168 | def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)), |
| 1169 | (MOVZX32_NOREXrr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, |
| 1170 | GR32_ABCD)), |
| 1171 | sub_8bit_hi))>, |
| 1172 | Requires<[In64BitMode]>; |
| 1173 | def : Pat<(srl GR16:$src, (i8 8)), |
| 1174 | (EXTRACT_SUBREG |
| 1175 | (MOVZX32_NOREXrr8 |
| 1176 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1177 | sub_8bit_hi)), |
| 1178 | sub_16bit)>, |
| 1179 | Requires<[In64BitMode]>; |
| 1180 | def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))), |
| 1181 | (MOVZX32_NOREXrr8 |
| 1182 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1183 | sub_8bit_hi))>, |
| 1184 | Requires<[In64BitMode]>; |
| 1185 | def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))), |
| 1186 | (MOVZX32_NOREXrr8 |
| 1187 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1188 | sub_8bit_hi))>, |
| 1189 | Requires<[In64BitMode]>; |
| 1190 | def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))), |
| 1191 | (SUBREG_TO_REG |
| 1192 | (i64 0), |
| 1193 | (MOVZX32_NOREXrr8 |
| 1194 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1195 | sub_8bit_hi)), |
| 1196 | sub_32bit)>; |
| 1197 | def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))), |
| 1198 | (SUBREG_TO_REG |
| 1199 | (i64 0), |
| 1200 | (MOVZX32_NOREXrr8 |
| 1201 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1202 | sub_8bit_hi)), |
| 1203 | sub_32bit)>; |
| 1204 | |
| 1205 | // h-register extract and store. |
| 1206 | def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst), |
| 1207 | (MOV8mr_NOREX |
| 1208 | addr:$dst, |
| 1209 | (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)), |
| 1210 | sub_8bit_hi))>; |
| 1211 | def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst), |
| 1212 | (MOV8mr_NOREX |
| 1213 | addr:$dst, |
| 1214 | (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)), |
| 1215 | sub_8bit_hi))>, |
| 1216 | Requires<[In64BitMode]>; |
| 1217 | def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst), |
| 1218 | (MOV8mr_NOREX |
| 1219 | addr:$dst, |
| 1220 | (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)), |
| 1221 | sub_8bit_hi))>, |
| 1222 | Requires<[In64BitMode]>; |
| 1223 | |
| 1224 | |
| 1225 | // (shl x, 1) ==> (add x, x) |
| 1226 | def : Pat<(shl GR8 :$src1, (i8 1)), (ADD8rr GR8 :$src1, GR8 :$src1)>; |
| 1227 | def : Pat<(shl GR16:$src1, (i8 1)), (ADD16rr GR16:$src1, GR16:$src1)>; |
| 1228 | def : Pat<(shl GR32:$src1, (i8 1)), (ADD32rr GR32:$src1, GR32:$src1)>; |
| 1229 | def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>; |
| 1230 | |
| 1231 | // (shl x (and y, 31)) ==> (shl x, y) |
| 1232 | def : Pat<(shl GR8:$src1, (and CL, 31)), |
| 1233 | (SHL8rCL GR8:$src1)>; |
| 1234 | def : Pat<(shl GR16:$src1, (and CL, 31)), |
| 1235 | (SHL16rCL GR16:$src1)>; |
| 1236 | def : Pat<(shl GR32:$src1, (and CL, 31)), |
| 1237 | (SHL32rCL GR32:$src1)>; |
| 1238 | def : Pat<(store (shl (loadi8 addr:$dst), (and CL, 31)), addr:$dst), |
| 1239 | (SHL8mCL addr:$dst)>; |
| 1240 | def : Pat<(store (shl (loadi16 addr:$dst), (and CL, 31)), addr:$dst), |
| 1241 | (SHL16mCL addr:$dst)>; |
| 1242 | def : Pat<(store (shl (loadi32 addr:$dst), (and CL, 31)), addr:$dst), |
| 1243 | (SHL32mCL addr:$dst)>; |
| 1244 | |
| 1245 | def : Pat<(srl GR8:$src1, (and CL, 31)), |
| 1246 | (SHR8rCL GR8:$src1)>; |
| 1247 | def : Pat<(srl GR16:$src1, (and CL, 31)), |
| 1248 | (SHR16rCL GR16:$src1)>; |
| 1249 | def : Pat<(srl GR32:$src1, (and CL, 31)), |
| 1250 | (SHR32rCL GR32:$src1)>; |
| 1251 | def : Pat<(store (srl (loadi8 addr:$dst), (and CL, 31)), addr:$dst), |
| 1252 | (SHR8mCL addr:$dst)>; |
| 1253 | def : Pat<(store (srl (loadi16 addr:$dst), (and CL, 31)), addr:$dst), |
| 1254 | (SHR16mCL addr:$dst)>; |
| 1255 | def : Pat<(store (srl (loadi32 addr:$dst), (and CL, 31)), addr:$dst), |
| 1256 | (SHR32mCL addr:$dst)>; |
| 1257 | |
| 1258 | def : Pat<(sra GR8:$src1, (and CL, 31)), |
| 1259 | (SAR8rCL GR8:$src1)>; |
| 1260 | def : Pat<(sra GR16:$src1, (and CL, 31)), |
| 1261 | (SAR16rCL GR16:$src1)>; |
| 1262 | def : Pat<(sra GR32:$src1, (and CL, 31)), |
| 1263 | (SAR32rCL GR32:$src1)>; |
| 1264 | def : Pat<(store (sra (loadi8 addr:$dst), (and CL, 31)), addr:$dst), |
| 1265 | (SAR8mCL addr:$dst)>; |
| 1266 | def : Pat<(store (sra (loadi16 addr:$dst), (and CL, 31)), addr:$dst), |
| 1267 | (SAR16mCL addr:$dst)>; |
| 1268 | def : Pat<(store (sra (loadi32 addr:$dst), (and CL, 31)), addr:$dst), |
| 1269 | (SAR32mCL addr:$dst)>; |
| 1270 | |
| 1271 | // (shl x (and y, 63)) ==> (shl x, y) |
| 1272 | def : Pat<(shl GR64:$src1, (and CL, 63)), |
| 1273 | (SHL64rCL GR64:$src1)>; |
| 1274 | def : Pat<(store (shl (loadi64 addr:$dst), (and CL, 63)), addr:$dst), |
| 1275 | (SHL64mCL addr:$dst)>; |
| 1276 | |
| 1277 | def : Pat<(srl GR64:$src1, (and CL, 63)), |
| 1278 | (SHR64rCL GR64:$src1)>; |
| 1279 | def : Pat<(store (srl (loadi64 addr:$dst), (and CL, 63)), addr:$dst), |
| 1280 | (SHR64mCL addr:$dst)>; |
| 1281 | |
| 1282 | def : Pat<(sra GR64:$src1, (and CL, 63)), |
| 1283 | (SAR64rCL GR64:$src1)>; |
| 1284 | def : Pat<(store (sra (loadi64 addr:$dst), (and CL, 63)), addr:$dst), |
| 1285 | (SAR64mCL addr:$dst)>; |
| 1286 | |
| 1287 | |
| 1288 | // (anyext (setcc_carry)) -> (setcc_carry) |
| 1289 | def : Pat<(i16 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))), |
| 1290 | (SETB_C16r)>; |
| 1291 | def : Pat<(i32 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))), |
| 1292 | (SETB_C32r)>; |
| 1293 | def : Pat<(i32 (anyext (i16 (X86setcc_c X86_COND_B, EFLAGS)))), |
| 1294 | (SETB_C32r)>; |
| 1295 | |
| 1296 | // (or x1, x2) -> (add x1, x2) if two operands are known not to share bits. |
| 1297 | let AddedComplexity = 5 in { // Try this before the selecting to OR |
| 1298 | def : Pat<(or_is_add GR16:$src1, imm:$src2), |
| 1299 | (ADD16ri GR16:$src1, imm:$src2)>; |
| 1300 | def : Pat<(or_is_add GR32:$src1, imm:$src2), |
| 1301 | (ADD32ri GR32:$src1, imm:$src2)>; |
| 1302 | def : Pat<(or_is_add GR16:$src1, i16immSExt8:$src2), |
| 1303 | (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>; |
| 1304 | def : Pat<(or_is_add GR32:$src1, i32immSExt8:$src2), |
| 1305 | (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>; |
| 1306 | def : Pat<(or_is_add GR16:$src1, GR16:$src2), |
| 1307 | (ADD16rr GR16:$src1, GR16:$src2)>; |
| 1308 | def : Pat<(or_is_add GR32:$src1, GR32:$src2), |
| 1309 | (ADD32rr GR32:$src1, GR32:$src2)>; |
| 1310 | def : Pat<(or_is_add GR64:$src1, i64immSExt8:$src2), |
| 1311 | (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>; |
| 1312 | def : Pat<(or_is_add GR64:$src1, i64immSExt32:$src2), |
| 1313 | (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>; |
| 1314 | def : Pat<(or_is_add GR64:$src1, GR64:$src2), |
| 1315 | (ADD64rr GR64:$src1, GR64:$src2)>; |
| 1316 | } // AddedComplexity |
| 1317 | |
| 1318 | //===----------------------------------------------------------------------===// |
| 1319 | // EFLAGS-defining Patterns |
| 1320 | //===----------------------------------------------------------------------===// |
| 1321 | |
| 1322 | // add reg, reg |
| 1323 | def : Pat<(add GR8 :$src1, GR8 :$src2), (ADD8rr GR8 :$src1, GR8 :$src2)>; |
| 1324 | def : Pat<(add GR16:$src1, GR16:$src2), (ADD16rr GR16:$src1, GR16:$src2)>; |
| 1325 | def : Pat<(add GR32:$src1, GR32:$src2), (ADD32rr GR32:$src1, GR32:$src2)>; |
| 1326 | |
| 1327 | // add reg, mem |
| 1328 | def : Pat<(add GR8:$src1, (loadi8 addr:$src2)), |
| 1329 | (ADD8rm GR8:$src1, addr:$src2)>; |
| 1330 | def : Pat<(add GR16:$src1, (loadi16 addr:$src2)), |
| 1331 | (ADD16rm GR16:$src1, addr:$src2)>; |
| 1332 | def : Pat<(add GR32:$src1, (loadi32 addr:$src2)), |
| 1333 | (ADD32rm GR32:$src1, addr:$src2)>; |
| 1334 | |
| 1335 | // add reg, imm |
| 1336 | def : Pat<(add GR8 :$src1, imm:$src2), (ADD8ri GR8:$src1 , imm:$src2)>; |
| 1337 | def : Pat<(add GR16:$src1, imm:$src2), (ADD16ri GR16:$src1, imm:$src2)>; |
| 1338 | def : Pat<(add GR32:$src1, imm:$src2), (ADD32ri GR32:$src1, imm:$src2)>; |
| 1339 | def : Pat<(add GR16:$src1, i16immSExt8:$src2), |
| 1340 | (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>; |
| 1341 | def : Pat<(add GR32:$src1, i32immSExt8:$src2), |
| 1342 | (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>; |
| 1343 | |
| 1344 | // sub reg, reg |
| 1345 | def : Pat<(sub GR8 :$src1, GR8 :$src2), (SUB8rr GR8 :$src1, GR8 :$src2)>; |
| 1346 | def : Pat<(sub GR16:$src1, GR16:$src2), (SUB16rr GR16:$src1, GR16:$src2)>; |
| 1347 | def : Pat<(sub GR32:$src1, GR32:$src2), (SUB32rr GR32:$src1, GR32:$src2)>; |
| 1348 | |
| 1349 | // sub reg, mem |
| 1350 | def : Pat<(sub GR8:$src1, (loadi8 addr:$src2)), |
| 1351 | (SUB8rm GR8:$src1, addr:$src2)>; |
| 1352 | def : Pat<(sub GR16:$src1, (loadi16 addr:$src2)), |
| 1353 | (SUB16rm GR16:$src1, addr:$src2)>; |
| 1354 | def : Pat<(sub GR32:$src1, (loadi32 addr:$src2)), |
| 1355 | (SUB32rm GR32:$src1, addr:$src2)>; |
| 1356 | |
| 1357 | // sub reg, imm |
| 1358 | def : Pat<(sub GR8:$src1, imm:$src2), |
| 1359 | (SUB8ri GR8:$src1, imm:$src2)>; |
| 1360 | def : Pat<(sub GR16:$src1, imm:$src2), |
| 1361 | (SUB16ri GR16:$src1, imm:$src2)>; |
| 1362 | def : Pat<(sub GR32:$src1, imm:$src2), |
| 1363 | (SUB32ri GR32:$src1, imm:$src2)>; |
| 1364 | def : Pat<(sub GR16:$src1, i16immSExt8:$src2), |
| 1365 | (SUB16ri8 GR16:$src1, i16immSExt8:$src2)>; |
| 1366 | def : Pat<(sub GR32:$src1, i32immSExt8:$src2), |
| 1367 | (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>; |
| 1368 | |
| 1369 | // mul reg, reg |
| 1370 | def : Pat<(mul GR16:$src1, GR16:$src2), |
| 1371 | (IMUL16rr GR16:$src1, GR16:$src2)>; |
| 1372 | def : Pat<(mul GR32:$src1, GR32:$src2), |
| 1373 | (IMUL32rr GR32:$src1, GR32:$src2)>; |
| 1374 | |
| 1375 | // mul reg, mem |
| 1376 | def : Pat<(mul GR16:$src1, (loadi16 addr:$src2)), |
| 1377 | (IMUL16rm GR16:$src1, addr:$src2)>; |
| 1378 | def : Pat<(mul GR32:$src1, (loadi32 addr:$src2)), |
| 1379 | (IMUL32rm GR32:$src1, addr:$src2)>; |
| 1380 | |
| 1381 | // mul reg, imm |
| 1382 | def : Pat<(mul GR16:$src1, imm:$src2), |
| 1383 | (IMUL16rri GR16:$src1, imm:$src2)>; |
| 1384 | def : Pat<(mul GR32:$src1, imm:$src2), |
| 1385 | (IMUL32rri GR32:$src1, imm:$src2)>; |
| 1386 | def : Pat<(mul GR16:$src1, i16immSExt8:$src2), |
| 1387 | (IMUL16rri8 GR16:$src1, i16immSExt8:$src2)>; |
| 1388 | def : Pat<(mul GR32:$src1, i32immSExt8:$src2), |
| 1389 | (IMUL32rri8 GR32:$src1, i32immSExt8:$src2)>; |
| 1390 | |
| 1391 | // reg = mul mem, imm |
| 1392 | def : Pat<(mul (loadi16 addr:$src1), imm:$src2), |
| 1393 | (IMUL16rmi addr:$src1, imm:$src2)>; |
| 1394 | def : Pat<(mul (loadi32 addr:$src1), imm:$src2), |
| 1395 | (IMUL32rmi addr:$src1, imm:$src2)>; |
| 1396 | def : Pat<(mul (loadi16 addr:$src1), i16immSExt8:$src2), |
| 1397 | (IMUL16rmi8 addr:$src1, i16immSExt8:$src2)>; |
| 1398 | def : Pat<(mul (loadi32 addr:$src1), i32immSExt8:$src2), |
| 1399 | (IMUL32rmi8 addr:$src1, i32immSExt8:$src2)>; |
| 1400 | |
| 1401 | // Optimize multiply by 2 with EFLAGS result. |
| 1402 | let AddedComplexity = 2 in { |
| 1403 | def : Pat<(X86smul_flag GR16:$src1, 2), (ADD16rr GR16:$src1, GR16:$src1)>; |
| 1404 | def : Pat<(X86smul_flag GR32:$src1, 2), (ADD32rr GR32:$src1, GR32:$src1)>; |
| 1405 | } |
| 1406 | |
| 1407 | // Patterns for nodes that do not produce flags, for instructions that do. |
| 1408 | |
| 1409 | // addition |
| 1410 | def : Pat<(add GR64:$src1, GR64:$src2), |
| 1411 | (ADD64rr GR64:$src1, GR64:$src2)>; |
| 1412 | def : Pat<(add GR64:$src1, i64immSExt8:$src2), |
| 1413 | (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>; |
| 1414 | def : Pat<(add GR64:$src1, i64immSExt32:$src2), |
| 1415 | (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>; |
| 1416 | def : Pat<(add GR64:$src1, (loadi64 addr:$src2)), |
| 1417 | (ADD64rm GR64:$src1, addr:$src2)>; |
| 1418 | |
| 1419 | // subtraction |
| 1420 | def : Pat<(sub GR64:$src1, GR64:$src2), |
| 1421 | (SUB64rr GR64:$src1, GR64:$src2)>; |
| 1422 | def : Pat<(sub GR64:$src1, (loadi64 addr:$src2)), |
| 1423 | (SUB64rm GR64:$src1, addr:$src2)>; |
| 1424 | def : Pat<(sub GR64:$src1, i64immSExt8:$src2), |
| 1425 | (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>; |
| 1426 | def : Pat<(sub GR64:$src1, i64immSExt32:$src2), |
| 1427 | (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>; |
| 1428 | |
| 1429 | // Multiply |
| 1430 | def : Pat<(mul GR64:$src1, GR64:$src2), |
| 1431 | (IMUL64rr GR64:$src1, GR64:$src2)>; |
| 1432 | def : Pat<(mul GR64:$src1, (loadi64 addr:$src2)), |
| 1433 | (IMUL64rm GR64:$src1, addr:$src2)>; |
| 1434 | def : Pat<(mul GR64:$src1, i64immSExt8:$src2), |
| 1435 | (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>; |
| 1436 | def : Pat<(mul GR64:$src1, i64immSExt32:$src2), |
| 1437 | (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>; |
| 1438 | def : Pat<(mul (loadi64 addr:$src1), i64immSExt8:$src2), |
| 1439 | (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>; |
| 1440 | def : Pat<(mul (loadi64 addr:$src1), i64immSExt32:$src2), |
| 1441 | (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>; |
| 1442 | |
| 1443 | // Increment reg. |
| 1444 | def : Pat<(add GR8 :$src, 1), (INC8r GR8 :$src)>; |
| 1445 | def : Pat<(add GR16:$src, 1), (INC16r GR16:$src)>, Requires<[In32BitMode]>; |
| 1446 | def : Pat<(add GR16:$src, 1), (INC64_16r GR16:$src)>, Requires<[In64BitMode]>; |
| 1447 | def : Pat<(add GR32:$src, 1), (INC32r GR32:$src)>, Requires<[In32BitMode]>; |
| 1448 | def : Pat<(add GR32:$src, 1), (INC64_32r GR32:$src)>, Requires<[In64BitMode]>; |
| 1449 | def : Pat<(add GR64:$src, 1), (INC64r GR64:$src)>; |
| 1450 | |
| 1451 | // Decrement reg. |
| 1452 | def : Pat<(add GR8 :$src, -1), (DEC8r GR8 :$src)>; |
| 1453 | def : Pat<(add GR16:$src, -1), (DEC16r GR16:$src)>, Requires<[In32BitMode]>; |
| 1454 | def : Pat<(add GR16:$src, -1), (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>; |
| 1455 | def : Pat<(add GR32:$src, -1), (DEC32r GR32:$src)>, Requires<[In32BitMode]>; |
| 1456 | def : Pat<(add GR32:$src, -1), (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>; |
| 1457 | def : Pat<(add GR64:$src, -1), (DEC64r GR64:$src)>; |
| 1458 | |
| 1459 | // or reg/reg. |
| 1460 | def : Pat<(or GR8 :$src1, GR8 :$src2), (OR8rr GR8 :$src1, GR8 :$src2)>; |
| 1461 | def : Pat<(or GR16:$src1, GR16:$src2), (OR16rr GR16:$src1, GR16:$src2)>; |
| 1462 | def : Pat<(or GR32:$src1, GR32:$src2), (OR32rr GR32:$src1, GR32:$src2)>; |
| 1463 | def : Pat<(or GR64:$src1, GR64:$src2), (OR64rr GR64:$src1, GR64:$src2)>; |
| 1464 | |
| 1465 | // or reg/mem |
| 1466 | def : Pat<(or GR8:$src1, (loadi8 addr:$src2)), |
| 1467 | (OR8rm GR8:$src1, addr:$src2)>; |
| 1468 | def : Pat<(or GR16:$src1, (loadi16 addr:$src2)), |
| 1469 | (OR16rm GR16:$src1, addr:$src2)>; |
| 1470 | def : Pat<(or GR32:$src1, (loadi32 addr:$src2)), |
| 1471 | (OR32rm GR32:$src1, addr:$src2)>; |
| 1472 | def : Pat<(or GR64:$src1, (loadi64 addr:$src2)), |
| 1473 | (OR64rm GR64:$src1, addr:$src2)>; |
| 1474 | |
| 1475 | // or reg/imm |
| 1476 | def : Pat<(or GR8:$src1 , imm:$src2), (OR8ri GR8 :$src1, imm:$src2)>; |
| 1477 | def : Pat<(or GR16:$src1, imm:$src2), (OR16ri GR16:$src1, imm:$src2)>; |
| 1478 | def : Pat<(or GR32:$src1, imm:$src2), (OR32ri GR32:$src1, imm:$src2)>; |
| 1479 | def : Pat<(or GR16:$src1, i16immSExt8:$src2), |
| 1480 | (OR16ri8 GR16:$src1, i16immSExt8:$src2)>; |
| 1481 | def : Pat<(or GR32:$src1, i32immSExt8:$src2), |
| 1482 | (OR32ri8 GR32:$src1, i32immSExt8:$src2)>; |
| 1483 | def : Pat<(or GR64:$src1, i64immSExt8:$src2), |
| 1484 | (OR64ri8 GR64:$src1, i64immSExt8:$src2)>; |
| 1485 | def : Pat<(or GR64:$src1, i64immSExt32:$src2), |
| 1486 | (OR64ri32 GR64:$src1, i64immSExt32:$src2)>; |
| 1487 | |
| 1488 | // xor reg/reg |
| 1489 | def : Pat<(xor GR8 :$src1, GR8 :$src2), (XOR8rr GR8 :$src1, GR8 :$src2)>; |
| 1490 | def : Pat<(xor GR16:$src1, GR16:$src2), (XOR16rr GR16:$src1, GR16:$src2)>; |
| 1491 | def : Pat<(xor GR32:$src1, GR32:$src2), (XOR32rr GR32:$src1, GR32:$src2)>; |
| 1492 | def : Pat<(xor GR64:$src1, GR64:$src2), (XOR64rr GR64:$src1, GR64:$src2)>; |
| 1493 | |
| 1494 | // xor reg/mem |
| 1495 | def : Pat<(xor GR8:$src1, (loadi8 addr:$src2)), |
| 1496 | (XOR8rm GR8:$src1, addr:$src2)>; |
| 1497 | def : Pat<(xor GR16:$src1, (loadi16 addr:$src2)), |
| 1498 | (XOR16rm GR16:$src1, addr:$src2)>; |
| 1499 | def : Pat<(xor GR32:$src1, (loadi32 addr:$src2)), |
| 1500 | (XOR32rm GR32:$src1, addr:$src2)>; |
| 1501 | def : Pat<(xor GR64:$src1, (loadi64 addr:$src2)), |
| 1502 | (XOR64rm GR64:$src1, addr:$src2)>; |
| 1503 | |
| 1504 | // xor reg/imm |
| 1505 | def : Pat<(xor GR8:$src1, imm:$src2), |
| 1506 | (XOR8ri GR8:$src1, imm:$src2)>; |
| 1507 | def : Pat<(xor GR16:$src1, imm:$src2), |
| 1508 | (XOR16ri GR16:$src1, imm:$src2)>; |
| 1509 | def : Pat<(xor GR32:$src1, imm:$src2), |
| 1510 | (XOR32ri GR32:$src1, imm:$src2)>; |
| 1511 | def : Pat<(xor GR16:$src1, i16immSExt8:$src2), |
| 1512 | (XOR16ri8 GR16:$src1, i16immSExt8:$src2)>; |
| 1513 | def : Pat<(xor GR32:$src1, i32immSExt8:$src2), |
| 1514 | (XOR32ri8 GR32:$src1, i32immSExt8:$src2)>; |
| 1515 | def : Pat<(xor GR64:$src1, i64immSExt8:$src2), |
| 1516 | (XOR64ri8 GR64:$src1, i64immSExt8:$src2)>; |
| 1517 | def : Pat<(xor GR64:$src1, i64immSExt32:$src2), |
| 1518 | (XOR64ri32 GR64:$src1, i64immSExt32:$src2)>; |
| 1519 | |
| 1520 | // and reg/reg |
| 1521 | def : Pat<(and GR8 :$src1, GR8 :$src2), (AND8rr GR8 :$src1, GR8 :$src2)>; |
| 1522 | def : Pat<(and GR16:$src1, GR16:$src2), (AND16rr GR16:$src1, GR16:$src2)>; |
| 1523 | def : Pat<(and GR32:$src1, GR32:$src2), (AND32rr GR32:$src1, GR32:$src2)>; |
| 1524 | def : Pat<(and GR64:$src1, GR64:$src2), (AND64rr GR64:$src1, GR64:$src2)>; |
| 1525 | |
| 1526 | // and reg/mem |
| 1527 | def : Pat<(and GR8:$src1, (loadi8 addr:$src2)), |
| 1528 | (AND8rm GR8:$src1, addr:$src2)>; |
| 1529 | def : Pat<(and GR16:$src1, (loadi16 addr:$src2)), |
| 1530 | (AND16rm GR16:$src1, addr:$src2)>; |
| 1531 | def : Pat<(and GR32:$src1, (loadi32 addr:$src2)), |
| 1532 | (AND32rm GR32:$src1, addr:$src2)>; |
| 1533 | def : Pat<(and GR64:$src1, (loadi64 addr:$src2)), |
| 1534 | (AND64rm GR64:$src1, addr:$src2)>; |
| 1535 | |
| 1536 | // and reg/imm |
| 1537 | def : Pat<(and GR8:$src1, imm:$src2), |
| 1538 | (AND8ri GR8:$src1, imm:$src2)>; |
| 1539 | def : Pat<(and GR16:$src1, imm:$src2), |
| 1540 | (AND16ri GR16:$src1, imm:$src2)>; |
| 1541 | def : Pat<(and GR32:$src1, imm:$src2), |
| 1542 | (AND32ri GR32:$src1, imm:$src2)>; |
| 1543 | def : Pat<(and GR16:$src1, i16immSExt8:$src2), |
| 1544 | (AND16ri8 GR16:$src1, i16immSExt8:$src2)>; |
| 1545 | def : Pat<(and GR32:$src1, i32immSExt8:$src2), |
| 1546 | (AND32ri8 GR32:$src1, i32immSExt8:$src2)>; |
| 1547 | def : Pat<(and GR64:$src1, i64immSExt8:$src2), |
| 1548 | (AND64ri8 GR64:$src1, i64immSExt8:$src2)>; |
| 1549 | def : Pat<(and GR64:$src1, i64immSExt32:$src2), |
| 1550 | (AND64ri32 GR64:$src1, i64immSExt32:$src2)>; |
Chris Lattner | 87be16a | 2010-10-05 06:04:14 +0000 | [diff] [blame] | 1551 | |