X86InstrArithmetic.td 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  1. //===-- X86InstrArithmetic.td - Integer Arithmetic Instrs --*- tablegen -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file describes the integer arithmetic instructions in the X86
  10. // architecture.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. // LEA - Load Effective Address
  15. let SchedRW = [WriteLEA] in {
  16. let hasSideEffects = 0 in
  17. def LEA16r : I<0x8D, MRMSrcMem,
  18. (outs GR16:$dst), (ins anymem:$src),
  19. "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize16;
  20. let isReMaterializable = 1 in
  21. def LEA32r : I<0x8D, MRMSrcMem,
  22. (outs GR32:$dst), (ins anymem:$src),
  23. "lea{l}\t{$src|$dst}, {$dst|$src}",
  24. [(set GR32:$dst, lea32addr:$src)]>,
  25. OpSize32, Requires<[Not64BitMode]>;
  26. def LEA64_32r : I<0x8D, MRMSrcMem,
  27. (outs GR32:$dst), (ins lea64_32mem:$src),
  28. "lea{l}\t{$src|$dst}, {$dst|$src}",
  29. [(set GR32:$dst, lea64_32addr:$src)]>,
  30. OpSize32, Requires<[In64BitMode]>;
  31. let isReMaterializable = 1 in
  32. def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
  33. "lea{q}\t{$src|$dst}, {$dst|$src}",
  34. [(set GR64:$dst, lea64addr:$src)]>;
  35. } // SchedRW
  36. //===----------------------------------------------------------------------===//
  37. // Fixed-Register Multiplication and Division Instructions.
  38. //
  39. // SchedModel info for instruction that loads one value and gets the second
  40. // (and possibly third) value from a register.
  41. // This is used for instructions that put the memory operands before other
  42. // uses.
  43. class SchedLoadReg<X86FoldableSchedWrite Sched> : Sched<[Sched.Folded,
  44. // Memory operand.
  45. ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  46. // Register reads (implicit or explicit).
  47. Sched.ReadAfterFold, Sched.ReadAfterFold]>;
  48. // Extra precision multiplication
  49. // AL is really implied by AX, but the registers in Defs must match the
  50. // SDNode results (i8, i32).
  51. // AL,AH = AL*GR8
  52. let Defs = [AL,EFLAGS,AX], Uses = [AL] in
  53. def MUL8r : I<0xF6, MRM4r, (outs), (ins GR8:$src), "mul{b}\t$src",
  54. // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
  55. // This probably ought to be moved to a def : Pat<> if the
  56. // syntax can be accepted.
  57. [(set AL, (mul AL, GR8:$src)),
  58. (implicit EFLAGS)]>, Sched<[WriteIMul8]>;
  59. // AX,DX = AX*GR16
  60. let Defs = [AX,DX,EFLAGS], Uses = [AX], hasSideEffects = 0 in
  61. def MUL16r : I<0xF7, MRM4r, (outs), (ins GR16:$src),
  62. "mul{w}\t$src",
  63. []>, OpSize16, Sched<[WriteIMul16]>;
  64. // EAX,EDX = EAX*GR32
  65. let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], hasSideEffects = 0 in
  66. def MUL32r : I<0xF7, MRM4r, (outs), (ins GR32:$src),
  67. "mul{l}\t$src",
  68. [/*(set EAX, EDX, EFLAGS, (X86umul_flag EAX, GR32:$src))*/]>,
  69. OpSize32, Sched<[WriteIMul32]>;
  70. // RAX,RDX = RAX*GR64
  71. let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], hasSideEffects = 0 in
  72. def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
  73. "mul{q}\t$src",
  74. [/*(set RAX, RDX, EFLAGS, (X86umul_flag RAX, GR64:$src))*/]>,
  75. Sched<[WriteIMul64]>;
  76. // AL,AH = AL*[mem8]
  77. let Defs = [AL,EFLAGS,AX], Uses = [AL] in
  78. def MUL8m : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
  79. "mul{b}\t$src",
  80. // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
  81. // This probably ought to be moved to a def : Pat<> if the
  82. // syntax can be accepted.
  83. [(set AL, (mul AL, (loadi8 addr:$src))),
  84. (implicit EFLAGS)]>, SchedLoadReg<WriteIMul8>;
  85. // AX,DX = AX*[mem16]
  86. let mayLoad = 1, hasSideEffects = 0 in {
  87. let Defs = [AX,DX,EFLAGS], Uses = [AX] in
  88. def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
  89. "mul{w}\t$src", []>, OpSize16, SchedLoadReg<WriteIMul16>;
  90. // EAX,EDX = EAX*[mem32]
  91. let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
  92. def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
  93. "mul{l}\t$src", []>, OpSize32, SchedLoadReg<WriteIMul32>;
  94. // RAX,RDX = RAX*[mem64]
  95. let Defs = [RAX,RDX,EFLAGS], Uses = [RAX] in
  96. def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
  97. "mul{q}\t$src", []>, SchedLoadReg<WriteIMul64>,
  98. Requires<[In64BitMode]>;
  99. }
  100. let hasSideEffects = 0 in {
  101. // AL,AH = AL*GR8
  102. let Defs = [AL,EFLAGS,AX], Uses = [AL] in
  103. def IMUL8r : I<0xF6, MRM5r, (outs), (ins GR8:$src), "imul{b}\t$src", []>,
  104. Sched<[WriteIMul8]>;
  105. // AX,DX = AX*GR16
  106. let Defs = [AX,DX,EFLAGS], Uses = [AX] in
  107. def IMUL16r : I<0xF7, MRM5r, (outs), (ins GR16:$src), "imul{w}\t$src", []>,
  108. OpSize16, Sched<[WriteIMul16]>;
  109. // EAX,EDX = EAX*GR32
  110. let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
  111. def IMUL32r : I<0xF7, MRM5r, (outs), (ins GR32:$src), "imul{l}\t$src", []>,
  112. OpSize32, Sched<[WriteIMul32]>;
  113. // RAX,RDX = RAX*GR64
  114. let Defs = [RAX,RDX,EFLAGS], Uses = [RAX] in
  115. def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src), "imul{q}\t$src", []>,
  116. Sched<[WriteIMul64]>;
  117. let mayLoad = 1 in {
  118. // AL,AH = AL*[mem8]
  119. let Defs = [AL,EFLAGS,AX], Uses = [AL] in
  120. def IMUL8m : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
  121. "imul{b}\t$src", []>, SchedLoadReg<WriteIMul8>;
  122. // AX,DX = AX*[mem16]
  123. let Defs = [AX,DX,EFLAGS], Uses = [AX] in
  124. def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
  125. "imul{w}\t$src", []>, OpSize16, SchedLoadReg<WriteIMul16>;
  126. // EAX,EDX = EAX*[mem32]
  127. let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
  128. def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
  129. "imul{l}\t$src", []>, OpSize32, SchedLoadReg<WriteIMul32>;
  130. // RAX,RDX = RAX*[mem64]
  131. let Defs = [RAX,RDX,EFLAGS], Uses = [RAX] in
  132. def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
  133. "imul{q}\t$src", []>, SchedLoadReg<WriteIMul64>,
  134. Requires<[In64BitMode]>;
  135. }
  136. } // hasSideEffects
  137. let Defs = [EFLAGS] in {
  138. let Constraints = "$src1 = $dst" in {
  139. let isCommutable = 1 in {
  140. // X = IMUL Y, Z --> X = IMUL Z, Y
  141. // Register-Register Signed Integer Multiply
  142. def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
  143. "imul{w}\t{$src2, $dst|$dst, $src2}",
  144. [(set GR16:$dst, EFLAGS,
  145. (X86smul_flag GR16:$src1, GR16:$src2))]>,
  146. Sched<[WriteIMul16Reg]>, TB, OpSize16;
  147. def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
  148. "imul{l}\t{$src2, $dst|$dst, $src2}",
  149. [(set GR32:$dst, EFLAGS,
  150. (X86smul_flag GR32:$src1, GR32:$src2))]>,
  151. Sched<[WriteIMul32Reg]>, TB, OpSize32;
  152. def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
  153. (ins GR64:$src1, GR64:$src2),
  154. "imul{q}\t{$src2, $dst|$dst, $src2}",
  155. [(set GR64:$dst, EFLAGS,
  156. (X86smul_flag GR64:$src1, GR64:$src2))]>,
  157. Sched<[WriteIMul64Reg]>, TB;
  158. } // isCommutable
  159. // Register-Memory Signed Integer Multiply
  160. def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
  161. (ins GR16:$src1, i16mem:$src2),
  162. "imul{w}\t{$src2, $dst|$dst, $src2}",
  163. [(set GR16:$dst, EFLAGS,
  164. (X86smul_flag GR16:$src1, (loadi16 addr:$src2)))]>,
  165. Sched<[WriteIMul16Reg.Folded, WriteIMul16Reg.ReadAfterFold]>, TB, OpSize16;
  166. def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst),
  167. (ins GR32:$src1, i32mem:$src2),
  168. "imul{l}\t{$src2, $dst|$dst, $src2}",
  169. [(set GR32:$dst, EFLAGS,
  170. (X86smul_flag GR32:$src1, (loadi32 addr:$src2)))]>,
  171. Sched<[WriteIMul32Reg.Folded, WriteIMul32Reg.ReadAfterFold]>, TB, OpSize32;
  172. def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
  173. (ins GR64:$src1, i64mem:$src2),
  174. "imul{q}\t{$src2, $dst|$dst, $src2}",
  175. [(set GR64:$dst, EFLAGS,
  176. (X86smul_flag GR64:$src1, (loadi64 addr:$src2)))]>,
  177. Sched<[WriteIMul64Reg.Folded, WriteIMul32Reg.ReadAfterFold]>, TB;
  178. } // Constraints = "$src1 = $dst"
  179. } // Defs = [EFLAGS]
  180. // Surprisingly enough, these are not two address instructions!
  181. let Defs = [EFLAGS] in {
  182. // NOTE: These are order specific, we want the ri8 forms to be listed
  183. // first so that they are slightly preferred to the ri forms.
  184. // Register-Integer Signed Integer Multiply
  185. def IMUL16rri8 : Ii8<0x6B, MRMSrcReg, // GR16 = GR16*I8
  186. (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
  187. "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  188. [(set GR16:$dst, EFLAGS,
  189. (X86smul_flag GR16:$src1, i16immSExt8:$src2))]>,
  190. Sched<[WriteIMul16Imm]>, OpSize16;
  191. def IMUL16rri : Ii16<0x69, MRMSrcReg, // GR16 = GR16*I16
  192. (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
  193. "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  194. [(set GR16:$dst, EFLAGS,
  195. (X86smul_flag GR16:$src1, imm:$src2))]>,
  196. Sched<[WriteIMul16Imm]>, OpSize16;
  197. def IMUL32rri : Ii32<0x69, MRMSrcReg, // GR32 = GR32*I32
  198. (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
  199. "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  200. [(set GR32:$dst, EFLAGS,
  201. (X86smul_flag GR32:$src1, imm:$src2))]>,
  202. Sched<[WriteIMul32Imm]>, OpSize32;
  203. def IMUL32rri8 : Ii8<0x6B, MRMSrcReg, // GR32 = GR32*I8
  204. (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
  205. "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  206. [(set GR32:$dst, EFLAGS,
  207. (X86smul_flag GR32:$src1, i32immSExt8:$src2))]>,
  208. Sched<[WriteIMul32Imm]>, OpSize32;
  209. def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
  210. (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
  211. "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  212. [(set GR64:$dst, EFLAGS,
  213. (X86smul_flag GR64:$src1, i64immSExt8:$src2))]>,
  214. Sched<[WriteIMul64Imm]>;
  215. def IMUL64rri32 : RIi32S<0x69, MRMSrcReg, // GR64 = GR64*I32
  216. (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
  217. "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  218. [(set GR64:$dst, EFLAGS,
  219. (X86smul_flag GR64:$src1, i64immSExt32:$src2))]>,
  220. Sched<[WriteIMul64Imm]>;
  221. // Memory-Integer Signed Integer Multiply
  222. def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem, // GR16 = [mem16]*I8
  223. (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
  224. "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  225. [(set GR16:$dst, EFLAGS,
  226. (X86smul_flag (loadi16 addr:$src1),
  227. i16immSExt8:$src2))]>,
  228. Sched<[WriteIMul16Imm.Folded]>, OpSize16;
  229. def IMUL16rmi : Ii16<0x69, MRMSrcMem, // GR16 = [mem16]*I16
  230. (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
  231. "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  232. [(set GR16:$dst, EFLAGS,
  233. (X86smul_flag (loadi16 addr:$src1), imm:$src2))]>,
  234. Sched<[WriteIMul16Imm.Folded]>, OpSize16;
  235. def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem, // GR32 = [mem32]*I8
  236. (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
  237. "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  238. [(set GR32:$dst, EFLAGS,
  239. (X86smul_flag (loadi32 addr:$src1),
  240. i32immSExt8:$src2))]>,
  241. Sched<[WriteIMul32Imm.Folded]>, OpSize32;
  242. def IMUL32rmi : Ii32<0x69, MRMSrcMem, // GR32 = [mem32]*I32
  243. (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
  244. "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  245. [(set GR32:$dst, EFLAGS,
  246. (X86smul_flag (loadi32 addr:$src1), imm:$src2))]>,
  247. Sched<[WriteIMul32Imm.Folded]>, OpSize32;
  248. def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
  249. (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
  250. "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  251. [(set GR64:$dst, EFLAGS,
  252. (X86smul_flag (loadi64 addr:$src1),
  253. i64immSExt8:$src2))]>,
  254. Sched<[WriteIMul64Imm.Folded]>;
  255. def IMUL64rmi32 : RIi32S<0x69, MRMSrcMem, // GR64 = [mem64]*I32
  256. (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
  257. "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
  258. [(set GR64:$dst, EFLAGS,
  259. (X86smul_flag (loadi64 addr:$src1),
  260. i64immSExt32:$src2))]>,
  261. Sched<[WriteIMul64Imm.Folded]>;
  262. } // Defs = [EFLAGS]
  263. // unsigned division/remainder
  264. let hasSideEffects = 1 in { // so that we don't speculatively execute
  265. let Defs = [AL,AH,EFLAGS], Uses = [AX] in
  266. def DIV8r : I<0xF6, MRM6r, (outs), (ins GR8:$src), // AX/r8 = AL,AH
  267. "div{b}\t$src", []>, Sched<[WriteDiv8]>;
  268. let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
  269. def DIV16r : I<0xF7, MRM6r, (outs), (ins GR16:$src), // DX:AX/r16 = AX,DX
  270. "div{w}\t$src", []>, Sched<[WriteDiv16]>, OpSize16;
  271. let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
  272. def DIV32r : I<0xF7, MRM6r, (outs), (ins GR32:$src), // EDX:EAX/r32 = EAX,EDX
  273. "div{l}\t$src", []>, Sched<[WriteDiv32]>, OpSize32;
  274. // RDX:RAX/r64 = RAX,RDX
  275. let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in
  276. def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),
  277. "div{q}\t$src", []>, Sched<[WriteDiv64]>;
  278. let mayLoad = 1 in {
  279. let Defs = [AL,AH,EFLAGS], Uses = [AX] in
  280. def DIV8m : I<0xF6, MRM6m, (outs), (ins i8mem:$src), // AX/[mem8] = AL,AH
  281. "div{b}\t$src", []>, SchedLoadReg<WriteDiv8>;
  282. let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
  283. def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src), // DX:AX/[mem16] = AX,DX
  284. "div{w}\t$src", []>, OpSize16, SchedLoadReg<WriteDiv16>;
  285. let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in // EDX:EAX/[mem32] = EAX,EDX
  286. def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),
  287. "div{l}\t$src", []>, SchedLoadReg<WriteDiv32>, OpSize32;
  288. // RDX:RAX/[mem64] = RAX,RDX
  289. let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in
  290. def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),
  291. "div{q}\t$src", []>, SchedLoadReg<WriteDiv64>,
  292. Requires<[In64BitMode]>;
  293. }
  294. // Signed division/remainder.
  295. let Defs = [AL,AH,EFLAGS], Uses = [AX] in
  296. def IDIV8r : I<0xF6, MRM7r, (outs), (ins GR8:$src), // AX/r8 = AL,AH
  297. "idiv{b}\t$src", []>, Sched<[WriteIDiv8]>;
  298. let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
  299. def IDIV16r: I<0xF7, MRM7r, (outs), (ins GR16:$src), // DX:AX/r16 = AX,DX
  300. "idiv{w}\t$src", []>, Sched<[WriteIDiv16]>, OpSize16;
  301. let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
  302. def IDIV32r: I<0xF7, MRM7r, (outs), (ins GR32:$src), // EDX:EAX/r32 = EAX,EDX
  303. "idiv{l}\t$src", []>, Sched<[WriteIDiv32]>, OpSize32;
  304. // RDX:RAX/r64 = RAX,RDX
  305. let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in
  306. def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),
  307. "idiv{q}\t$src", []>, Sched<[WriteIDiv64]>;
  308. let mayLoad = 1 in {
  309. let Defs = [AL,AH,EFLAGS], Uses = [AX] in
  310. def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src), // AX/[mem8] = AL,AH
  311. "idiv{b}\t$src", []>, SchedLoadReg<WriteIDiv8>;
  312. let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
  313. def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src), // DX:AX/[mem16] = AX,DX
  314. "idiv{w}\t$src", []>, OpSize16, SchedLoadReg<WriteIDiv16>;
  315. let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in // EDX:EAX/[mem32] = EAX,EDX
  316. def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src),
  317. "idiv{l}\t$src", []>, OpSize32, SchedLoadReg<WriteIDiv32>;
  318. let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in // RDX:RAX/[mem64] = RAX,RDX
  319. def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),
  320. "idiv{q}\t$src", []>, SchedLoadReg<WriteIDiv64>,
  321. Requires<[In64BitMode]>;
  322. }
  323. } // hasSideEffects = 0
  324. //===----------------------------------------------------------------------===//
  325. // Two address Instructions.
  326. //
  327. // unary instructions
  328. let CodeSize = 2 in {
  329. let Defs = [EFLAGS] in {
  330. let Constraints = "$src1 = $dst", SchedRW = [WriteALU] in {
  331. def NEG8r : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src1),
  332. "neg{b}\t$dst",
  333. [(set GR8:$dst, (ineg GR8:$src1)),
  334. (implicit EFLAGS)]>;
  335. def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
  336. "neg{w}\t$dst",
  337. [(set GR16:$dst, (ineg GR16:$src1)),
  338. (implicit EFLAGS)]>, OpSize16;
  339. def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
  340. "neg{l}\t$dst",
  341. [(set GR32:$dst, (ineg GR32:$src1)),
  342. (implicit EFLAGS)]>, OpSize32;
  343. def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src1), "neg{q}\t$dst",
  344. [(set GR64:$dst, (ineg GR64:$src1)),
  345. (implicit EFLAGS)]>;
  346. } // Constraints = "$src1 = $dst", SchedRW
  347. // Read-modify-write negate.
  348. let SchedRW = [WriteALURMW] in {
  349. def NEG8m : I<0xF6, MRM3m, (outs), (ins i8mem :$dst),
  350. "neg{b}\t$dst",
  351. [(store (ineg (loadi8 addr:$dst)), addr:$dst),
  352. (implicit EFLAGS)]>;
  353. def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst),
  354. "neg{w}\t$dst",
  355. [(store (ineg (loadi16 addr:$dst)), addr:$dst),
  356. (implicit EFLAGS)]>, OpSize16;
  357. def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst),
  358. "neg{l}\t$dst",
  359. [(store (ineg (loadi32 addr:$dst)), addr:$dst),
  360. (implicit EFLAGS)]>, OpSize32;
  361. def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
  362. [(store (ineg (loadi64 addr:$dst)), addr:$dst),
  363. (implicit EFLAGS)]>,
  364. Requires<[In64BitMode]>;
  365. } // SchedRW
  366. } // Defs = [EFLAGS]
  367. // Note: NOT does not set EFLAGS!
  368. let Constraints = "$src1 = $dst", SchedRW = [WriteALU] in {
  369. def NOT8r : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src1),
  370. "not{b}\t$dst",
  371. [(set GR8:$dst, (not GR8:$src1))]>;
  372. def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
  373. "not{w}\t$dst",
  374. [(set GR16:$dst, (not GR16:$src1))]>, OpSize16;
  375. def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
  376. "not{l}\t$dst",
  377. [(set GR32:$dst, (not GR32:$src1))]>, OpSize32;
  378. def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src1), "not{q}\t$dst",
  379. [(set GR64:$dst, (not GR64:$src1))]>;
  380. } // Constraints = "$src1 = $dst", SchedRW
  381. let SchedRW = [WriteALURMW] in {
  382. def NOT8m : I<0xF6, MRM2m, (outs), (ins i8mem :$dst),
  383. "not{b}\t$dst",
  384. [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
  385. def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst),
  386. "not{w}\t$dst",
  387. [(store (not (loadi16 addr:$dst)), addr:$dst)]>,
  388. OpSize16;
  389. def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst),
  390. "not{l}\t$dst",
  391. [(store (not (loadi32 addr:$dst)), addr:$dst)]>,
  392. OpSize32;
  393. def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
  394. [(store (not (loadi64 addr:$dst)), addr:$dst)]>,
  395. Requires<[In64BitMode]>;
  396. } // SchedRW
  397. } // CodeSize
  398. def X86add_flag_nocf : PatFrag<(ops node:$lhs, node:$rhs),
  399. (X86add_flag node:$lhs, node:$rhs), [{
  400. return hasNoCarryFlagUses(SDValue(N, 1));
  401. }]>;
  402. def X86sub_flag_nocf : PatFrag<(ops node:$lhs, node:$rhs),
  403. (X86sub_flag node:$lhs, node:$rhs), [{
  404. // Only use DEC if the result is used.
  405. return !SDValue(N, 0).use_empty() && hasNoCarryFlagUses(SDValue(N, 1));
  406. }]>;
  407. // TODO: inc/dec is slow for P4, but fast for Pentium-M.
  408. let Defs = [EFLAGS] in {
  409. let Constraints = "$src1 = $dst", SchedRW = [WriteALU] in {
  410. let isConvertibleToThreeAddress = 1, CodeSize = 2 in { // Can xform into LEA.
  411. def INC8r : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
  412. "inc{b}\t$dst",
  413. [(set GR8:$dst, EFLAGS, (X86add_flag_nocf GR8:$src1, 1))]>;
  414. def INC16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
  415. "inc{w}\t$dst",
  416. [(set GR16:$dst, EFLAGS, (X86add_flag_nocf GR16:$src1, 1))]>,
  417. OpSize16;
  418. def INC32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
  419. "inc{l}\t$dst",
  420. [(set GR32:$dst, EFLAGS, (X86add_flag_nocf GR32:$src1, 1))]>,
  421. OpSize32;
  422. def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src1), "inc{q}\t$dst",
  423. [(set GR64:$dst, EFLAGS, (X86add_flag_nocf GR64:$src1, 1))]>;
  424. } // isConvertibleToThreeAddress = 1, CodeSize = 2
  425. // Short forms only valid in 32-bit mode. Selected during MCInst lowering.
  426. let CodeSize = 1, hasSideEffects = 0 in {
  427. def INC16r_alt : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1),
  428. "inc{w}\t$dst", []>,
  429. OpSize16, Requires<[Not64BitMode]>;
  430. def INC32r_alt : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1),
  431. "inc{l}\t$dst", []>,
  432. OpSize32, Requires<[Not64BitMode]>;
  433. } // CodeSize = 1, hasSideEffects = 0
  434. } // Constraints = "$src1 = $dst", SchedRW
  435. let CodeSize = 2, SchedRW = [WriteALURMW] in {
  436. let Predicates = [UseIncDec] in {
  437. def INC8m : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
  438. [(store (add (loadi8 addr:$dst), 1), addr:$dst),
  439. (implicit EFLAGS)]>;
  440. def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
  441. [(store (add (loadi16 addr:$dst), 1), addr:$dst),
  442. (implicit EFLAGS)]>, OpSize16;
  443. def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
  444. [(store (add (loadi32 addr:$dst), 1), addr:$dst),
  445. (implicit EFLAGS)]>, OpSize32;
  446. } // Predicates
  447. let Predicates = [UseIncDec, In64BitMode] in {
  448. def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
  449. [(store (add (loadi64 addr:$dst), 1), addr:$dst),
  450. (implicit EFLAGS)]>;
  451. } // Predicates
  452. } // CodeSize = 2, SchedRW
  453. let Constraints = "$src1 = $dst", SchedRW = [WriteALU] in {
  454. let isConvertibleToThreeAddress = 1, CodeSize = 2 in { // Can xform into LEA.
  455. def DEC8r : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
  456. "dec{b}\t$dst",
  457. [(set GR8:$dst, EFLAGS, (X86sub_flag_nocf GR8:$src1, 1))]>;
  458. def DEC16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
  459. "dec{w}\t$dst",
  460. [(set GR16:$dst, EFLAGS, (X86sub_flag_nocf GR16:$src1, 1))]>,
  461. OpSize16;
  462. def DEC32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
  463. "dec{l}\t$dst",
  464. [(set GR32:$dst, EFLAGS, (X86sub_flag_nocf GR32:$src1, 1))]>,
  465. OpSize32;
  466. def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src1), "dec{q}\t$dst",
  467. [(set GR64:$dst, EFLAGS, (X86sub_flag_nocf GR64:$src1, 1))]>;
  468. } // isConvertibleToThreeAddress = 1, CodeSize = 2
  469. // Short forms only valid in 32-bit mode. Selected during MCInst lowering.
  470. let CodeSize = 1, hasSideEffects = 0 in {
  471. def DEC16r_alt : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1),
  472. "dec{w}\t$dst", []>,
  473. OpSize16, Requires<[Not64BitMode]>;
  474. def DEC32r_alt : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1),
  475. "dec{l}\t$dst", []>,
  476. OpSize32, Requires<[Not64BitMode]>;
  477. } // CodeSize = 1, hasSideEffects = 0
  478. } // Constraints = "$src1 = $dst", SchedRW
  479. let CodeSize = 2, SchedRW = [WriteALURMW] in {
  480. let Predicates = [UseIncDec] in {
  481. def DEC8m : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
  482. [(store (add (loadi8 addr:$dst), -1), addr:$dst),
  483. (implicit EFLAGS)]>;
  484. def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
  485. [(store (add (loadi16 addr:$dst), -1), addr:$dst),
  486. (implicit EFLAGS)]>, OpSize16;
  487. def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
  488. [(store (add (loadi32 addr:$dst), -1), addr:$dst),
  489. (implicit EFLAGS)]>, OpSize32;
  490. } // Predicates
  491. let Predicates = [UseIncDec, In64BitMode] in {
  492. def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
  493. [(store (add (loadi64 addr:$dst), -1), addr:$dst),
  494. (implicit EFLAGS)]>;
  495. } // Predicates
  496. } // CodeSize = 2, SchedRW
  497. } // Defs = [EFLAGS]
  498. /// X86TypeInfo - This is a bunch of information that describes relevant X86
  499. /// information about value types. For example, it can tell you what the
  500. /// register class and preferred load to use.
  501. class X86TypeInfo<ValueType vt, string instrsuffix, RegisterClass regclass,
  502. PatFrag loadnode, X86MemOperand memoperand, ImmType immkind,
  503. Operand immoperand, SDPatternOperator immoperator,
  504. Operand imm8operand, SDPatternOperator imm8operator,
  505. bit hasOddOpcode, OperandSize opSize,
  506. bit hasREX_W> {
  507. /// VT - This is the value type itself.
  508. ValueType VT = vt;
  509. /// InstrSuffix - This is the suffix used on instructions with this type. For
  510. /// example, i8 -> "b", i16 -> "w", i32 -> "l", i64 -> "q".
  511. string InstrSuffix = instrsuffix;
  512. /// RegClass - This is the register class associated with this type. For
  513. /// example, i8 -> GR8, i16 -> GR16, i32 -> GR32, i64 -> GR64.
  514. RegisterClass RegClass = regclass;
  515. /// LoadNode - This is the load node associated with this type. For
  516. /// example, i8 -> loadi8, i16 -> loadi16, i32 -> loadi32, i64 -> loadi64.
  517. PatFrag LoadNode = loadnode;
  518. /// MemOperand - This is the memory operand associated with this type. For
  519. /// example, i8 -> i8mem, i16 -> i16mem, i32 -> i32mem, i64 -> i64mem.
  520. X86MemOperand MemOperand = memoperand;
  521. /// ImmEncoding - This is the encoding of an immediate of this type. For
  522. /// example, i8 -> Imm8, i16 -> Imm16, i32 -> Imm32. Note that i64 -> Imm32
  523. /// since the immediate fields of i64 instructions is a 32-bit sign extended
  524. /// value.
  525. ImmType ImmEncoding = immkind;
  526. /// ImmOperand - This is the operand kind of an immediate of this type. For
  527. /// example, i8 -> i8imm, i16 -> i16imm, i32 -> i32imm. Note that i64 ->
  528. /// i64i32imm since the immediate fields of i64 instructions is a 32-bit sign
  529. /// extended value.
  530. Operand ImmOperand = immoperand;
  531. /// ImmOperator - This is the operator that should be used to match an
  532. /// immediate of this kind in a pattern (e.g. imm, or i64immSExt32).
  533. SDPatternOperator ImmOperator = immoperator;
  534. /// Imm8Operand - This is the operand kind to use for an imm8 of this type.
  535. /// For example, i8 -> <invalid>, i16 -> i16i8imm, i32 -> i32i8imm. This is
  536. /// only used for instructions that have a sign-extended imm8 field form.
  537. Operand Imm8Operand = imm8operand;
  538. /// Imm8Operator - This is the operator that should be used to match an 8-bit
  539. /// sign extended immediate of this kind in a pattern (e.g. imm16immSExt8).
  540. SDPatternOperator Imm8Operator = imm8operator;
  541. /// HasOddOpcode - This bit is true if the instruction should have an odd (as
  542. /// opposed to even) opcode. Operations on i8 are usually even, operations on
  543. /// other datatypes are odd.
  544. bit HasOddOpcode = hasOddOpcode;
  545. /// OpSize - Selects whether the instruction needs a 0x66 prefix based on
  546. /// 16-bit vs 32-bit mode. i8/i64 set this to OpSizeFixed. i16 sets this
  547. /// to Opsize16. i32 sets this to OpSize32.
  548. OperandSize OpSize = opSize;
  549. /// HasREX_W - This bit is set to true if the instruction should have
  550. /// the 0x40 REX prefix. This is set for i64 types.
  551. bit HasREX_W = hasREX_W;
  552. }
  553. def invalid_node : SDNode<"<<invalid_node>>", SDTIntLeaf,[],"<<invalid_node>>">;
  554. def Xi8 : X86TypeInfo<i8, "b", GR8, loadi8, i8mem,
  555. Imm8, i8imm, imm_su, i8imm, invalid_node,
  556. 0, OpSizeFixed, 0>;
  557. def Xi16 : X86TypeInfo<i16, "w", GR16, loadi16, i16mem,
  558. Imm16, i16imm, imm_su, i16i8imm, i16immSExt8_su,
  559. 1, OpSize16, 0>;
  560. def Xi32 : X86TypeInfo<i32, "l", GR32, loadi32, i32mem,
  561. Imm32, i32imm, imm_su, i32i8imm, i32immSExt8_su,
  562. 1, OpSize32, 0>;
  563. def Xi64 : X86TypeInfo<i64, "q", GR64, loadi64, i64mem,
  564. Imm32S, i64i32imm, i64immSExt32_su, i64i8imm, i64immSExt8_su,
  565. 1, OpSizeFixed, 1>;
  566. /// ITy - This instruction base class takes the type info for the instruction.
  567. /// Using this, it:
  568. /// 1. Concatenates together the instruction mnemonic with the appropriate
  569. /// suffix letter, a tab, and the arguments.
  570. /// 2. Infers whether the instruction should have a 0x66 prefix byte.
  571. /// 3. Infers whether the instruction should have a 0x40 REX_W prefix.
  572. /// 4. Infers whether the low bit of the opcode should be 0 (for i8 operations)
  573. /// or 1 (for i16,i32,i64 operations).
  574. class ITy<bits<8> opcode, Format f, X86TypeInfo typeinfo, dag outs, dag ins,
  575. string mnemonic, string args, list<dag> pattern>
  576. : I<{opcode{7}, opcode{6}, opcode{5}, opcode{4},
  577. opcode{3}, opcode{2}, opcode{1}, typeinfo.HasOddOpcode },
  578. f, outs, ins,
  579. !strconcat(mnemonic, "{", typeinfo.InstrSuffix, "}\t", args), pattern> {
  580. // Infer instruction prefixes from type info.
  581. let OpSize = typeinfo.OpSize;
  582. let hasREX_W = typeinfo.HasREX_W;
  583. }
  584. // BinOpRR - Instructions like "add reg, reg, reg".
  585. class BinOpRR<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  586. dag outlist, X86FoldableSchedWrite sched, list<dag> pattern>
  587. : ITy<opcode, MRMDestReg, typeinfo, outlist,
  588. (ins typeinfo.RegClass:$src1, typeinfo.RegClass:$src2),
  589. mnemonic, "{$src2, $src1|$src1, $src2}", pattern>,
  590. Sched<[sched]>;
  591. // BinOpRR_F - Instructions like "cmp reg, Reg", where the pattern has
  592. // just a EFLAGS as a result.
  593. class BinOpRR_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  594. SDPatternOperator opnode>
  595. : BinOpRR<opcode, mnemonic, typeinfo, (outs), WriteALU,
  596. [(set EFLAGS,
  597. (opnode typeinfo.RegClass:$src1, typeinfo.RegClass:$src2))]>;
  598. // BinOpRR_RF - Instructions like "add reg, reg, reg", where the pattern has
  599. // both a regclass and EFLAGS as a result.
  600. class BinOpRR_RF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  601. SDNode opnode>
  602. : BinOpRR<opcode, mnemonic, typeinfo, (outs typeinfo.RegClass:$dst), WriteALU,
  603. [(set typeinfo.RegClass:$dst, EFLAGS,
  604. (opnode typeinfo.RegClass:$src1, typeinfo.RegClass:$src2))]>;
  605. // BinOpRR_RFF - Instructions like "adc reg, reg, reg", where the pattern has
  606. // both a regclass and EFLAGS as a result, and has EFLAGS as input.
  607. class BinOpRR_RFF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  608. SDNode opnode>
  609. : BinOpRR<opcode, mnemonic, typeinfo, (outs typeinfo.RegClass:$dst), WriteADC,
  610. [(set typeinfo.RegClass:$dst, EFLAGS,
  611. (opnode typeinfo.RegClass:$src1, typeinfo.RegClass:$src2,
  612. EFLAGS))]>;
  613. // BinOpRR_Rev - Instructions like "add reg, reg, reg" (reversed encoding).
  614. class BinOpRR_Rev<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  615. X86FoldableSchedWrite sched = WriteALU>
  616. : ITy<opcode, MRMSrcReg, typeinfo,
  617. (outs typeinfo.RegClass:$dst),
  618. (ins typeinfo.RegClass:$src1, typeinfo.RegClass:$src2),
  619. mnemonic, "{$src2, $dst|$dst, $src2}", []>,
  620. Sched<[sched]> {
  621. // The disassembler should know about this, but not the asmparser.
  622. let isCodeGenOnly = 1;
  623. let ForceDisassemble = 1;
  624. let hasSideEffects = 0;
  625. }
  626. // BinOpRR_RDD_Rev - Instructions like "adc reg, reg, reg" (reversed encoding).
  627. class BinOpRR_RFF_Rev<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo>
  628. : BinOpRR_Rev<opcode, mnemonic, typeinfo, WriteADC>;
  629. // BinOpRR_F_Rev - Instructions like "cmp reg, reg" (reversed encoding).
  630. class BinOpRR_F_Rev<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo>
  631. : ITy<opcode, MRMSrcReg, typeinfo, (outs),
  632. (ins typeinfo.RegClass:$src1, typeinfo.RegClass:$src2),
  633. mnemonic, "{$src2, $src1|$src1, $src2}", []>,
  634. Sched<[WriteALU]> {
  635. // The disassembler should know about this, but not the asmparser.
  636. let isCodeGenOnly = 1;
  637. let ForceDisassemble = 1;
  638. let hasSideEffects = 0;
  639. }
  640. // BinOpRM - Instructions like "add reg, reg, [mem]".
  641. class BinOpRM<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  642. dag outlist, X86FoldableSchedWrite sched, list<dag> pattern>
  643. : ITy<opcode, MRMSrcMem, typeinfo, outlist,
  644. (ins typeinfo.RegClass:$src1, typeinfo.MemOperand:$src2),
  645. mnemonic, "{$src2, $src1|$src1, $src2}", pattern>,
  646. Sched<[sched.Folded, sched.ReadAfterFold]>;
  647. // BinOpRM - Instructions like "adc reg, reg, [mem]".
  648. // There is an implicit register read at the end of the operand sequence.
  649. class BinOpRM_ImplicitUse<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  650. dag outlist, X86FoldableSchedWrite sched, list<dag> pattern>
  651. : ITy<opcode, MRMSrcMem, typeinfo, outlist,
  652. (ins typeinfo.RegClass:$src1, typeinfo.MemOperand:$src2),
  653. mnemonic, "{$src2, $src1|$src1, $src2}", pattern>,
  654. Sched<[sched.Folded, sched.ReadAfterFold,
  655. // base, scale, index, offset, segment.
  656. ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  657. // implicit register read.
  658. sched.ReadAfterFold]>;
  659. // BinOpRM_F - Instructions like "cmp reg, [mem]".
  660. class BinOpRM_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  661. SDNode opnode>
  662. : BinOpRM<opcode, mnemonic, typeinfo, (outs), WriteALU,
  663. [(set EFLAGS,
  664. (opnode typeinfo.RegClass:$src1, (typeinfo.LoadNode addr:$src2)))]>;
  665. // BinOpRM_RF - Instructions like "add reg, reg, [mem]".
  666. class BinOpRM_RF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  667. SDNode opnode>
  668. : BinOpRM<opcode, mnemonic, typeinfo, (outs typeinfo.RegClass:$dst), WriteALU,
  669. [(set typeinfo.RegClass:$dst, EFLAGS,
  670. (opnode typeinfo.RegClass:$src1, (typeinfo.LoadNode addr:$src2)))]>;
  671. // BinOpRM_RFF - Instructions like "adc reg, reg, [mem]".
  672. class BinOpRM_RFF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  673. SDNode opnode>
  674. : BinOpRM_ImplicitUse<opcode, mnemonic, typeinfo, (outs typeinfo.RegClass:$dst), WriteADC,
  675. [(set typeinfo.RegClass:$dst, EFLAGS,
  676. (opnode typeinfo.RegClass:$src1, (typeinfo.LoadNode addr:$src2),
  677. EFLAGS))]>;
  678. // BinOpRI - Instructions like "add reg, reg, imm".
  679. class BinOpRI<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  680. Format f, dag outlist, X86FoldableSchedWrite sched, list<dag> pattern>
  681. : ITy<opcode, f, typeinfo, outlist,
  682. (ins typeinfo.RegClass:$src1, typeinfo.ImmOperand:$src2),
  683. mnemonic, "{$src2, $src1|$src1, $src2}", pattern>,
  684. Sched<[sched]> {
  685. let ImmT = typeinfo.ImmEncoding;
  686. }
  687. // BinOpRI_F - Instructions like "cmp reg, imm".
  688. class BinOpRI_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  689. SDPatternOperator opnode, Format f>
  690. : BinOpRI<opcode, mnemonic, typeinfo, f, (outs), WriteALU,
  691. [(set EFLAGS,
  692. (opnode typeinfo.RegClass:$src1, typeinfo.ImmOperator:$src2))]>;
  693. // BinOpRI_RF - Instructions like "add reg, reg, imm".
  694. class BinOpRI_RF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  695. SDNode opnode, Format f>
  696. : BinOpRI<opcode, mnemonic, typeinfo, f, (outs typeinfo.RegClass:$dst), WriteALU,
  697. [(set typeinfo.RegClass:$dst, EFLAGS,
  698. (opnode typeinfo.RegClass:$src1, typeinfo.ImmOperator:$src2))]>;
  699. // BinOpRI_RFF - Instructions like "adc reg, reg, imm".
  700. class BinOpRI_RFF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  701. SDNode opnode, Format f>
  702. : BinOpRI<opcode, mnemonic, typeinfo, f, (outs typeinfo.RegClass:$dst), WriteADC,
  703. [(set typeinfo.RegClass:$dst, EFLAGS,
  704. (opnode typeinfo.RegClass:$src1, typeinfo.ImmOperator:$src2,
  705. EFLAGS))]>;
  706. // BinOpRI8 - Instructions like "add reg, reg, imm8".
  707. class BinOpRI8<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  708. Format f, dag outlist, X86FoldableSchedWrite sched, list<dag> pattern>
  709. : ITy<opcode, f, typeinfo, outlist,
  710. (ins typeinfo.RegClass:$src1, typeinfo.Imm8Operand:$src2),
  711. mnemonic, "{$src2, $src1|$src1, $src2}", pattern>,
  712. Sched<[sched]> {
  713. let ImmT = Imm8; // Always 8-bit immediate.
  714. }
  715. // BinOpRI8_F - Instructions like "cmp reg, imm8".
  716. class BinOpRI8_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  717. SDPatternOperator opnode, Format f>
  718. : BinOpRI8<opcode, mnemonic, typeinfo, f, (outs), WriteALU,
  719. [(set EFLAGS,
  720. (opnode typeinfo.RegClass:$src1, typeinfo.Imm8Operator:$src2))]>;
  721. // BinOpRI8_RF - Instructions like "add reg, reg, imm8".
  722. class BinOpRI8_RF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  723. SDPatternOperator opnode, Format f>
  724. : BinOpRI8<opcode, mnemonic, typeinfo, f, (outs typeinfo.RegClass:$dst), WriteALU,
  725. [(set typeinfo.RegClass:$dst, EFLAGS,
  726. (opnode typeinfo.RegClass:$src1, typeinfo.Imm8Operator:$src2))]>;
  727. // BinOpRI8_RFF - Instructions like "adc reg, reg, imm8".
  728. class BinOpRI8_RFF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  729. SDPatternOperator opnode, Format f>
  730. : BinOpRI8<opcode, mnemonic, typeinfo, f, (outs typeinfo.RegClass:$dst), WriteADC,
  731. [(set typeinfo.RegClass:$dst, EFLAGS,
  732. (opnode typeinfo.RegClass:$src1, typeinfo.Imm8Operator:$src2,
  733. EFLAGS))]>;
  734. // BinOpMR - Instructions like "add [mem], reg".
  735. class BinOpMR<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  736. list<dag> pattern>
  737. : ITy<opcode, MRMDestMem, typeinfo,
  738. (outs), (ins typeinfo.MemOperand:$dst, typeinfo.RegClass:$src),
  739. mnemonic, "{$src, $dst|$dst, $src}", pattern>;
  740. // BinOpMR_RMW - Instructions like "add [mem], reg".
  741. class BinOpMR_RMW<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  742. SDNode opnode>
  743. : BinOpMR<opcode, mnemonic, typeinfo,
  744. [(store (opnode (load addr:$dst), typeinfo.RegClass:$src), addr:$dst),
  745. (implicit EFLAGS)]>, Sched<[WriteALURMW,
  746. // base, scale, index, offset, segment
  747. ReadDefault, ReadDefault, ReadDefault,
  748. ReadDefault, ReadDefault,
  749. WriteALU.ReadAfterFold]>; // reg
  750. // BinOpMR_RMW_FF - Instructions like "adc [mem], reg".
  751. class BinOpMR_RMW_FF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  752. SDNode opnode>
  753. : BinOpMR<opcode, mnemonic, typeinfo,
  754. [(store (opnode (load addr:$dst), typeinfo.RegClass:$src, EFLAGS),
  755. addr:$dst),
  756. (implicit EFLAGS)]>, Sched<[WriteADCRMW,
  757. // base, scale, index, offset, segment
  758. ReadDefault, ReadDefault, ReadDefault,
  759. ReadDefault, ReadDefault,
  760. WriteALU.ReadAfterFold, // reg
  761. WriteALU.ReadAfterFold]>; // EFLAGS
  762. // BinOpMR_F - Instructions like "cmp [mem], reg".
  763. class BinOpMR_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  764. SDPatternOperator opnode>
  765. : BinOpMR<opcode, mnemonic, typeinfo,
  766. [(set EFLAGS, (opnode (typeinfo.LoadNode addr:$dst),
  767. typeinfo.RegClass:$src))]>,
  768. Sched<[WriteALU.Folded, ReadDefault, ReadDefault, ReadDefault,
  769. ReadDefault, ReadDefault, WriteALU.ReadAfterFold]>;
  770. // BinOpMI - Instructions like "add [mem], imm".
  771. class BinOpMI<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  772. Format f, list<dag> pattern>
  773. : ITy<opcode, f, typeinfo,
  774. (outs), (ins typeinfo.MemOperand:$dst, typeinfo.ImmOperand:$src),
  775. mnemonic, "{$src, $dst|$dst, $src}", pattern> {
  776. let ImmT = typeinfo.ImmEncoding;
  777. }
  778. // BinOpMI_RMW - Instructions like "add [mem], imm".
  779. class BinOpMI_RMW<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  780. SDNode opnode, Format f>
  781. : BinOpMI<opcode, mnemonic, typeinfo, f,
  782. [(store (opnode (typeinfo.VT (load addr:$dst)),
  783. typeinfo.ImmOperator:$src), addr:$dst),
  784. (implicit EFLAGS)]>, Sched<[WriteALURMW]>;
  785. // BinOpMI_RMW_FF - Instructions like "adc [mem], imm".
  786. class BinOpMI_RMW_FF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  787. SDNode opnode, Format f>
  788. : BinOpMI<opcode, mnemonic, typeinfo, f,
  789. [(store (opnode (typeinfo.VT (load addr:$dst)),
  790. typeinfo.ImmOperator:$src, EFLAGS), addr:$dst),
  791. (implicit EFLAGS)]>, Sched<[WriteADCRMW]>;
  792. // BinOpMI_F - Instructions like "cmp [mem], imm".
  793. class BinOpMI_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  794. SDPatternOperator opnode, Format f>
  795. : BinOpMI<opcode, mnemonic, typeinfo, f,
  796. [(set EFLAGS, (opnode (typeinfo.LoadNode addr:$dst),
  797. typeinfo.ImmOperator:$src))]>,
  798. Sched<[WriteALU.Folded]>;
  799. // BinOpMI8 - Instructions like "add [mem], imm8".
  800. class BinOpMI8<string mnemonic, X86TypeInfo typeinfo,
  801. Format f, list<dag> pattern>
  802. : ITy<0x82, f, typeinfo,
  803. (outs), (ins typeinfo.MemOperand:$dst, typeinfo.Imm8Operand:$src),
  804. mnemonic, "{$src, $dst|$dst, $src}", pattern> {
  805. let ImmT = Imm8; // Always 8-bit immediate.
  806. }
  807. // BinOpMI8_RMW - Instructions like "add [mem], imm8".
  808. class BinOpMI8_RMW<string mnemonic, X86TypeInfo typeinfo,
  809. SDPatternOperator opnode, Format f>
  810. : BinOpMI8<mnemonic, typeinfo, f,
  811. [(store (opnode (load addr:$dst),
  812. typeinfo.Imm8Operator:$src), addr:$dst),
  813. (implicit EFLAGS)]>, Sched<[WriteALURMW]>;
  814. // BinOpMI8_RMW_FF - Instructions like "adc [mem], imm8".
  815. class BinOpMI8_RMW_FF<string mnemonic, X86TypeInfo typeinfo,
  816. SDPatternOperator opnode, Format f>
  817. : BinOpMI8<mnemonic, typeinfo, f,
  818. [(store (opnode (load addr:$dst),
  819. typeinfo.Imm8Operator:$src, EFLAGS), addr:$dst),
  820. (implicit EFLAGS)]>, Sched<[WriteADCRMW]>;
  821. // BinOpMI8_F - Instructions like "cmp [mem], imm8".
  822. class BinOpMI8_F<string mnemonic, X86TypeInfo typeinfo,
  823. SDPatternOperator opnode, Format f>
  824. : BinOpMI8<mnemonic, typeinfo, f,
  825. [(set EFLAGS, (opnode (typeinfo.LoadNode addr:$dst),
  826. typeinfo.Imm8Operator:$src))]>,
  827. Sched<[WriteALU.Folded]>;
  828. // BinOpAI - Instructions like "add %eax, %eax, imm", that imp-def EFLAGS.
  829. class BinOpAI<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  830. Register areg, string operands, X86FoldableSchedWrite sched = WriteALU>
  831. : ITy<opcode, RawFrm, typeinfo,
  832. (outs), (ins typeinfo.ImmOperand:$src),
  833. mnemonic, operands, []>, Sched<[sched]> {
  834. let ImmT = typeinfo.ImmEncoding;
  835. let Uses = [areg];
  836. let Defs = [areg, EFLAGS];
  837. let hasSideEffects = 0;
  838. }
  839. // BinOpAI_RFF - Instructions like "adc %eax, %eax, imm", that implicitly define
  840. // and use EFLAGS.
  841. class BinOpAI_RFF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  842. Register areg, string operands>
  843. : BinOpAI<opcode, mnemonic, typeinfo, areg, operands, WriteADC> {
  844. let Uses = [areg, EFLAGS];
  845. }
  846. // BinOpAI_F - Instructions like "cmp %eax, %eax, imm", that imp-def EFLAGS.
  847. class BinOpAI_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
  848. Register areg, string operands>
  849. : BinOpAI<opcode, mnemonic, typeinfo, areg, operands> {
  850. let Defs = [EFLAGS];
  851. }
  852. /// ArithBinOp_RF - This is an arithmetic binary operator where the pattern is
  853. /// defined with "(set GPR:$dst, EFLAGS, (...".
  854. ///
  855. /// It would be nice to get rid of the second and third argument here, but
  856. /// tblgen can't handle dependent type references aggressively enough: PR8330
  857. multiclass ArithBinOp_RF<bits<8> BaseOpc, bits<8> BaseOpc2, bits<8> BaseOpc4,
  858. string mnemonic, Format RegMRM, Format MemMRM,
  859. SDNode opnodeflag, SDNode opnode,
  860. bit CommutableRR, bit ConvertibleToThreeAddress,
  861. bit ConvertibleToThreeAddressRR> {
  862. let Defs = [EFLAGS] in {
  863. let Constraints = "$src1 = $dst" in {
  864. let isCommutable = CommutableRR in {
  865. let isConvertibleToThreeAddress = ConvertibleToThreeAddressRR in {
  866. def NAME#8rr : BinOpRR_RF<BaseOpc, mnemonic, Xi8 , opnodeflag>;
  867. def NAME#16rr : BinOpRR_RF<BaseOpc, mnemonic, Xi16, opnodeflag>;
  868. def NAME#32rr : BinOpRR_RF<BaseOpc, mnemonic, Xi32, opnodeflag>;
  869. def NAME#64rr : BinOpRR_RF<BaseOpc, mnemonic, Xi64, opnodeflag>;
  870. } // isConvertibleToThreeAddress
  871. } // isCommutable
  872. def NAME#8rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi8>, FoldGenData<NAME#8rr>;
  873. def NAME#16rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi16>, FoldGenData<NAME#16rr>;
  874. def NAME#32rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi32>, FoldGenData<NAME#32rr>;
  875. def NAME#64rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi64>, FoldGenData<NAME#64rr>;
  876. def NAME#8rm : BinOpRM_RF<BaseOpc2, mnemonic, Xi8 , opnodeflag>;
  877. def NAME#16rm : BinOpRM_RF<BaseOpc2, mnemonic, Xi16, opnodeflag>;
  878. def NAME#32rm : BinOpRM_RF<BaseOpc2, mnemonic, Xi32, opnodeflag>;
  879. def NAME#64rm : BinOpRM_RF<BaseOpc2, mnemonic, Xi64, opnodeflag>;
  880. let isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
  881. def NAME#8ri : BinOpRI_RF<0x80, mnemonic, Xi8 , opnodeflag, RegMRM>;
  882. // NOTE: These are order specific, we want the ri8 forms to be listed
  883. // first so that they are slightly preferred to the ri forms.
  884. def NAME#16ri8 : BinOpRI8_RF<0x82, mnemonic, Xi16, opnodeflag, RegMRM>;
  885. def NAME#32ri8 : BinOpRI8_RF<0x82, mnemonic, Xi32, opnodeflag, RegMRM>;
  886. def NAME#64ri8 : BinOpRI8_RF<0x82, mnemonic, Xi64, opnodeflag, RegMRM>;
  887. def NAME#16ri : BinOpRI_RF<0x80, mnemonic, Xi16, opnodeflag, RegMRM>;
  888. def NAME#32ri : BinOpRI_RF<0x80, mnemonic, Xi32, opnodeflag, RegMRM>;
  889. def NAME#64ri32: BinOpRI_RF<0x80, mnemonic, Xi64, opnodeflag, RegMRM>;
  890. }
  891. } // Constraints = "$src1 = $dst"
  892. let mayLoad = 1, mayStore = 1 in {
  893. def NAME#8mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi8 , opnode>;
  894. def NAME#16mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi16, opnode>;
  895. def NAME#32mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi32, opnode>;
  896. def NAME#64mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi64, opnode>;
  897. }
  898. // NOTE: These are order specific, we want the mi8 forms to be listed
  899. // first so that they are slightly preferred to the mi forms.
  900. def NAME#16mi8 : BinOpMI8_RMW<mnemonic, Xi16, opnode, MemMRM>;
  901. def NAME#32mi8 : BinOpMI8_RMW<mnemonic, Xi32, opnode, MemMRM>;
  902. let Predicates = [In64BitMode] in
  903. def NAME#64mi8 : BinOpMI8_RMW<mnemonic, Xi64, opnode, MemMRM>;
  904. def NAME#8mi : BinOpMI_RMW<0x80, mnemonic, Xi8 , opnode, MemMRM>;
  905. def NAME#16mi : BinOpMI_RMW<0x80, mnemonic, Xi16, opnode, MemMRM>;
  906. def NAME#32mi : BinOpMI_RMW<0x80, mnemonic, Xi32, opnode, MemMRM>;
  907. let Predicates = [In64BitMode] in
  908. def NAME#64mi32 : BinOpMI_RMW<0x80, mnemonic, Xi64, opnode, MemMRM>;
  909. // These are for the disassembler since 0x82 opcode behaves like 0x80, but
  910. // not in 64-bit mode.
  911. let Predicates = [Not64BitMode], isCodeGenOnly = 1, ForceDisassemble = 1,
  912. hasSideEffects = 0 in {
  913. let Constraints = "$src1 = $dst" in
  914. def NAME#8ri8 : BinOpRI8_RF<0x82, mnemonic, Xi8, null_frag, RegMRM>;
  915. let mayLoad = 1, mayStore = 1 in
  916. def NAME#8mi8 : BinOpMI8_RMW<mnemonic, Xi8, null_frag, MemMRM>;
  917. }
  918. } // Defs = [EFLAGS]
  919. def NAME#8i8 : BinOpAI<BaseOpc4, mnemonic, Xi8 , AL,
  920. "{$src, %al|al, $src}">;
  921. def NAME#16i16 : BinOpAI<BaseOpc4, mnemonic, Xi16, AX,
  922. "{$src, %ax|ax, $src}">;
  923. def NAME#32i32 : BinOpAI<BaseOpc4, mnemonic, Xi32, EAX,
  924. "{$src, %eax|eax, $src}">;
  925. def NAME#64i32 : BinOpAI<BaseOpc4, mnemonic, Xi64, RAX,
  926. "{$src, %rax|rax, $src}">;
  927. }
  928. /// ArithBinOp_RFF - This is an arithmetic binary operator where the pattern is
  929. /// defined with "(set GPR:$dst, EFLAGS, (node LHS, RHS, EFLAGS))" like ADC and
  930. /// SBB.
  931. ///
  932. /// It would be nice to get rid of the second and third argument here, but
  933. /// tblgen can't handle dependent type references aggressively enough: PR8330
  934. multiclass ArithBinOp_RFF<bits<8> BaseOpc, bits<8> BaseOpc2, bits<8> BaseOpc4,
  935. string mnemonic, Format RegMRM, Format MemMRM,
  936. SDNode opnode, bit CommutableRR,
  937. bit ConvertibleToThreeAddress> {
  938. let Uses = [EFLAGS], Defs = [EFLAGS] in {
  939. let Constraints = "$src1 = $dst" in {
  940. let isCommutable = CommutableRR in {
  941. def NAME#8rr : BinOpRR_RFF<BaseOpc, mnemonic, Xi8 , opnode>;
  942. let isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
  943. def NAME#16rr : BinOpRR_RFF<BaseOpc, mnemonic, Xi16, opnode>;
  944. def NAME#32rr : BinOpRR_RFF<BaseOpc, mnemonic, Xi32, opnode>;
  945. def NAME#64rr : BinOpRR_RFF<BaseOpc, mnemonic, Xi64, opnode>;
  946. } // isConvertibleToThreeAddress
  947. } // isCommutable
  948. def NAME#8rr_REV : BinOpRR_RFF_Rev<BaseOpc2, mnemonic, Xi8>, FoldGenData<NAME#8rr>;
  949. def NAME#16rr_REV : BinOpRR_RFF_Rev<BaseOpc2, mnemonic, Xi16>, FoldGenData<NAME#16rr>;
  950. def NAME#32rr_REV : BinOpRR_RFF_Rev<BaseOpc2, mnemonic, Xi32>, FoldGenData<NAME#32rr>;
  951. def NAME#64rr_REV : BinOpRR_RFF_Rev<BaseOpc2, mnemonic, Xi64>, FoldGenData<NAME#64rr>;
  952. def NAME#8rm : BinOpRM_RFF<BaseOpc2, mnemonic, Xi8 , opnode>;
  953. def NAME#16rm : BinOpRM_RFF<BaseOpc2, mnemonic, Xi16, opnode>;
  954. def NAME#32rm : BinOpRM_RFF<BaseOpc2, mnemonic, Xi32, opnode>;
  955. def NAME#64rm : BinOpRM_RFF<BaseOpc2, mnemonic, Xi64, opnode>;
  956. def NAME#8ri : BinOpRI_RFF<0x80, mnemonic, Xi8 , opnode, RegMRM>;
  957. let isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
  958. // NOTE: These are order specific, we want the ri8 forms to be listed
  959. // first so that they are slightly preferred to the ri forms.
  960. def NAME#16ri8 : BinOpRI8_RFF<0x82, mnemonic, Xi16, opnode, RegMRM>;
  961. def NAME#32ri8 : BinOpRI8_RFF<0x82, mnemonic, Xi32, opnode, RegMRM>;
  962. def NAME#64ri8 : BinOpRI8_RFF<0x82, mnemonic, Xi64, opnode, RegMRM>;
  963. def NAME#16ri : BinOpRI_RFF<0x80, mnemonic, Xi16, opnode, RegMRM>;
  964. def NAME#32ri : BinOpRI_RFF<0x80, mnemonic, Xi32, opnode, RegMRM>;
  965. def NAME#64ri32: BinOpRI_RFF<0x80, mnemonic, Xi64, opnode, RegMRM>;
  966. }
  967. } // Constraints = "$src1 = $dst"
  968. def NAME#8mr : BinOpMR_RMW_FF<BaseOpc, mnemonic, Xi8 , opnode>;
  969. def NAME#16mr : BinOpMR_RMW_FF<BaseOpc, mnemonic, Xi16, opnode>;
  970. def NAME#32mr : BinOpMR_RMW_FF<BaseOpc, mnemonic, Xi32, opnode>;
  971. def NAME#64mr : BinOpMR_RMW_FF<BaseOpc, mnemonic, Xi64, opnode>;
  972. // NOTE: These are order specific, we want the mi8 forms to be listed
  973. // first so that they are slightly preferred to the mi forms.
  974. def NAME#16mi8 : BinOpMI8_RMW_FF<mnemonic, Xi16, opnode, MemMRM>;
  975. def NAME#32mi8 : BinOpMI8_RMW_FF<mnemonic, Xi32, opnode, MemMRM>;
  976. let Predicates = [In64BitMode] in
  977. def NAME#64mi8 : BinOpMI8_RMW_FF<mnemonic, Xi64, opnode, MemMRM>;
  978. def NAME#8mi : BinOpMI_RMW_FF<0x80, mnemonic, Xi8 , opnode, MemMRM>;
  979. def NAME#16mi : BinOpMI_RMW_FF<0x80, mnemonic, Xi16, opnode, MemMRM>;
  980. def NAME#32mi : BinOpMI_RMW_FF<0x80, mnemonic, Xi32, opnode, MemMRM>;
  981. let Predicates = [In64BitMode] in
  982. def NAME#64mi32 : BinOpMI_RMW_FF<0x80, mnemonic, Xi64, opnode, MemMRM>;
  983. // These are for the disassembler since 0x82 opcode behaves like 0x80, but
  984. // not in 64-bit mode.
  985. let Predicates = [Not64BitMode], isCodeGenOnly = 1, ForceDisassemble = 1,
  986. hasSideEffects = 0 in {
  987. let Constraints = "$src1 = $dst" in
  988. def NAME#8ri8 : BinOpRI8_RFF<0x82, mnemonic, Xi8, null_frag, RegMRM>;
  989. let mayLoad = 1, mayStore = 1 in
  990. def NAME#8mi8 : BinOpMI8_RMW_FF<mnemonic, Xi8, null_frag, MemMRM>;
  991. }
  992. } // Uses = [EFLAGS], Defs = [EFLAGS]
  993. def NAME#8i8 : BinOpAI_RFF<BaseOpc4, mnemonic, Xi8 , AL,
  994. "{$src, %al|al, $src}">;
  995. def NAME#16i16 : BinOpAI_RFF<BaseOpc4, mnemonic, Xi16, AX,
  996. "{$src, %ax|ax, $src}">;
  997. def NAME#32i32 : BinOpAI_RFF<BaseOpc4, mnemonic, Xi32, EAX,
  998. "{$src, %eax|eax, $src}">;
  999. def NAME#64i32 : BinOpAI_RFF<BaseOpc4, mnemonic, Xi64, RAX,
  1000. "{$src, %rax|rax, $src}">;
  1001. }
  1002. /// ArithBinOp_F - This is an arithmetic binary operator where the pattern is
  1003. /// defined with "(set EFLAGS, (...". It would be really nice to find a way
  1004. /// to factor this with the other ArithBinOp_*.
  1005. ///
  1006. multiclass ArithBinOp_F<bits<8> BaseOpc, bits<8> BaseOpc2, bits<8> BaseOpc4,
  1007. string mnemonic, Format RegMRM, Format MemMRM,
  1008. SDNode opnode,
  1009. bit CommutableRR, bit ConvertibleToThreeAddress> {
  1010. let Defs = [EFLAGS] in {
  1011. let isCommutable = CommutableRR in {
  1012. def NAME#8rr : BinOpRR_F<BaseOpc, mnemonic, Xi8 , opnode>;
  1013. let isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
  1014. def NAME#16rr : BinOpRR_F<BaseOpc, mnemonic, Xi16, opnode>;
  1015. def NAME#32rr : BinOpRR_F<BaseOpc, mnemonic, Xi32, opnode>;
  1016. def NAME#64rr : BinOpRR_F<BaseOpc, mnemonic, Xi64, opnode>;
  1017. }
  1018. } // isCommutable
  1019. def NAME#8rr_REV : BinOpRR_F_Rev<BaseOpc2, mnemonic, Xi8>, FoldGenData<NAME#8rr>;
  1020. def NAME#16rr_REV : BinOpRR_F_Rev<BaseOpc2, mnemonic, Xi16>, FoldGenData<NAME#16rr>;
  1021. def NAME#32rr_REV : BinOpRR_F_Rev<BaseOpc2, mnemonic, Xi32>, FoldGenData<NAME#32rr>;
  1022. def NAME#64rr_REV : BinOpRR_F_Rev<BaseOpc2, mnemonic, Xi64>, FoldGenData<NAME#64rr>;
  1023. def NAME#8rm : BinOpRM_F<BaseOpc2, mnemonic, Xi8 , opnode>;
  1024. def NAME#16rm : BinOpRM_F<BaseOpc2, mnemonic, Xi16, opnode>;
  1025. def NAME#32rm : BinOpRM_F<BaseOpc2, mnemonic, Xi32, opnode>;
  1026. def NAME#64rm : BinOpRM_F<BaseOpc2, mnemonic, Xi64, opnode>;
  1027. def NAME#8ri : BinOpRI_F<0x80, mnemonic, Xi8 , opnode, RegMRM>;
  1028. let isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
  1029. // NOTE: These are order specific, we want the ri8 forms to be listed
  1030. // first so that they are slightly preferred to the ri forms.
  1031. def NAME#16ri8 : BinOpRI8_F<0x82, mnemonic, Xi16, opnode, RegMRM>;
  1032. def NAME#32ri8 : BinOpRI8_F<0x82, mnemonic, Xi32, opnode, RegMRM>;
  1033. def NAME#64ri8 : BinOpRI8_F<0x82, mnemonic, Xi64, opnode, RegMRM>;
  1034. def NAME#16ri : BinOpRI_F<0x80, mnemonic, Xi16, opnode, RegMRM>;
  1035. def NAME#32ri : BinOpRI_F<0x80, mnemonic, Xi32, opnode, RegMRM>;
  1036. def NAME#64ri32: BinOpRI_F<0x80, mnemonic, Xi64, opnode, RegMRM>;
  1037. }
  1038. def NAME#8mr : BinOpMR_F<BaseOpc, mnemonic, Xi8 , opnode>;
  1039. def NAME#16mr : BinOpMR_F<BaseOpc, mnemonic, Xi16, opnode>;
  1040. def NAME#32mr : BinOpMR_F<BaseOpc, mnemonic, Xi32, opnode>;
  1041. def NAME#64mr : BinOpMR_F<BaseOpc, mnemonic, Xi64, opnode>;
  1042. // NOTE: These are order specific, we want the mi8 forms to be listed
  1043. // first so that they are slightly preferred to the mi forms.
  1044. def NAME#16mi8 : BinOpMI8_F<mnemonic, Xi16, opnode, MemMRM>;
  1045. def NAME#32mi8 : BinOpMI8_F<mnemonic, Xi32, opnode, MemMRM>;
  1046. let Predicates = [In64BitMode] in
  1047. def NAME#64mi8 : BinOpMI8_F<mnemonic, Xi64, opnode, MemMRM>;
  1048. def NAME#8mi : BinOpMI_F<0x80, mnemonic, Xi8 , opnode, MemMRM>;
  1049. def NAME#16mi : BinOpMI_F<0x80, mnemonic, Xi16, opnode, MemMRM>;
  1050. def NAME#32mi : BinOpMI_F<0x80, mnemonic, Xi32, opnode, MemMRM>;
  1051. let Predicates = [In64BitMode] in
  1052. def NAME#64mi32 : BinOpMI_F<0x80, mnemonic, Xi64, opnode, MemMRM>;
  1053. // These are for the disassembler since 0x82 opcode behaves like 0x80, but
  1054. // not in 64-bit mode.
  1055. let Predicates = [Not64BitMode], isCodeGenOnly = 1, ForceDisassemble = 1,
  1056. hasSideEffects = 0 in {
  1057. def NAME#8ri8 : BinOpRI8_F<0x82, mnemonic, Xi8, null_frag, RegMRM>;
  1058. let mayLoad = 1 in
  1059. def NAME#8mi8 : BinOpMI8_F<mnemonic, Xi8, null_frag, MemMRM>;
  1060. }
  1061. } // Defs = [EFLAGS]
  1062. def NAME#8i8 : BinOpAI_F<BaseOpc4, mnemonic, Xi8 , AL,
  1063. "{$src, %al|al, $src}">;
  1064. def NAME#16i16 : BinOpAI_F<BaseOpc4, mnemonic, Xi16, AX,
  1065. "{$src, %ax|ax, $src}">;
  1066. def NAME#32i32 : BinOpAI_F<BaseOpc4, mnemonic, Xi32, EAX,
  1067. "{$src, %eax|eax, $src}">;
  1068. def NAME#64i32 : BinOpAI_F<BaseOpc4, mnemonic, Xi64, RAX,
  1069. "{$src, %rax|rax, $src}">;
  1070. }
  1071. defm AND : ArithBinOp_RF<0x20, 0x22, 0x24, "and", MRM4r, MRM4m,
  1072. X86and_flag, and, 1, 0, 0>;
  1073. defm OR : ArithBinOp_RF<0x08, 0x0A, 0x0C, "or", MRM1r, MRM1m,
  1074. X86or_flag, or, 1, 0, 0>;
  1075. defm XOR : ArithBinOp_RF<0x30, 0x32, 0x34, "xor", MRM6r, MRM6m,
  1076. X86xor_flag, xor, 1, 0, 0>;
  1077. defm ADD : ArithBinOp_RF<0x00, 0x02, 0x04, "add", MRM0r, MRM0m,
  1078. X86add_flag, add, 1, 1, 1>;
  1079. let isCompare = 1 in {
  1080. defm SUB : ArithBinOp_RF<0x28, 0x2A, 0x2C, "sub", MRM5r, MRM5m,
  1081. X86sub_flag, sub, 0, 1, 0>;
  1082. }
  1083. // Version of XOR8rr_NOREX that use GR8_NOREX. This is used by the handling of
  1084. // __builtin_parity where the last step xors an h-register with an l-register.
  1085. let isCodeGenOnly = 1, hasSideEffects = 0, Constraints = "$src1 = $dst",
  1086. Defs = [EFLAGS], isCommutable = 1 in
  1087. def XOR8rr_NOREX : I<0x30, MRMDestReg, (outs GR8_NOREX:$dst),
  1088. (ins GR8_NOREX:$src1, GR8_NOREX:$src2),
  1089. "xor{b}\t{$src2, $dst|$dst, $src2}", []>,
  1090. Sched<[WriteALU]>;
  1091. // Arithmetic.
  1092. defm ADC : ArithBinOp_RFF<0x10, 0x12, 0x14, "adc", MRM2r, MRM2m, X86adc_flag,
  1093. 1, 0>;
  1094. defm SBB : ArithBinOp_RFF<0x18, 0x1A, 0x1C, "sbb", MRM3r, MRM3m, X86sbb_flag,
  1095. 0, 0>;
  1096. let isCompare = 1 in {
  1097. defm CMP : ArithBinOp_F<0x38, 0x3A, 0x3C, "cmp", MRM7r, MRM7m, X86cmp, 0, 0>;
  1098. }
  1099. // Patterns to recognize loads on the LHS of an ADC. We can't make X86adc_flag
  1100. // commutable since it has EFLAGs as an input.
  1101. def : Pat<(X86adc_flag (loadi8 addr:$src2), GR8:$src1, EFLAGS),
  1102. (ADC8rm GR8:$src1, addr:$src2)>;
  1103. def : Pat<(X86adc_flag (loadi16 addr:$src2), GR16:$src1, EFLAGS),
  1104. (ADC16rm GR16:$src1, addr:$src2)>;
  1105. def : Pat<(X86adc_flag (loadi32 addr:$src2), GR32:$src1, EFLAGS),
  1106. (ADC32rm GR32:$src1, addr:$src2)>;
  1107. def : Pat<(X86adc_flag (loadi64 addr:$src2), GR64:$src1, EFLAGS),
  1108. (ADC64rm GR64:$src1, addr:$src2)>;
  1109. // Patterns to recognize RMW ADC with loads in operand 1.
  1110. def : Pat<(store (X86adc_flag GR8:$src, (loadi8 addr:$dst), EFLAGS),
  1111. addr:$dst),
  1112. (ADC8mr addr:$dst, GR8:$src)>;
  1113. def : Pat<(store (X86adc_flag GR16:$src, (loadi16 addr:$dst), EFLAGS),
  1114. addr:$dst),
  1115. (ADC16mr addr:$dst, GR16:$src)>;
  1116. def : Pat<(store (X86adc_flag GR32:$src, (loadi32 addr:$dst), EFLAGS),
  1117. addr:$dst),
  1118. (ADC32mr addr:$dst, GR32:$src)>;
  1119. def : Pat<(store (X86adc_flag GR64:$src, (loadi64 addr:$dst), EFLAGS),
  1120. addr:$dst),
  1121. (ADC64mr addr:$dst, GR64:$src)>;
  1122. // Patterns for basic arithmetic ops with relocImm for the immediate field.
  1123. multiclass ArithBinOp_RF_relocImm_Pats<SDNode OpNodeFlag, SDNode OpNode> {
  1124. def : Pat<(OpNodeFlag GR8:$src1, relocImm8_su:$src2),
  1125. (!cast<Instruction>(NAME#"8ri") GR8:$src1, relocImm8_su:$src2)>;
  1126. def : Pat<(OpNodeFlag GR16:$src1, i16relocImmSExt8_su:$src2),
  1127. (!cast<Instruction>(NAME#"16ri8") GR16:$src1, i16relocImmSExt8_su:$src2)>;
  1128. def : Pat<(OpNodeFlag GR16:$src1, relocImm16_su:$src2),
  1129. (!cast<Instruction>(NAME#"16ri") GR16:$src1, relocImm16_su:$src2)>;
  1130. def : Pat<(OpNodeFlag GR32:$src1, i32relocImmSExt8_su:$src2),
  1131. (!cast<Instruction>(NAME#"32ri8") GR32:$src1, i32relocImmSExt8_su:$src2)>;
  1132. def : Pat<(OpNodeFlag GR32:$src1, relocImm32_su:$src2),
  1133. (!cast<Instruction>(NAME#"32ri") GR32:$src1, relocImm32_su:$src2)>;
  1134. def : Pat<(OpNodeFlag GR64:$src1, i64relocImmSExt8_su:$src2),
  1135. (!cast<Instruction>(NAME#"64ri8") GR64:$src1, i64relocImmSExt8_su:$src2)>;
  1136. def : Pat<(OpNodeFlag GR64:$src1, i64relocImmSExt32_su:$src2),
  1137. (!cast<Instruction>(NAME#"64ri32") GR64:$src1, i64relocImmSExt32_su:$src2)>;
  1138. def : Pat<(store (OpNode (load addr:$dst), relocImm8_su:$src), addr:$dst),
  1139. (!cast<Instruction>(NAME#"8mi") addr:$dst, relocImm8_su:$src)>;
  1140. def : Pat<(store (OpNode (load addr:$dst), i16relocImmSExt8_su:$src), addr:$dst),
  1141. (!cast<Instruction>(NAME#"16mi8") addr:$dst, i16relocImmSExt8_su:$src)>;
  1142. def : Pat<(store (OpNode (load addr:$dst), relocImm16_su:$src), addr:$dst),
  1143. (!cast<Instruction>(NAME#"16mi") addr:$dst, relocImm16_su:$src)>;
  1144. def : Pat<(store (OpNode (load addr:$dst), i32relocImmSExt8_su:$src), addr:$dst),
  1145. (!cast<Instruction>(NAME#"32mi8") addr:$dst, i32relocImmSExt8_su:$src)>;
  1146. def : Pat<(store (OpNode (load addr:$dst), relocImm32_su:$src), addr:$dst),
  1147. (!cast<Instruction>(NAME#"32mi") addr:$dst, relocImm32_su:$src)>;
  1148. def : Pat<(store (OpNode (load addr:$dst), i64relocImmSExt8_su:$src), addr:$dst),
  1149. (!cast<Instruction>(NAME#"64mi8") addr:$dst, i64relocImmSExt8_su:$src)>;
  1150. def : Pat<(store (OpNode (load addr:$dst), i64relocImmSExt32_su:$src), addr:$dst),
  1151. (!cast<Instruction>(NAME#"64mi32") addr:$dst, i64relocImmSExt32_su:$src)>;
  1152. }
  1153. multiclass ArithBinOp_RFF_relocImm_Pats<SDNode OpNodeFlag> {
  1154. def : Pat<(OpNodeFlag GR8:$src1, relocImm8_su:$src2, EFLAGS),
  1155. (!cast<Instruction>(NAME#"8ri") GR8:$src1, relocImm8_su:$src2)>;
  1156. def : Pat<(OpNodeFlag GR16:$src1, i16relocImmSExt8_su:$src2, EFLAGS),
  1157. (!cast<Instruction>(NAME#"16ri8") GR16:$src1, i16relocImmSExt8_su:$src2)>;
  1158. def : Pat<(OpNodeFlag GR16:$src1, relocImm16_su:$src2, EFLAGS),
  1159. (!cast<Instruction>(NAME#"16ri") GR16:$src1, relocImm16_su:$src2)>;
  1160. def : Pat<(OpNodeFlag GR32:$src1, i32relocImmSExt8_su:$src2, EFLAGS),
  1161. (!cast<Instruction>(NAME#"32ri8") GR32:$src1, i32relocImmSExt8_su:$src2)>;
  1162. def : Pat<(OpNodeFlag GR32:$src1, relocImm32_su:$src2, EFLAGS),
  1163. (!cast<Instruction>(NAME#"32ri") GR32:$src1, relocImm32_su:$src2)>;
  1164. def : Pat<(OpNodeFlag GR64:$src1, i64relocImmSExt8_su:$src2, EFLAGS),
  1165. (!cast<Instruction>(NAME#"64ri8") GR64:$src1, i64relocImmSExt8_su:$src2)>;
  1166. def : Pat<(OpNodeFlag GR64:$src1, i64relocImmSExt32_su:$src2, EFLAGS),
  1167. (!cast<Instruction>(NAME#"64ri32") GR64:$src1, i64relocImmSExt32_su:$src2)>;
  1168. def : Pat<(store (OpNodeFlag (load addr:$dst), relocImm8_su:$src, EFLAGS), addr:$dst),
  1169. (!cast<Instruction>(NAME#"8mi") addr:$dst, relocImm8_su:$src)>;
  1170. def : Pat<(store (OpNodeFlag (load addr:$dst), i16relocImmSExt8_su:$src, EFLAGS), addr:$dst),
  1171. (!cast<Instruction>(NAME#"16mi8") addr:$dst, i16relocImmSExt8_su:$src)>;
  1172. def : Pat<(store (OpNodeFlag (load addr:$dst), relocImm16_su:$src, EFLAGS), addr:$dst),
  1173. (!cast<Instruction>(NAME#"16mi") addr:$dst, relocImm16_su:$src)>;
  1174. def : Pat<(store (OpNodeFlag (load addr:$dst), i32relocImmSExt8_su:$src, EFLAGS), addr:$dst),
  1175. (!cast<Instruction>(NAME#"32mi8") addr:$dst, i32relocImmSExt8_su:$src)>;
  1176. def : Pat<(store (OpNodeFlag (load addr:$dst), relocImm32_su:$src, EFLAGS), addr:$dst),
  1177. (!cast<Instruction>(NAME#"32mi") addr:$dst, relocImm32_su:$src)>;
  1178. def : Pat<(store (OpNodeFlag (load addr:$dst), i64relocImmSExt8_su:$src, EFLAGS), addr:$dst),
  1179. (!cast<Instruction>(NAME#"64mi8") addr:$dst, i64relocImmSExt8_su:$src)>;
  1180. def : Pat<(store (OpNodeFlag (load addr:$dst), i64relocImmSExt32_su:$src, EFLAGS), addr:$dst),
  1181. (!cast<Instruction>(NAME#"64mi32") addr:$dst, i64relocImmSExt32_su:$src)>;
  1182. }
  1183. multiclass ArithBinOp_F_relocImm_Pats<SDNode OpNodeFlag> {
  1184. def : Pat<(OpNodeFlag GR8:$src1, relocImm8_su:$src2),
  1185. (!cast<Instruction>(NAME#"8ri") GR8:$src1, relocImm8_su:$src2)>;
  1186. def : Pat<(OpNodeFlag GR16:$src1, i16relocImmSExt8_su:$src2),
  1187. (!cast<Instruction>(NAME#"16ri8") GR16:$src1, i16relocImmSExt8_su:$src2)>;
  1188. def : Pat<(OpNodeFlag GR16:$src1, relocImm16_su:$src2),
  1189. (!cast<Instruction>(NAME#"16ri") GR16:$src1, relocImm16_su:$src2)>;
  1190. def : Pat<(OpNodeFlag GR32:$src1, i32relocImmSExt8_su:$src2),
  1191. (!cast<Instruction>(NAME#"32ri8") GR32:$src1, i32relocImmSExt8_su:$src2)>;
  1192. def : Pat<(OpNodeFlag GR32:$src1, relocImm32_su:$src2),
  1193. (!cast<Instruction>(NAME#"32ri") GR32:$src1, relocImm32_su:$src2)>;
  1194. def : Pat<(OpNodeFlag GR64:$src1, i64relocImmSExt8_su:$src2),
  1195. (!cast<Instruction>(NAME#"64ri8") GR64:$src1, i64relocImmSExt8_su:$src2)>;
  1196. def : Pat<(OpNodeFlag GR64:$src1, i64relocImmSExt32_su:$src2),
  1197. (!cast<Instruction>(NAME#"64ri32") GR64:$src1, i64relocImmSExt32_su:$src2)>;
  1198. def : Pat<(OpNodeFlag (loadi8 addr:$src1), relocImm8_su:$src2),
  1199. (!cast<Instruction>(NAME#"8mi") addr:$src1, relocImm8_su:$src2)>;
  1200. def : Pat<(OpNodeFlag (loadi16 addr:$src1), i16relocImmSExt8_su:$src2),
  1201. (!cast<Instruction>(NAME#"16mi8") addr:$src1, i16relocImmSExt8_su:$src2)>;
  1202. def : Pat<(OpNodeFlag (loadi16 addr:$src1), relocImm16_su:$src2),
  1203. (!cast<Instruction>(NAME#"16mi") addr:$src1, relocImm16_su:$src2)>;
  1204. def : Pat<(OpNodeFlag (loadi32 addr:$src1), i32relocImmSExt8_su:$src2),
  1205. (!cast<Instruction>(NAME#"32mi8") addr:$src1, i32relocImmSExt8_su:$src2)>;
  1206. def : Pat<(OpNodeFlag (loadi32 addr:$src1), relocImm32_su:$src2),
  1207. (!cast<Instruction>(NAME#"32mi") addr:$src1, relocImm32_su:$src2)>;
  1208. def : Pat<(OpNodeFlag (loadi64 addr:$src1), i64relocImmSExt8_su:$src2),
  1209. (!cast<Instruction>(NAME#"64mi8") addr:$src1, i64relocImmSExt8_su:$src2)>;
  1210. def : Pat<(OpNodeFlag (loadi64 addr:$src1), i64relocImmSExt32_su:$src2),
  1211. (!cast<Instruction>(NAME#"64mi32") addr:$src1, i64relocImmSExt32_su:$src2)>;
  1212. }
  1213. defm AND : ArithBinOp_RF_relocImm_Pats<X86and_flag, and>;
  1214. defm OR : ArithBinOp_RF_relocImm_Pats<X86or_flag, or>;
  1215. defm XOR : ArithBinOp_RF_relocImm_Pats<X86xor_flag, xor>;
  1216. defm ADD : ArithBinOp_RF_relocImm_Pats<X86add_flag, add>;
  1217. defm SUB : ArithBinOp_RF_relocImm_Pats<X86sub_flag, sub>;
  1218. defm ADC : ArithBinOp_RFF_relocImm_Pats<X86adc_flag>;
  1219. defm SBB : ArithBinOp_RFF_relocImm_Pats<X86sbb_flag>;
  1220. defm CMP : ArithBinOp_F_relocImm_Pats<X86cmp>;
  1221. // ADC is commutable, but we can't indicate that to tablegen. So manually
  1222. // reverse the operands.
  1223. def : Pat<(X86adc_flag GR8:$src1, relocImm8_su:$src2, EFLAGS),
  1224. (ADC8ri relocImm8_su:$src2, GR8:$src1)>;
  1225. def : Pat<(X86adc_flag i16relocImmSExt8_su:$src2, GR16:$src1, EFLAGS),
  1226. (ADC16ri8 GR16:$src1, i16relocImmSExt8_su:$src2)>;
  1227. def : Pat<(X86adc_flag relocImm16_su:$src2, GR16:$src1, EFLAGS),
  1228. (ADC16ri GR16:$src1, relocImm16_su:$src2)>;
  1229. def : Pat<(X86adc_flag i32relocImmSExt8_su:$src2, GR32:$src1, EFLAGS),
  1230. (ADC32ri8 GR32:$src1, i32relocImmSExt8_su:$src2)>;
  1231. def : Pat<(X86adc_flag relocImm32_su:$src2, GR32:$src1, EFLAGS),
  1232. (ADC32ri GR32:$src1, relocImm32_su:$src2)>;
  1233. def : Pat<(X86adc_flag i64relocImmSExt8_su:$src2, GR64:$src1, EFLAGS),
  1234. (ADC64ri8 GR64:$src1, i64relocImmSExt8_su:$src2)>;
  1235. def : Pat<(X86adc_flag i64relocImmSExt32_su:$src2, GR64:$src1, EFLAGS),
  1236. (ADC64ri32 GR64:$src1, i64relocImmSExt32_su:$src2)>;
  1237. def : Pat<(store (X86adc_flag relocImm8_su:$src, (load addr:$dst), EFLAGS), addr:$dst),
  1238. (ADC8mi addr:$dst, relocImm8_su:$src)>;
  1239. def : Pat<(store (X86adc_flag i16relocImmSExt8_su:$src, (load addr:$dst), EFLAGS), addr:$dst),
  1240. (ADC16mi8 addr:$dst, i16relocImmSExt8_su:$src)>;
  1241. def : Pat<(store (X86adc_flag relocImm16_su:$src, (load addr:$dst), EFLAGS), addr:$dst),
  1242. (ADC16mi addr:$dst, relocImm16_su:$src)>;
  1243. def : Pat<(store (X86adc_flag i32relocImmSExt8_su:$src, (load addr:$dst), EFLAGS), addr:$dst),
  1244. (ADC32mi8 addr:$dst, i32relocImmSExt8_su:$src)>;
  1245. def : Pat<(store (X86adc_flag relocImm32_su:$src, (load addr:$dst), EFLAGS), addr:$dst),
  1246. (ADC32mi addr:$dst, relocImm32_su:$src)>;
  1247. def : Pat<(store (X86adc_flag i64relocImmSExt8_su:$src, (load addr:$dst), EFLAGS), addr:$dst),
  1248. (ADC64mi8 addr:$dst, i64relocImmSExt8_su:$src)>;
  1249. def : Pat<(store (X86adc_flag i64relocImmSExt32_su:$src, (load addr:$dst), EFLAGS), addr:$dst),
  1250. (ADC64mi32 addr:$dst, i64relocImmSExt32_su:$src)>;
  1251. //===----------------------------------------------------------------------===//
  1252. // Semantically, test instructions are similar like AND, except they don't
  1253. // generate a result. From an encoding perspective, they are very different:
  1254. // they don't have all the usual imm8 and REV forms, and are encoded into a
  1255. // different space.
  1256. def X86testpat : PatFrag<(ops node:$lhs, node:$rhs),
  1257. (X86cmp (and_su node:$lhs, node:$rhs), 0)>;
  1258. let isCompare = 1 in {
  1259. let Defs = [EFLAGS] in {
  1260. let isCommutable = 1 in {
  1261. // Avoid selecting these and instead use a test+and. Post processing will
  1262. // combine them. This gives bunch of other patterns that start with
  1263. // and a chance to match.
  1264. def TEST8rr : BinOpRR_F<0x84, "test", Xi8 , null_frag>;
  1265. def TEST16rr : BinOpRR_F<0x84, "test", Xi16, null_frag>;
  1266. def TEST32rr : BinOpRR_F<0x84, "test", Xi32, null_frag>;
  1267. def TEST64rr : BinOpRR_F<0x84, "test", Xi64, null_frag>;
  1268. } // isCommutable
  1269. let hasSideEffects = 0, mayLoad = 1 in {
  1270. def TEST8mr : BinOpMR_F<0x84, "test", Xi8 , null_frag>;
  1271. def TEST16mr : BinOpMR_F<0x84, "test", Xi16, null_frag>;
  1272. def TEST32mr : BinOpMR_F<0x84, "test", Xi32, null_frag>;
  1273. def TEST64mr : BinOpMR_F<0x84, "test", Xi64, null_frag>;
  1274. }
  1275. def TEST8ri : BinOpRI_F<0xF6, "test", Xi8 , X86testpat, MRM0r>;
  1276. def TEST16ri : BinOpRI_F<0xF6, "test", Xi16, X86testpat, MRM0r>;
  1277. def TEST32ri : BinOpRI_F<0xF6, "test", Xi32, X86testpat, MRM0r>;
  1278. def TEST64ri32 : BinOpRI_F<0xF6, "test", Xi64, X86testpat, MRM0r>;
  1279. def TEST8mi : BinOpMI_F<0xF6, "test", Xi8 , X86testpat, MRM0m>;
  1280. def TEST16mi : BinOpMI_F<0xF6, "test", Xi16, X86testpat, MRM0m>;
  1281. def TEST32mi : BinOpMI_F<0xF6, "test", Xi32, X86testpat, MRM0m>;
  1282. let Predicates = [In64BitMode] in
  1283. def TEST64mi32 : BinOpMI_F<0xF6, "test", Xi64, X86testpat, MRM0m>;
  1284. } // Defs = [EFLAGS]
  1285. def TEST8i8 : BinOpAI_F<0xA8, "test", Xi8 , AL,
  1286. "{$src, %al|al, $src}">;
  1287. def TEST16i16 : BinOpAI_F<0xA8, "test", Xi16, AX,
  1288. "{$src, %ax|ax, $src}">;
  1289. def TEST32i32 : BinOpAI_F<0xA8, "test", Xi32, EAX,
  1290. "{$src, %eax|eax, $src}">;
  1291. def TEST64i32 : BinOpAI_F<0xA8, "test", Xi64, RAX,
  1292. "{$src, %rax|rax, $src}">;
  1293. } // isCompare
  1294. // Patterns to match a relocImm into the immediate field.
  1295. def : Pat<(X86testpat GR8:$src1, relocImm8_su:$src2),
  1296. (TEST8ri GR8:$src1, relocImm8_su:$src2)>;
  1297. def : Pat<(X86testpat GR16:$src1, relocImm16_su:$src2),
  1298. (TEST16ri GR16:$src1, relocImm16_su:$src2)>;
  1299. def : Pat<(X86testpat GR32:$src1, relocImm32_su:$src2),
  1300. (TEST32ri GR32:$src1, relocImm32_su:$src2)>;
  1301. def : Pat<(X86testpat GR64:$src1, i64relocImmSExt32_su:$src2),
  1302. (TEST64ri32 GR64:$src1, i64relocImmSExt32_su:$src2)>;
  1303. def : Pat<(X86testpat (loadi8 addr:$src1), relocImm8_su:$src2),
  1304. (TEST8mi addr:$src1, relocImm8_su:$src2)>;
  1305. def : Pat<(X86testpat (loadi16 addr:$src1), relocImm16_su:$src2),
  1306. (TEST16mi addr:$src1, relocImm16_su:$src2)>;
  1307. def : Pat<(X86testpat (loadi32 addr:$src1), relocImm32_su:$src2),
  1308. (TEST32mi addr:$src1, relocImm32_su:$src2)>;
  1309. def : Pat<(X86testpat (loadi64 addr:$src1), i64relocImmSExt32_su:$src2),
  1310. (TEST64mi32 addr:$src1, i64relocImmSExt32_su:$src2)>;
  1311. //===----------------------------------------------------------------------===//
  1312. // ANDN Instruction
  1313. //
  1314. multiclass bmi_andn<string mnemonic, RegisterClass RC, X86MemOperand x86memop,
  1315. PatFrag ld_frag, X86FoldableSchedWrite sched> {
  1316. def rr : I<0xF2, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
  1317. !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
  1318. [(set RC:$dst, EFLAGS, (X86and_flag (not RC:$src1), RC:$src2))]>,
  1319. Sched<[sched]>;
  1320. def rm : I<0xF2, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
  1321. !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
  1322. [(set RC:$dst, EFLAGS,
  1323. (X86and_flag (not RC:$src1), (ld_frag addr:$src2)))]>,
  1324. Sched<[sched.Folded, sched.ReadAfterFold]>;
  1325. }
  1326. // Complexity is reduced to give and with immediate a chance to match first.
  1327. let Predicates = [HasBMI], Defs = [EFLAGS], AddedComplexity = -6 in {
  1328. defm ANDN32 : bmi_andn<"andn{l}", GR32, i32mem, loadi32, WriteALU>, T8PS, VEX_4V;
  1329. defm ANDN64 : bmi_andn<"andn{q}", GR64, i64mem, loadi64, WriteALU>, T8PS, VEX_4V, VEX_W;
  1330. }
  1331. let Predicates = [HasBMI], AddedComplexity = -6 in {
  1332. def : Pat<(and (not GR32:$src1), GR32:$src2),
  1333. (ANDN32rr GR32:$src1, GR32:$src2)>;
  1334. def : Pat<(and (not GR64:$src1), GR64:$src2),
  1335. (ANDN64rr GR64:$src1, GR64:$src2)>;
  1336. def : Pat<(and (not GR32:$src1), (loadi32 addr:$src2)),
  1337. (ANDN32rm GR32:$src1, addr:$src2)>;
  1338. def : Pat<(and (not GR64:$src1), (loadi64 addr:$src2)),
  1339. (ANDN64rm GR64:$src1, addr:$src2)>;
  1340. }
  1341. //===----------------------------------------------------------------------===//
  1342. // MULX Instruction
  1343. //
  1344. multiclass bmi_mulx<string mnemonic, RegisterClass RC, X86MemOperand x86memop,
  1345. X86FoldableSchedWrite sched> {
  1346. let hasSideEffects = 0 in {
  1347. def rr : I<0xF6, MRMSrcReg, (outs RC:$dst1, RC:$dst2), (ins RC:$src),
  1348. !strconcat(mnemonic, "\t{$src, $dst2, $dst1|$dst1, $dst2, $src}"),
  1349. []>, T8XD, VEX_4V, Sched<[WriteIMulH, sched]>;
  1350. let mayLoad = 1 in
  1351. def rm : I<0xF6, MRMSrcMem, (outs RC:$dst1, RC:$dst2), (ins x86memop:$src),
  1352. !strconcat(mnemonic, "\t{$src, $dst2, $dst1|$dst1, $dst2, $src}"),
  1353. []>, T8XD, VEX_4V,
  1354. Sched<[WriteIMulHLd, sched.Folded,
  1355. // Memory operand.
  1356. ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  1357. // Implicit read of EDX/RDX
  1358. sched.ReadAfterFold]>;
  1359. // Pseudo instructions to be used when the low result isn't used. The
  1360. // instruction is defined to keep the high if both destinations are the same.
  1361. def Hrr : PseudoI<(outs RC:$dst), (ins RC:$src),
  1362. []>, Sched<[sched]>;
  1363. let mayLoad = 1 in
  1364. def Hrm : PseudoI<(outs RC:$dst), (ins x86memop:$src),
  1365. []>, Sched<[sched.Folded]>;
  1366. }
  1367. }
  1368. let Predicates = [HasBMI2] in {
  1369. let Uses = [EDX] in
  1370. defm MULX32 : bmi_mulx<"mulx{l}", GR32, i32mem, WriteMULX32>;
  1371. let Uses = [RDX] in
  1372. defm MULX64 : bmi_mulx<"mulx{q}", GR64, i64mem, WriteMULX64>, VEX_W;
  1373. }
  1374. //===----------------------------------------------------------------------===//
  1375. // ADCX and ADOX Instructions
  1376. //
  1377. // We don't have patterns for these as there is no advantage over ADC for
  1378. // most code.
  1379. let Predicates = [HasADX], Defs = [EFLAGS], Uses = [EFLAGS],
  1380. Constraints = "$src1 = $dst", hasSideEffects = 0 in {
  1381. let SchedRW = [WriteADC], isCommutable = 1 in {
  1382. def ADCX32rr : I<0xF6, MRMSrcReg, (outs GR32:$dst),
  1383. (ins GR32:$src1, GR32:$src2),
  1384. "adcx{l}\t{$src2, $dst|$dst, $src2}", []>, T8PD;
  1385. def ADCX64rr : RI<0xF6, MRMSrcReg, (outs GR64:$dst),
  1386. (ins GR64:$src1, GR64:$src2),
  1387. "adcx{q}\t{$src2, $dst|$dst, $src2}", []>, T8PD;
  1388. def ADOX32rr : I<0xF6, MRMSrcReg, (outs GR32:$dst),
  1389. (ins GR32:$src1, GR32:$src2),
  1390. "adox{l}\t{$src2, $dst|$dst, $src2}", []>, T8XS;
  1391. def ADOX64rr : RI<0xF6, MRMSrcReg, (outs GR64:$dst),
  1392. (ins GR64:$src1, GR64:$src2),
  1393. "adox{q}\t{$src2, $dst|$dst, $src2}", []>, T8XS;
  1394. } // SchedRW
  1395. let mayLoad = 1,
  1396. SchedRW = [WriteADC.Folded, WriteADC.ReadAfterFold,
  1397. // Memory operand.
  1398. ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  1399. // Implicit read of EFLAGS
  1400. WriteADC.ReadAfterFold] in {
  1401. def ADCX32rm : I<0xF6, MRMSrcMem, (outs GR32:$dst),
  1402. (ins GR32:$src1, i32mem:$src2),
  1403. "adcx{l}\t{$src2, $dst|$dst, $src2}", []>, T8PD;
  1404. def ADCX64rm : RI<0xF6, MRMSrcMem, (outs GR64:$dst),
  1405. (ins GR64:$src1, i64mem:$src2),
  1406. "adcx{q}\t{$src2, $dst|$dst, $src2}", []>, T8PD;
  1407. def ADOX32rm : I<0xF6, MRMSrcMem, (outs GR32:$dst),
  1408. (ins GR32:$src1, i32mem:$src2),
  1409. "adox{l}\t{$src2, $dst|$dst, $src2}", []>, T8XS;
  1410. def ADOX64rm : RI<0xF6, MRMSrcMem, (outs GR64:$dst),
  1411. (ins GR64:$src1, i64mem:$src2),
  1412. "adox{q}\t{$src2, $dst|$dst, $src2}", []>, T8XS;
  1413. } // mayLoad, SchedRW
  1414. }