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