X86InstComments.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. //===-- X86InstComments.cpp - Generate verbose-asm comments for instrs ----===//
  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 defines functionality used to emit comments about X86 instructions to
  10. // an output stream for -fverbose-asm.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "X86InstComments.h"
  14. #include "X86ATTInstPrinter.h"
  15. #include "X86BaseInfo.h"
  16. #include "X86MCTargetDesc.h"
  17. #include "X86ShuffleDecode.h"
  18. #include "llvm/MC/MCInst.h"
  19. #include "llvm/MC/MCInstrInfo.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. using namespace llvm;
  22. #define CASE_SSE_INS_COMMON(Inst, src) \
  23. case X86::Inst##src:
  24. #define CASE_AVX_INS_COMMON(Inst, Suffix, src) \
  25. case X86::V##Inst##Suffix##src:
  26. #define CASE_MASK_INS_COMMON(Inst, Suffix, src) \
  27. case X86::V##Inst##Suffix##src##k:
  28. #define CASE_MASKZ_INS_COMMON(Inst, Suffix, src) \
  29. case X86::V##Inst##Suffix##src##kz:
  30. #define CASE_AVX512_INS_COMMON(Inst, Suffix, src) \
  31. CASE_AVX_INS_COMMON(Inst, Suffix, src) \
  32. CASE_MASK_INS_COMMON(Inst, Suffix, src) \
  33. CASE_MASKZ_INS_COMMON(Inst, Suffix, src)
  34. #define CASE_MOVDUP(Inst, src) \
  35. CASE_AVX512_INS_COMMON(Inst, Z, r##src) \
  36. CASE_AVX512_INS_COMMON(Inst, Z256, r##src) \
  37. CASE_AVX512_INS_COMMON(Inst, Z128, r##src) \
  38. CASE_AVX_INS_COMMON(Inst, , r##src) \
  39. CASE_AVX_INS_COMMON(Inst, Y, r##src) \
  40. CASE_SSE_INS_COMMON(Inst, r##src)
  41. #define CASE_MASK_MOVDUP(Inst, src) \
  42. CASE_MASK_INS_COMMON(Inst, Z, r##src) \
  43. CASE_MASK_INS_COMMON(Inst, Z256, r##src) \
  44. CASE_MASK_INS_COMMON(Inst, Z128, r##src)
  45. #define CASE_MASKZ_MOVDUP(Inst, src) \
  46. CASE_MASKZ_INS_COMMON(Inst, Z, r##src) \
  47. CASE_MASKZ_INS_COMMON(Inst, Z256, r##src) \
  48. CASE_MASKZ_INS_COMMON(Inst, Z128, r##src)
  49. #define CASE_PMOVZX(Inst, src) \
  50. CASE_AVX512_INS_COMMON(Inst, Z, r##src) \
  51. CASE_AVX512_INS_COMMON(Inst, Z256, r##src) \
  52. CASE_AVX512_INS_COMMON(Inst, Z128, r##src) \
  53. CASE_AVX_INS_COMMON(Inst, , r##src) \
  54. CASE_AVX_INS_COMMON(Inst, Y, r##src) \
  55. CASE_SSE_INS_COMMON(Inst, r##src)
  56. #define CASE_MASK_PMOVZX(Inst, src) \
  57. CASE_MASK_INS_COMMON(Inst, Z, r##src) \
  58. CASE_MASK_INS_COMMON(Inst, Z256, r##src) \
  59. CASE_MASK_INS_COMMON(Inst, Z128, r##src)
  60. #define CASE_MASKZ_PMOVZX(Inst, src) \
  61. CASE_MASKZ_INS_COMMON(Inst, Z, r##src) \
  62. CASE_MASKZ_INS_COMMON(Inst, Z256, r##src) \
  63. CASE_MASKZ_INS_COMMON(Inst, Z128, r##src)
  64. #define CASE_UNPCK(Inst, src) \
  65. CASE_AVX512_INS_COMMON(Inst, Z, r##src) \
  66. CASE_AVX512_INS_COMMON(Inst, Z256, r##src) \
  67. CASE_AVX512_INS_COMMON(Inst, Z128, r##src) \
  68. CASE_AVX_INS_COMMON(Inst, , r##src) \
  69. CASE_AVX_INS_COMMON(Inst, Y, r##src) \
  70. CASE_SSE_INS_COMMON(Inst, r##src)
  71. #define CASE_MASK_UNPCK(Inst, src) \
  72. CASE_MASK_INS_COMMON(Inst, Z, r##src) \
  73. CASE_MASK_INS_COMMON(Inst, Z256, r##src) \
  74. CASE_MASK_INS_COMMON(Inst, Z128, r##src)
  75. #define CASE_MASKZ_UNPCK(Inst, src) \
  76. CASE_MASKZ_INS_COMMON(Inst, Z, r##src) \
  77. CASE_MASKZ_INS_COMMON(Inst, Z256, r##src) \
  78. CASE_MASKZ_INS_COMMON(Inst, Z128, r##src)
  79. #define CASE_SHUF(Inst, suf) \
  80. CASE_AVX512_INS_COMMON(Inst, Z, suf) \
  81. CASE_AVX512_INS_COMMON(Inst, Z256, suf) \
  82. CASE_AVX512_INS_COMMON(Inst, Z128, suf) \
  83. CASE_AVX_INS_COMMON(Inst, , suf) \
  84. CASE_AVX_INS_COMMON(Inst, Y, suf) \
  85. CASE_SSE_INS_COMMON(Inst, suf)
  86. #define CASE_MASK_SHUF(Inst, src) \
  87. CASE_MASK_INS_COMMON(Inst, Z, r##src##i) \
  88. CASE_MASK_INS_COMMON(Inst, Z256, r##src##i) \
  89. CASE_MASK_INS_COMMON(Inst, Z128, r##src##i)
  90. #define CASE_MASKZ_SHUF(Inst, src) \
  91. CASE_MASKZ_INS_COMMON(Inst, Z, r##src##i) \
  92. CASE_MASKZ_INS_COMMON(Inst, Z256, r##src##i) \
  93. CASE_MASKZ_INS_COMMON(Inst, Z128, r##src##i)
  94. #define CASE_VPERMILPI(Inst, src) \
  95. CASE_AVX512_INS_COMMON(Inst, Z, src##i) \
  96. CASE_AVX512_INS_COMMON(Inst, Z256, src##i) \
  97. CASE_AVX512_INS_COMMON(Inst, Z128, src##i) \
  98. CASE_AVX_INS_COMMON(Inst, , src##i) \
  99. CASE_AVX_INS_COMMON(Inst, Y, src##i)
  100. #define CASE_MASK_VPERMILPI(Inst, src) \
  101. CASE_MASK_INS_COMMON(Inst, Z, src##i) \
  102. CASE_MASK_INS_COMMON(Inst, Z256, src##i) \
  103. CASE_MASK_INS_COMMON(Inst, Z128, src##i)
  104. #define CASE_MASKZ_VPERMILPI(Inst, src) \
  105. CASE_MASKZ_INS_COMMON(Inst, Z, src##i) \
  106. CASE_MASKZ_INS_COMMON(Inst, Z256, src##i) \
  107. CASE_MASKZ_INS_COMMON(Inst, Z128, src##i)
  108. #define CASE_VPERM(Inst, src) \
  109. CASE_AVX512_INS_COMMON(Inst, Z, src##i) \
  110. CASE_AVX512_INS_COMMON(Inst, Z256, src##i) \
  111. CASE_AVX_INS_COMMON(Inst, Y, src##i)
  112. #define CASE_MASK_VPERM(Inst, src) \
  113. CASE_MASK_INS_COMMON(Inst, Z, src##i) \
  114. CASE_MASK_INS_COMMON(Inst, Z256, src##i)
  115. #define CASE_MASKZ_VPERM(Inst, src) \
  116. CASE_MASKZ_INS_COMMON(Inst, Z, src##i) \
  117. CASE_MASKZ_INS_COMMON(Inst, Z256, src##i)
  118. #define CASE_VSHUF(Inst, src) \
  119. CASE_AVX512_INS_COMMON(SHUFF##Inst, Z, r##src##i) \
  120. CASE_AVX512_INS_COMMON(SHUFI##Inst, Z, r##src##i) \
  121. CASE_AVX512_INS_COMMON(SHUFF##Inst, Z256, r##src##i) \
  122. CASE_AVX512_INS_COMMON(SHUFI##Inst, Z256, r##src##i)
  123. #define CASE_MASK_VSHUF(Inst, src) \
  124. CASE_MASK_INS_COMMON(SHUFF##Inst, Z, r##src##i) \
  125. CASE_MASK_INS_COMMON(SHUFI##Inst, Z, r##src##i) \
  126. CASE_MASK_INS_COMMON(SHUFF##Inst, Z256, r##src##i) \
  127. CASE_MASK_INS_COMMON(SHUFI##Inst, Z256, r##src##i)
  128. #define CASE_MASKZ_VSHUF(Inst, src) \
  129. CASE_MASKZ_INS_COMMON(SHUFF##Inst, Z, r##src##i) \
  130. CASE_MASKZ_INS_COMMON(SHUFI##Inst, Z, r##src##i) \
  131. CASE_MASKZ_INS_COMMON(SHUFF##Inst, Z256, r##src##i) \
  132. CASE_MASKZ_INS_COMMON(SHUFI##Inst, Z256, r##src##i)
  133. #define CASE_AVX512_FMA(Inst, suf) \
  134. CASE_AVX512_INS_COMMON(Inst, Z, suf) \
  135. CASE_AVX512_INS_COMMON(Inst, Z256, suf) \
  136. CASE_AVX512_INS_COMMON(Inst, Z128, suf)
  137. #define CASE_FMA(Inst, suf) \
  138. CASE_AVX512_FMA(Inst, suf) \
  139. CASE_AVX_INS_COMMON(Inst, , suf) \
  140. CASE_AVX_INS_COMMON(Inst, Y, suf)
  141. #define CASE_FMA_PACKED_REG(Inst) \
  142. CASE_FMA(Inst##PD, r) \
  143. CASE_FMA(Inst##PS, r)
  144. #define CASE_FMA_PACKED_MEM(Inst) \
  145. CASE_FMA(Inst##PD, m) \
  146. CASE_FMA(Inst##PS, m) \
  147. CASE_AVX512_FMA(Inst##PD, mb) \
  148. CASE_AVX512_FMA(Inst##PS, mb)
  149. #define CASE_FMA_SCALAR_REG(Inst) \
  150. CASE_AVX_INS_COMMON(Inst##SD, , r) \
  151. CASE_AVX_INS_COMMON(Inst##SS, , r) \
  152. CASE_AVX_INS_COMMON(Inst##SD, , r_Int) \
  153. CASE_AVX_INS_COMMON(Inst##SS, , r_Int) \
  154. CASE_AVX_INS_COMMON(Inst##SD, Z, r) \
  155. CASE_AVX_INS_COMMON(Inst##SS, Z, r) \
  156. CASE_AVX512_INS_COMMON(Inst##SD, Z, r_Int) \
  157. CASE_AVX512_INS_COMMON(Inst##SS, Z, r_Int)
  158. #define CASE_FMA_SCALAR_MEM(Inst) \
  159. CASE_AVX_INS_COMMON(Inst##SD, , m) \
  160. CASE_AVX_INS_COMMON(Inst##SS, , m) \
  161. CASE_AVX_INS_COMMON(Inst##SD, , m_Int) \
  162. CASE_AVX_INS_COMMON(Inst##SS, , m_Int) \
  163. CASE_AVX_INS_COMMON(Inst##SD, Z, m) \
  164. CASE_AVX_INS_COMMON(Inst##SS, Z, m) \
  165. CASE_AVX512_INS_COMMON(Inst##SD, Z, m_Int) \
  166. CASE_AVX512_INS_COMMON(Inst##SS, Z, m_Int)
  167. #define CASE_FMA4(Inst, suf) \
  168. CASE_AVX_INS_COMMON(Inst, 4, suf) \
  169. CASE_AVX_INS_COMMON(Inst, 4Y, suf)
  170. #define CASE_FMA4_PACKED_RR(Inst) \
  171. CASE_FMA4(Inst##PD, rr) \
  172. CASE_FMA4(Inst##PS, rr)
  173. #define CASE_FMA4_PACKED_RM(Inst) \
  174. CASE_FMA4(Inst##PD, rm) \
  175. CASE_FMA4(Inst##PS, rm)
  176. #define CASE_FMA4_PACKED_MR(Inst) \
  177. CASE_FMA4(Inst##PD, mr) \
  178. CASE_FMA4(Inst##PS, mr)
  179. #define CASE_FMA4_SCALAR_RR(Inst) \
  180. CASE_AVX_INS_COMMON(Inst##SD4, , rr) \
  181. CASE_AVX_INS_COMMON(Inst##SS4, , rr) \
  182. CASE_AVX_INS_COMMON(Inst##SD4, , rr_Int) \
  183. CASE_AVX_INS_COMMON(Inst##SS4, , rr_Int)
  184. #define CASE_FMA4_SCALAR_RM(Inst) \
  185. CASE_AVX_INS_COMMON(Inst##SD4, , rm) \
  186. CASE_AVX_INS_COMMON(Inst##SS4, , rm) \
  187. CASE_AVX_INS_COMMON(Inst##SD4, , rm_Int) \
  188. CASE_AVX_INS_COMMON(Inst##SS4, , rm_Int)
  189. #define CASE_FMA4_SCALAR_MR(Inst) \
  190. CASE_AVX_INS_COMMON(Inst##SD4, , mr) \
  191. CASE_AVX_INS_COMMON(Inst##SS4, , mr) \
  192. CASE_AVX_INS_COMMON(Inst##SD4, , mr_Int) \
  193. CASE_AVX_INS_COMMON(Inst##SS4, , mr_Int)
  194. static unsigned getVectorRegSize(unsigned RegNo) {
  195. if (X86::ZMM0 <= RegNo && RegNo <= X86::ZMM31)
  196. return 512;
  197. if (X86::YMM0 <= RegNo && RegNo <= X86::YMM31)
  198. return 256;
  199. if (X86::XMM0 <= RegNo && RegNo <= X86::XMM31)
  200. return 128;
  201. if (X86::MM0 <= RegNo && RegNo <= X86::MM7)
  202. return 64;
  203. llvm_unreachable("Unknown vector reg!");
  204. }
  205. static unsigned getRegOperandNumElts(const MCInst *MI, unsigned ScalarSize,
  206. unsigned OperandIndex) {
  207. unsigned OpReg = MI->getOperand(OperandIndex).getReg();
  208. return getVectorRegSize(OpReg) / ScalarSize;
  209. }
  210. static const char *getRegName(unsigned Reg) {
  211. return X86ATTInstPrinter::getRegisterName(Reg);
  212. }
  213. /// Wraps the destination register name with AVX512 mask/maskz filtering.
  214. static void printMasking(raw_ostream &OS, const MCInst *MI,
  215. const MCInstrInfo &MCII) {
  216. const MCInstrDesc &Desc = MCII.get(MI->getOpcode());
  217. uint64_t TSFlags = Desc.TSFlags;
  218. if (!(TSFlags & X86II::EVEX_K))
  219. return;
  220. bool MaskWithZero = (TSFlags & X86II::EVEX_Z);
  221. unsigned MaskOp = Desc.getNumDefs();
  222. if (Desc.getOperandConstraint(MaskOp, MCOI::TIED_TO) != -1)
  223. ++MaskOp;
  224. const char *MaskRegName = getRegName(MI->getOperand(MaskOp).getReg());
  225. // MASK: zmmX {%kY}
  226. OS << " {%" << MaskRegName << "}";
  227. // MASKZ: zmmX {%kY} {z}
  228. if (MaskWithZero)
  229. OS << " {z}";
  230. }
  231. static bool printFMAComments(const MCInst *MI, raw_ostream &OS,
  232. const MCInstrInfo &MCII) {
  233. const char *Mul1Name = nullptr, *Mul2Name = nullptr, *AccName = nullptr;
  234. unsigned NumOperands = MI->getNumOperands();
  235. bool RegForm = false;
  236. bool Negate = false;
  237. StringRef AccStr = "+";
  238. // The operands for FMA3 instructions without rounding fall into two forms:
  239. // dest, src1, src2, src3
  240. // dest, src1, mask, src2, src3
  241. // Where src3 is either a register or 5 memory address operands. So to find
  242. // dest and src1 we can index from the front. To find src2 and src3 we can
  243. // index from the end by taking into account memory vs register form when
  244. // finding src2.
  245. // The operands for FMA4 instructions:
  246. // dest, src1, src2, src3
  247. // Where src2 OR src3 are either a register or 5 memory address operands. So
  248. // to find dest and src1 we can index from the front, src2 (reg/mem) follows
  249. // and then src3 (reg) will be at the end.
  250. switch (MI->getOpcode()) {
  251. default:
  252. return false;
  253. CASE_FMA4_PACKED_RR(FMADD)
  254. CASE_FMA4_SCALAR_RR(FMADD)
  255. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  256. LLVM_FALLTHROUGH;
  257. CASE_FMA4_PACKED_RM(FMADD)
  258. CASE_FMA4_SCALAR_RM(FMADD)
  259. Mul2Name = getRegName(MI->getOperand(2).getReg());
  260. Mul1Name = getRegName(MI->getOperand(1).getReg());
  261. break;
  262. CASE_FMA4_PACKED_MR(FMADD)
  263. CASE_FMA4_SCALAR_MR(FMADD)
  264. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  265. Mul1Name = getRegName(MI->getOperand(1).getReg());
  266. break;
  267. CASE_FMA4_PACKED_RR(FMSUB)
  268. CASE_FMA4_SCALAR_RR(FMSUB)
  269. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  270. LLVM_FALLTHROUGH;
  271. CASE_FMA4_PACKED_RM(FMSUB)
  272. CASE_FMA4_SCALAR_RM(FMSUB)
  273. Mul2Name = getRegName(MI->getOperand(2).getReg());
  274. Mul1Name = getRegName(MI->getOperand(1).getReg());
  275. AccStr = "-";
  276. break;
  277. CASE_FMA4_PACKED_MR(FMSUB)
  278. CASE_FMA4_SCALAR_MR(FMSUB)
  279. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  280. Mul1Name = getRegName(MI->getOperand(1).getReg());
  281. AccStr = "-";
  282. break;
  283. CASE_FMA4_PACKED_RR(FNMADD)
  284. CASE_FMA4_SCALAR_RR(FNMADD)
  285. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  286. LLVM_FALLTHROUGH;
  287. CASE_FMA4_PACKED_RM(FNMADD)
  288. CASE_FMA4_SCALAR_RM(FNMADD)
  289. Mul2Name = getRegName(MI->getOperand(2).getReg());
  290. Mul1Name = getRegName(MI->getOperand(1).getReg());
  291. Negate = true;
  292. break;
  293. CASE_FMA4_PACKED_MR(FNMADD)
  294. CASE_FMA4_SCALAR_MR(FNMADD)
  295. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  296. Mul1Name = getRegName(MI->getOperand(1).getReg());
  297. Negate = true;
  298. break;
  299. CASE_FMA4_PACKED_RR(FNMSUB)
  300. CASE_FMA4_SCALAR_RR(FNMSUB)
  301. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  302. LLVM_FALLTHROUGH;
  303. CASE_FMA4_PACKED_RM(FNMSUB)
  304. CASE_FMA4_SCALAR_RM(FNMSUB)
  305. Mul2Name = getRegName(MI->getOperand(2).getReg());
  306. Mul1Name = getRegName(MI->getOperand(1).getReg());
  307. AccStr = "-";
  308. Negate = true;
  309. break;
  310. CASE_FMA4_PACKED_MR(FNMSUB)
  311. CASE_FMA4_SCALAR_MR(FNMSUB)
  312. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  313. Mul1Name = getRegName(MI->getOperand(1).getReg());
  314. AccStr = "-";
  315. Negate = true;
  316. break;
  317. CASE_FMA4_PACKED_RR(FMADDSUB)
  318. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  319. LLVM_FALLTHROUGH;
  320. CASE_FMA4_PACKED_RM(FMADDSUB)
  321. Mul2Name = getRegName(MI->getOperand(2).getReg());
  322. Mul1Name = getRegName(MI->getOperand(1).getReg());
  323. AccStr = "+/-";
  324. break;
  325. CASE_FMA4_PACKED_MR(FMADDSUB)
  326. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  327. Mul1Name = getRegName(MI->getOperand(1).getReg());
  328. AccStr = "+/-";
  329. break;
  330. CASE_FMA4_PACKED_RR(FMSUBADD)
  331. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  332. LLVM_FALLTHROUGH;
  333. CASE_FMA4_PACKED_RM(FMSUBADD)
  334. Mul2Name = getRegName(MI->getOperand(2).getReg());
  335. Mul1Name = getRegName(MI->getOperand(1).getReg());
  336. AccStr = "-/+";
  337. break;
  338. CASE_FMA4_PACKED_MR(FMSUBADD)
  339. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  340. Mul1Name = getRegName(MI->getOperand(1).getReg());
  341. AccStr = "-/+";
  342. break;
  343. CASE_FMA_PACKED_REG(FMADD132)
  344. CASE_FMA_SCALAR_REG(FMADD132)
  345. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  346. RegForm = true;
  347. LLVM_FALLTHROUGH;
  348. CASE_FMA_PACKED_MEM(FMADD132)
  349. CASE_FMA_SCALAR_MEM(FMADD132)
  350. AccName = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  351. Mul1Name = getRegName(MI->getOperand(1).getReg());
  352. break;
  353. CASE_FMA_PACKED_REG(FMADD213)
  354. CASE_FMA_SCALAR_REG(FMADD213)
  355. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  356. RegForm = true;
  357. LLVM_FALLTHROUGH;
  358. CASE_FMA_PACKED_MEM(FMADD213)
  359. CASE_FMA_SCALAR_MEM(FMADD213)
  360. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  361. Mul2Name = getRegName(MI->getOperand(1).getReg());
  362. break;
  363. CASE_FMA_PACKED_REG(FMADD231)
  364. CASE_FMA_SCALAR_REG(FMADD231)
  365. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  366. RegForm = true;
  367. LLVM_FALLTHROUGH;
  368. CASE_FMA_PACKED_MEM(FMADD231)
  369. CASE_FMA_SCALAR_MEM(FMADD231)
  370. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  371. AccName = getRegName(MI->getOperand(1).getReg());
  372. break;
  373. CASE_FMA_PACKED_REG(FMSUB132)
  374. CASE_FMA_SCALAR_REG(FMSUB132)
  375. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  376. RegForm = true;
  377. LLVM_FALLTHROUGH;
  378. CASE_FMA_PACKED_MEM(FMSUB132)
  379. CASE_FMA_SCALAR_MEM(FMSUB132)
  380. AccName = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  381. Mul1Name = getRegName(MI->getOperand(1).getReg());
  382. AccStr = "-";
  383. break;
  384. CASE_FMA_PACKED_REG(FMSUB213)
  385. CASE_FMA_SCALAR_REG(FMSUB213)
  386. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  387. RegForm = true;
  388. LLVM_FALLTHROUGH;
  389. CASE_FMA_PACKED_MEM(FMSUB213)
  390. CASE_FMA_SCALAR_MEM(FMSUB213)
  391. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  392. Mul2Name = getRegName(MI->getOperand(1).getReg());
  393. AccStr = "-";
  394. break;
  395. CASE_FMA_PACKED_REG(FMSUB231)
  396. CASE_FMA_SCALAR_REG(FMSUB231)
  397. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  398. RegForm = true;
  399. LLVM_FALLTHROUGH;
  400. CASE_FMA_PACKED_MEM(FMSUB231)
  401. CASE_FMA_SCALAR_MEM(FMSUB231)
  402. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  403. AccName = getRegName(MI->getOperand(1).getReg());
  404. AccStr = "-";
  405. break;
  406. CASE_FMA_PACKED_REG(FNMADD132)
  407. CASE_FMA_SCALAR_REG(FNMADD132)
  408. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  409. RegForm = true;
  410. LLVM_FALLTHROUGH;
  411. CASE_FMA_PACKED_MEM(FNMADD132)
  412. CASE_FMA_SCALAR_MEM(FNMADD132)
  413. AccName = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  414. Mul1Name = getRegName(MI->getOperand(1).getReg());
  415. Negate = true;
  416. break;
  417. CASE_FMA_PACKED_REG(FNMADD213)
  418. CASE_FMA_SCALAR_REG(FNMADD213)
  419. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  420. RegForm = true;
  421. LLVM_FALLTHROUGH;
  422. CASE_FMA_PACKED_MEM(FNMADD213)
  423. CASE_FMA_SCALAR_MEM(FNMADD213)
  424. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  425. Mul2Name = getRegName(MI->getOperand(1).getReg());
  426. Negate = true;
  427. break;
  428. CASE_FMA_PACKED_REG(FNMADD231)
  429. CASE_FMA_SCALAR_REG(FNMADD231)
  430. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  431. RegForm = true;
  432. LLVM_FALLTHROUGH;
  433. CASE_FMA_PACKED_MEM(FNMADD231)
  434. CASE_FMA_SCALAR_MEM(FNMADD231)
  435. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  436. AccName = getRegName(MI->getOperand(1).getReg());
  437. Negate = true;
  438. break;
  439. CASE_FMA_PACKED_REG(FNMSUB132)
  440. CASE_FMA_SCALAR_REG(FNMSUB132)
  441. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  442. RegForm = true;
  443. LLVM_FALLTHROUGH;
  444. CASE_FMA_PACKED_MEM(FNMSUB132)
  445. CASE_FMA_SCALAR_MEM(FNMSUB132)
  446. AccName = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  447. Mul1Name = getRegName(MI->getOperand(1).getReg());
  448. AccStr = "-";
  449. Negate = true;
  450. break;
  451. CASE_FMA_PACKED_REG(FNMSUB213)
  452. CASE_FMA_SCALAR_REG(FNMSUB213)
  453. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  454. RegForm = true;
  455. LLVM_FALLTHROUGH;
  456. CASE_FMA_PACKED_MEM(FNMSUB213)
  457. CASE_FMA_SCALAR_MEM(FNMSUB213)
  458. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  459. Mul2Name = getRegName(MI->getOperand(1).getReg());
  460. AccStr = "-";
  461. Negate = true;
  462. break;
  463. CASE_FMA_PACKED_REG(FNMSUB231)
  464. CASE_FMA_SCALAR_REG(FNMSUB231)
  465. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  466. RegForm = true;
  467. LLVM_FALLTHROUGH;
  468. CASE_FMA_PACKED_MEM(FNMSUB231)
  469. CASE_FMA_SCALAR_MEM(FNMSUB231)
  470. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  471. AccName = getRegName(MI->getOperand(1).getReg());
  472. AccStr = "-";
  473. Negate = true;
  474. break;
  475. CASE_FMA_PACKED_REG(FMADDSUB132)
  476. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  477. RegForm = true;
  478. LLVM_FALLTHROUGH;
  479. CASE_FMA_PACKED_MEM(FMADDSUB132)
  480. AccName = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  481. Mul1Name = getRegName(MI->getOperand(1).getReg());
  482. AccStr = "+/-";
  483. break;
  484. CASE_FMA_PACKED_REG(FMADDSUB213)
  485. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  486. RegForm = true;
  487. LLVM_FALLTHROUGH;
  488. CASE_FMA_PACKED_MEM(FMADDSUB213)
  489. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  490. Mul2Name = getRegName(MI->getOperand(1).getReg());
  491. AccStr = "+/-";
  492. break;
  493. CASE_FMA_PACKED_REG(FMADDSUB231)
  494. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  495. RegForm = true;
  496. LLVM_FALLTHROUGH;
  497. CASE_FMA_PACKED_MEM(FMADDSUB231)
  498. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  499. AccName = getRegName(MI->getOperand(1).getReg());
  500. AccStr = "+/-";
  501. break;
  502. CASE_FMA_PACKED_REG(FMSUBADD132)
  503. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  504. RegForm = true;
  505. LLVM_FALLTHROUGH;
  506. CASE_FMA_PACKED_MEM(FMSUBADD132)
  507. AccName = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  508. Mul1Name = getRegName(MI->getOperand(1).getReg());
  509. AccStr = "-/+";
  510. break;
  511. CASE_FMA_PACKED_REG(FMSUBADD213)
  512. AccName = getRegName(MI->getOperand(NumOperands - 1).getReg());
  513. RegForm = true;
  514. LLVM_FALLTHROUGH;
  515. CASE_FMA_PACKED_MEM(FMSUBADD213)
  516. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  517. Mul2Name = getRegName(MI->getOperand(1).getReg());
  518. AccStr = "-/+";
  519. break;
  520. CASE_FMA_PACKED_REG(FMSUBADD231)
  521. Mul2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  522. RegForm = true;
  523. LLVM_FALLTHROUGH;
  524. CASE_FMA_PACKED_MEM(FMSUBADD231)
  525. Mul1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  526. AccName = getRegName(MI->getOperand(1).getReg());
  527. AccStr = "-/+";
  528. break;
  529. }
  530. const char *DestName = getRegName(MI->getOperand(0).getReg());
  531. if (!Mul1Name) Mul1Name = "mem";
  532. if (!Mul2Name) Mul2Name = "mem";
  533. if (!AccName) AccName = "mem";
  534. OS << DestName;
  535. printMasking(OS, MI, MCII);
  536. OS << " = ";
  537. if (Negate)
  538. OS << '-';
  539. OS << '(' << Mul1Name << " * " << Mul2Name << ") " << AccStr << ' '
  540. << AccName;
  541. return true;
  542. }
  543. //===----------------------------------------------------------------------===//
  544. // Top Level Entrypoint
  545. //===----------------------------------------------------------------------===//
  546. /// EmitAnyX86InstComments - This function decodes x86 instructions and prints
  547. /// newline terminated strings to the specified string if desired. This
  548. /// information is shown in disassembly dumps when verbose assembly is enabled.
  549. bool llvm::EmitAnyX86InstComments(const MCInst *MI, raw_ostream &OS,
  550. const MCInstrInfo &MCII) {
  551. // If this is a shuffle operation, the switch should fill in this state.
  552. SmallVector<int, 8> ShuffleMask;
  553. const char *DestName = nullptr, *Src1Name = nullptr, *Src2Name = nullptr;
  554. unsigned NumOperands = MI->getNumOperands();
  555. bool RegForm = false;
  556. if (printFMAComments(MI, OS, MCII))
  557. return true;
  558. switch (MI->getOpcode()) {
  559. default:
  560. // Not an instruction for which we can decode comments.
  561. return false;
  562. case X86::BLENDPDrri:
  563. case X86::VBLENDPDrri:
  564. case X86::VBLENDPDYrri:
  565. Src2Name = getRegName(MI->getOperand(2).getReg());
  566. LLVM_FALLTHROUGH;
  567. case X86::BLENDPDrmi:
  568. case X86::VBLENDPDrmi:
  569. case X86::VBLENDPDYrmi:
  570. if (MI->getOperand(NumOperands - 1).isImm())
  571. DecodeBLENDMask(getRegOperandNumElts(MI, 64, 0),
  572. MI->getOperand(NumOperands - 1).getImm(),
  573. ShuffleMask);
  574. Src1Name = getRegName(MI->getOperand(1).getReg());
  575. DestName = getRegName(MI->getOperand(0).getReg());
  576. break;
  577. case X86::BLENDPSrri:
  578. case X86::VBLENDPSrri:
  579. case X86::VBLENDPSYrri:
  580. Src2Name = getRegName(MI->getOperand(2).getReg());
  581. LLVM_FALLTHROUGH;
  582. case X86::BLENDPSrmi:
  583. case X86::VBLENDPSrmi:
  584. case X86::VBLENDPSYrmi:
  585. if (MI->getOperand(NumOperands - 1).isImm())
  586. DecodeBLENDMask(getRegOperandNumElts(MI, 32, 0),
  587. MI->getOperand(NumOperands - 1).getImm(),
  588. ShuffleMask);
  589. Src1Name = getRegName(MI->getOperand(1).getReg());
  590. DestName = getRegName(MI->getOperand(0).getReg());
  591. break;
  592. case X86::PBLENDWrri:
  593. case X86::VPBLENDWrri:
  594. case X86::VPBLENDWYrri:
  595. Src2Name = getRegName(MI->getOperand(2).getReg());
  596. LLVM_FALLTHROUGH;
  597. case X86::PBLENDWrmi:
  598. case X86::VPBLENDWrmi:
  599. case X86::VPBLENDWYrmi:
  600. if (MI->getOperand(NumOperands - 1).isImm())
  601. DecodeBLENDMask(getRegOperandNumElts(MI, 16, 0),
  602. MI->getOperand(NumOperands - 1).getImm(),
  603. ShuffleMask);
  604. Src1Name = getRegName(MI->getOperand(1).getReg());
  605. DestName = getRegName(MI->getOperand(0).getReg());
  606. break;
  607. case X86::VPBLENDDrri:
  608. case X86::VPBLENDDYrri:
  609. Src2Name = getRegName(MI->getOperand(2).getReg());
  610. LLVM_FALLTHROUGH;
  611. case X86::VPBLENDDrmi:
  612. case X86::VPBLENDDYrmi:
  613. if (MI->getOperand(NumOperands - 1).isImm())
  614. DecodeBLENDMask(getRegOperandNumElts(MI, 32, 0),
  615. MI->getOperand(NumOperands - 1).getImm(),
  616. ShuffleMask);
  617. Src1Name = getRegName(MI->getOperand(1).getReg());
  618. DestName = getRegName(MI->getOperand(0).getReg());
  619. break;
  620. case X86::INSERTPSrr:
  621. case X86::VINSERTPSrr:
  622. case X86::VINSERTPSZrr:
  623. Src2Name = getRegName(MI->getOperand(2).getReg());
  624. LLVM_FALLTHROUGH;
  625. case X86::INSERTPSrm:
  626. case X86::VINSERTPSrm:
  627. case X86::VINSERTPSZrm:
  628. DestName = getRegName(MI->getOperand(0).getReg());
  629. Src1Name = getRegName(MI->getOperand(1).getReg());
  630. if (MI->getOperand(NumOperands - 1).isImm())
  631. DecodeINSERTPSMask(MI->getOperand(NumOperands - 1).getImm(),
  632. ShuffleMask);
  633. break;
  634. case X86::MOVLHPSrr:
  635. case X86::VMOVLHPSrr:
  636. case X86::VMOVLHPSZrr:
  637. Src2Name = getRegName(MI->getOperand(2).getReg());
  638. Src1Name = getRegName(MI->getOperand(1).getReg());
  639. DestName = getRegName(MI->getOperand(0).getReg());
  640. DecodeMOVLHPSMask(2, ShuffleMask);
  641. break;
  642. case X86::MOVHLPSrr:
  643. case X86::VMOVHLPSrr:
  644. case X86::VMOVHLPSZrr:
  645. Src2Name = getRegName(MI->getOperand(2).getReg());
  646. Src1Name = getRegName(MI->getOperand(1).getReg());
  647. DestName = getRegName(MI->getOperand(0).getReg());
  648. DecodeMOVHLPSMask(2, ShuffleMask);
  649. break;
  650. case X86::MOVHPDrm:
  651. case X86::VMOVHPDrm:
  652. case X86::VMOVHPDZ128rm:
  653. Src1Name = getRegName(MI->getOperand(1).getReg());
  654. DestName = getRegName(MI->getOperand(0).getReg());
  655. DecodeInsertElementMask(2, 1, 1, ShuffleMask);
  656. break;
  657. case X86::MOVHPSrm:
  658. case X86::VMOVHPSrm:
  659. case X86::VMOVHPSZ128rm:
  660. Src1Name = getRegName(MI->getOperand(1).getReg());
  661. DestName = getRegName(MI->getOperand(0).getReg());
  662. DecodeInsertElementMask(4, 2, 2, ShuffleMask);
  663. break;
  664. case X86::MOVLPDrm:
  665. case X86::VMOVLPDrm:
  666. case X86::VMOVLPDZ128rm:
  667. Src1Name = getRegName(MI->getOperand(1).getReg());
  668. DestName = getRegName(MI->getOperand(0).getReg());
  669. DecodeInsertElementMask(2, 0, 1, ShuffleMask);
  670. break;
  671. case X86::MOVLPSrm:
  672. case X86::VMOVLPSrm:
  673. case X86::VMOVLPSZ128rm:
  674. Src1Name = getRegName(MI->getOperand(1).getReg());
  675. DestName = getRegName(MI->getOperand(0).getReg());
  676. DecodeInsertElementMask(4, 0, 2, ShuffleMask);
  677. break;
  678. CASE_MOVDUP(MOVSLDUP, r)
  679. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  680. LLVM_FALLTHROUGH;
  681. CASE_MOVDUP(MOVSLDUP, m)
  682. DestName = getRegName(MI->getOperand(0).getReg());
  683. DecodeMOVSLDUPMask(getRegOperandNumElts(MI, 32, 0), ShuffleMask);
  684. break;
  685. CASE_MOVDUP(MOVSHDUP, r)
  686. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  687. LLVM_FALLTHROUGH;
  688. CASE_MOVDUP(MOVSHDUP, m)
  689. DestName = getRegName(MI->getOperand(0).getReg());
  690. DecodeMOVSHDUPMask(getRegOperandNumElts(MI, 32, 0), ShuffleMask);
  691. break;
  692. CASE_MOVDUP(MOVDDUP, r)
  693. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  694. LLVM_FALLTHROUGH;
  695. CASE_MOVDUP(MOVDDUP, m)
  696. DestName = getRegName(MI->getOperand(0).getReg());
  697. DecodeMOVDDUPMask(getRegOperandNumElts(MI, 64, 0), ShuffleMask);
  698. break;
  699. case X86::PSLLDQri:
  700. case X86::VPSLLDQri:
  701. case X86::VPSLLDQYri:
  702. case X86::VPSLLDQZ128ri:
  703. case X86::VPSLLDQZ256ri:
  704. case X86::VPSLLDQZri:
  705. Src1Name = getRegName(MI->getOperand(1).getReg());
  706. LLVM_FALLTHROUGH;
  707. case X86::VPSLLDQZ128mi:
  708. case X86::VPSLLDQZ256mi:
  709. case X86::VPSLLDQZmi:
  710. DestName = getRegName(MI->getOperand(0).getReg());
  711. if (MI->getOperand(NumOperands - 1).isImm())
  712. DecodePSLLDQMask(getRegOperandNumElts(MI, 8, 0),
  713. MI->getOperand(NumOperands - 1).getImm(),
  714. ShuffleMask);
  715. break;
  716. case X86::PSRLDQri:
  717. case X86::VPSRLDQri:
  718. case X86::VPSRLDQYri:
  719. case X86::VPSRLDQZ128ri:
  720. case X86::VPSRLDQZ256ri:
  721. case X86::VPSRLDQZri:
  722. Src1Name = getRegName(MI->getOperand(1).getReg());
  723. LLVM_FALLTHROUGH;
  724. case X86::VPSRLDQZ128mi:
  725. case X86::VPSRLDQZ256mi:
  726. case X86::VPSRLDQZmi:
  727. DestName = getRegName(MI->getOperand(0).getReg());
  728. if (MI->getOperand(NumOperands - 1).isImm())
  729. DecodePSRLDQMask(getRegOperandNumElts(MI, 8, 0),
  730. MI->getOperand(NumOperands - 1).getImm(),
  731. ShuffleMask);
  732. break;
  733. CASE_SHUF(PALIGNR, rri)
  734. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  735. RegForm = true;
  736. LLVM_FALLTHROUGH;
  737. CASE_SHUF(PALIGNR, rmi)
  738. Src2Name = getRegName(MI->getOperand(NumOperands-(RegForm?3:7)).getReg());
  739. DestName = getRegName(MI->getOperand(0).getReg());
  740. if (MI->getOperand(NumOperands - 1).isImm())
  741. DecodePALIGNRMask(getRegOperandNumElts(MI, 8, 0),
  742. MI->getOperand(NumOperands - 1).getImm(),
  743. ShuffleMask);
  744. break;
  745. CASE_AVX512_INS_COMMON(ALIGNQ, Z, rri)
  746. CASE_AVX512_INS_COMMON(ALIGNQ, Z256, rri)
  747. CASE_AVX512_INS_COMMON(ALIGNQ, Z128, rri)
  748. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  749. RegForm = true;
  750. LLVM_FALLTHROUGH;
  751. CASE_AVX512_INS_COMMON(ALIGNQ, Z, rmi)
  752. CASE_AVX512_INS_COMMON(ALIGNQ, Z256, rmi)
  753. CASE_AVX512_INS_COMMON(ALIGNQ, Z128, rmi)
  754. Src2Name = getRegName(MI->getOperand(NumOperands-(RegForm?3:7)).getReg());
  755. DestName = getRegName(MI->getOperand(0).getReg());
  756. if (MI->getOperand(NumOperands - 1).isImm())
  757. DecodeVALIGNMask(getRegOperandNumElts(MI, 64, 0),
  758. MI->getOperand(NumOperands - 1).getImm(),
  759. ShuffleMask);
  760. break;
  761. CASE_AVX512_INS_COMMON(ALIGND, Z, rri)
  762. CASE_AVX512_INS_COMMON(ALIGND, Z256, rri)
  763. CASE_AVX512_INS_COMMON(ALIGND, Z128, rri)
  764. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  765. RegForm = true;
  766. LLVM_FALLTHROUGH;
  767. CASE_AVX512_INS_COMMON(ALIGND, Z, rmi)
  768. CASE_AVX512_INS_COMMON(ALIGND, Z256, rmi)
  769. CASE_AVX512_INS_COMMON(ALIGND, Z128, rmi)
  770. Src2Name = getRegName(MI->getOperand(NumOperands-(RegForm?3:7)).getReg());
  771. DestName = getRegName(MI->getOperand(0).getReg());
  772. if (MI->getOperand(NumOperands - 1).isImm())
  773. DecodeVALIGNMask(getRegOperandNumElts(MI, 32, 0),
  774. MI->getOperand(NumOperands - 1).getImm(),
  775. ShuffleMask);
  776. break;
  777. CASE_SHUF(PSHUFD, ri)
  778. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  779. LLVM_FALLTHROUGH;
  780. CASE_SHUF(PSHUFD, mi)
  781. DestName = getRegName(MI->getOperand(0).getReg());
  782. if (MI->getOperand(NumOperands - 1).isImm())
  783. DecodePSHUFMask(getRegOperandNumElts(MI, 32, 0), 32,
  784. MI->getOperand(NumOperands - 1).getImm(),
  785. ShuffleMask);
  786. break;
  787. CASE_SHUF(PSHUFHW, ri)
  788. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  789. LLVM_FALLTHROUGH;
  790. CASE_SHUF(PSHUFHW, mi)
  791. DestName = getRegName(MI->getOperand(0).getReg());
  792. if (MI->getOperand(NumOperands - 1).isImm())
  793. DecodePSHUFHWMask(getRegOperandNumElts(MI, 16, 0),
  794. MI->getOperand(NumOperands - 1).getImm(),
  795. ShuffleMask);
  796. break;
  797. CASE_SHUF(PSHUFLW, ri)
  798. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  799. LLVM_FALLTHROUGH;
  800. CASE_SHUF(PSHUFLW, mi)
  801. DestName = getRegName(MI->getOperand(0).getReg());
  802. if (MI->getOperand(NumOperands - 1).isImm())
  803. DecodePSHUFLWMask(getRegOperandNumElts(MI, 16, 0),
  804. MI->getOperand(NumOperands - 1).getImm(),
  805. ShuffleMask);
  806. break;
  807. case X86::MMX_PSHUFWri:
  808. Src1Name = getRegName(MI->getOperand(1).getReg());
  809. LLVM_FALLTHROUGH;
  810. case X86::MMX_PSHUFWmi:
  811. DestName = getRegName(MI->getOperand(0).getReg());
  812. if (MI->getOperand(NumOperands - 1).isImm())
  813. DecodePSHUFMask(4, 16, MI->getOperand(NumOperands - 1).getImm(),
  814. ShuffleMask);
  815. break;
  816. case X86::PSWAPDrr:
  817. Src1Name = getRegName(MI->getOperand(1).getReg());
  818. LLVM_FALLTHROUGH;
  819. case X86::PSWAPDrm:
  820. DestName = getRegName(MI->getOperand(0).getReg());
  821. DecodePSWAPMask(2, ShuffleMask);
  822. break;
  823. CASE_UNPCK(PUNPCKHBW, r)
  824. case X86::MMX_PUNPCKHBWrr:
  825. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  826. RegForm = true;
  827. LLVM_FALLTHROUGH;
  828. CASE_UNPCK(PUNPCKHBW, m)
  829. case X86::MMX_PUNPCKHBWrm:
  830. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  831. DestName = getRegName(MI->getOperand(0).getReg());
  832. DecodeUNPCKHMask(getRegOperandNumElts(MI, 8, 0), 8, ShuffleMask);
  833. break;
  834. CASE_UNPCK(PUNPCKHWD, r)
  835. case X86::MMX_PUNPCKHWDrr:
  836. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  837. RegForm = true;
  838. LLVM_FALLTHROUGH;
  839. CASE_UNPCK(PUNPCKHWD, m)
  840. case X86::MMX_PUNPCKHWDrm:
  841. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  842. DestName = getRegName(MI->getOperand(0).getReg());
  843. DecodeUNPCKHMask(getRegOperandNumElts(MI, 16, 0), 16, ShuffleMask);
  844. break;
  845. CASE_UNPCK(PUNPCKHDQ, r)
  846. case X86::MMX_PUNPCKHDQrr:
  847. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  848. RegForm = true;
  849. LLVM_FALLTHROUGH;
  850. CASE_UNPCK(PUNPCKHDQ, m)
  851. case X86::MMX_PUNPCKHDQrm:
  852. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  853. DestName = getRegName(MI->getOperand(0).getReg());
  854. DecodeUNPCKHMask(getRegOperandNumElts(MI, 32, 0), 32, ShuffleMask);
  855. break;
  856. CASE_UNPCK(PUNPCKHQDQ, r)
  857. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  858. RegForm = true;
  859. LLVM_FALLTHROUGH;
  860. CASE_UNPCK(PUNPCKHQDQ, m)
  861. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  862. DestName = getRegName(MI->getOperand(0).getReg());
  863. DecodeUNPCKHMask(getRegOperandNumElts(MI, 64, 0), 64, ShuffleMask);
  864. break;
  865. CASE_UNPCK(PUNPCKLBW, r)
  866. case X86::MMX_PUNPCKLBWrr:
  867. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  868. RegForm = true;
  869. LLVM_FALLTHROUGH;
  870. CASE_UNPCK(PUNPCKLBW, m)
  871. case X86::MMX_PUNPCKLBWrm:
  872. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  873. DestName = getRegName(MI->getOperand(0).getReg());
  874. DecodeUNPCKLMask(getRegOperandNumElts(MI, 8, 0), 8, ShuffleMask);
  875. break;
  876. CASE_UNPCK(PUNPCKLWD, r)
  877. case X86::MMX_PUNPCKLWDrr:
  878. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  879. RegForm = true;
  880. LLVM_FALLTHROUGH;
  881. CASE_UNPCK(PUNPCKLWD, m)
  882. case X86::MMX_PUNPCKLWDrm:
  883. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  884. DestName = getRegName(MI->getOperand(0).getReg());
  885. DecodeUNPCKLMask(getRegOperandNumElts(MI, 16, 0), 16, ShuffleMask);
  886. break;
  887. CASE_UNPCK(PUNPCKLDQ, r)
  888. case X86::MMX_PUNPCKLDQrr:
  889. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  890. RegForm = true;
  891. LLVM_FALLTHROUGH;
  892. CASE_UNPCK(PUNPCKLDQ, m)
  893. case X86::MMX_PUNPCKLDQrm:
  894. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  895. DestName = getRegName(MI->getOperand(0).getReg());
  896. DecodeUNPCKLMask(getRegOperandNumElts(MI, 32, 0), 32, ShuffleMask);
  897. break;
  898. CASE_UNPCK(PUNPCKLQDQ, r)
  899. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  900. RegForm = true;
  901. LLVM_FALLTHROUGH;
  902. CASE_UNPCK(PUNPCKLQDQ, m)
  903. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  904. DestName = getRegName(MI->getOperand(0).getReg());
  905. DecodeUNPCKLMask(getRegOperandNumElts(MI, 64, 0), 64, ShuffleMask);
  906. break;
  907. CASE_SHUF(SHUFPD, rri)
  908. Src2Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  909. RegForm = true;
  910. LLVM_FALLTHROUGH;
  911. CASE_SHUF(SHUFPD, rmi)
  912. if (MI->getOperand(NumOperands - 1).isImm())
  913. DecodeSHUFPMask(getRegOperandNumElts(MI, 64, 0), 64,
  914. MI->getOperand(NumOperands - 1).getImm(), ShuffleMask);
  915. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?3:7)).getReg());
  916. DestName = getRegName(MI->getOperand(0).getReg());
  917. break;
  918. CASE_SHUF(SHUFPS, rri)
  919. Src2Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  920. RegForm = true;
  921. LLVM_FALLTHROUGH;
  922. CASE_SHUF(SHUFPS, rmi)
  923. if (MI->getOperand(NumOperands - 1).isImm())
  924. DecodeSHUFPMask(getRegOperandNumElts(MI, 32, 0), 32,
  925. MI->getOperand(NumOperands - 1).getImm(),
  926. ShuffleMask);
  927. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?3:7)).getReg());
  928. DestName = getRegName(MI->getOperand(0).getReg());
  929. break;
  930. CASE_VSHUF(64X2, r)
  931. Src2Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  932. RegForm = true;
  933. LLVM_FALLTHROUGH;
  934. CASE_VSHUF(64X2, m)
  935. decodeVSHUF64x2FamilyMask(getRegOperandNumElts(MI, 64, 0), 64,
  936. MI->getOperand(NumOperands - 1).getImm(),
  937. ShuffleMask);
  938. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?3:7)).getReg());
  939. DestName = getRegName(MI->getOperand(0).getReg());
  940. break;
  941. CASE_VSHUF(32X4, r)
  942. Src2Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  943. RegForm = true;
  944. LLVM_FALLTHROUGH;
  945. CASE_VSHUF(32X4, m)
  946. decodeVSHUF64x2FamilyMask(getRegOperandNumElts(MI, 32, 0), 32,
  947. MI->getOperand(NumOperands - 1).getImm(),
  948. ShuffleMask);
  949. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?3:7)).getReg());
  950. DestName = getRegName(MI->getOperand(0).getReg());
  951. break;
  952. CASE_UNPCK(UNPCKLPD, r)
  953. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  954. RegForm = true;
  955. LLVM_FALLTHROUGH;
  956. CASE_UNPCK(UNPCKLPD, m)
  957. DecodeUNPCKLMask(getRegOperandNumElts(MI, 64, 0), 64, ShuffleMask);
  958. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  959. DestName = getRegName(MI->getOperand(0).getReg());
  960. break;
  961. CASE_UNPCK(UNPCKLPS, r)
  962. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  963. RegForm = true;
  964. LLVM_FALLTHROUGH;
  965. CASE_UNPCK(UNPCKLPS, m)
  966. DecodeUNPCKLMask(getRegOperandNumElts(MI, 32, 0), 32, ShuffleMask);
  967. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  968. DestName = getRegName(MI->getOperand(0).getReg());
  969. break;
  970. CASE_UNPCK(UNPCKHPD, r)
  971. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  972. RegForm = true;
  973. LLVM_FALLTHROUGH;
  974. CASE_UNPCK(UNPCKHPD, m)
  975. DecodeUNPCKHMask(getRegOperandNumElts(MI, 64, 0), 64, ShuffleMask);
  976. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  977. DestName = getRegName(MI->getOperand(0).getReg());
  978. break;
  979. CASE_UNPCK(UNPCKHPS, r)
  980. Src2Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  981. RegForm = true;
  982. LLVM_FALLTHROUGH;
  983. CASE_UNPCK(UNPCKHPS, m)
  984. DecodeUNPCKHMask(getRegOperandNumElts(MI, 32, 0), 32, ShuffleMask);
  985. Src1Name = getRegName(MI->getOperand(NumOperands-(RegForm?2:6)).getReg());
  986. DestName = getRegName(MI->getOperand(0).getReg());
  987. break;
  988. CASE_VPERMILPI(PERMILPS, r)
  989. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  990. LLVM_FALLTHROUGH;
  991. CASE_VPERMILPI(PERMILPS, m)
  992. if (MI->getOperand(NumOperands - 1).isImm())
  993. DecodePSHUFMask(getRegOperandNumElts(MI, 32, 0), 32,
  994. MI->getOperand(NumOperands - 1).getImm(),
  995. ShuffleMask);
  996. DestName = getRegName(MI->getOperand(0).getReg());
  997. break;
  998. CASE_VPERMILPI(PERMILPD, r)
  999. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  1000. LLVM_FALLTHROUGH;
  1001. CASE_VPERMILPI(PERMILPD, m)
  1002. if (MI->getOperand(NumOperands - 1).isImm())
  1003. DecodePSHUFMask(getRegOperandNumElts(MI, 64, 0), 64,
  1004. MI->getOperand(NumOperands - 1).getImm(),
  1005. ShuffleMask);
  1006. DestName = getRegName(MI->getOperand(0).getReg());
  1007. break;
  1008. case X86::VPERM2F128rr:
  1009. case X86::VPERM2I128rr:
  1010. Src2Name = getRegName(MI->getOperand(2).getReg());
  1011. LLVM_FALLTHROUGH;
  1012. case X86::VPERM2F128rm:
  1013. case X86::VPERM2I128rm:
  1014. // For instruction comments purpose, assume the 256-bit vector is v4i64.
  1015. if (MI->getOperand(NumOperands - 1).isImm())
  1016. DecodeVPERM2X128Mask(4, MI->getOperand(NumOperands - 1).getImm(),
  1017. ShuffleMask);
  1018. Src1Name = getRegName(MI->getOperand(1).getReg());
  1019. DestName = getRegName(MI->getOperand(0).getReg());
  1020. break;
  1021. CASE_VPERM(PERMPD, r)
  1022. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  1023. LLVM_FALLTHROUGH;
  1024. CASE_VPERM(PERMPD, m)
  1025. if (MI->getOperand(NumOperands - 1).isImm())
  1026. DecodeVPERMMask(getRegOperandNumElts(MI, 64, 0),
  1027. MI->getOperand(NumOperands - 1).getImm(),
  1028. ShuffleMask);
  1029. DestName = getRegName(MI->getOperand(0).getReg());
  1030. break;
  1031. CASE_VPERM(PERMQ, r)
  1032. Src1Name = getRegName(MI->getOperand(NumOperands - 2).getReg());
  1033. LLVM_FALLTHROUGH;
  1034. CASE_VPERM(PERMQ, m)
  1035. if (MI->getOperand(NumOperands - 1).isImm())
  1036. DecodeVPERMMask(getRegOperandNumElts(MI, 64, 0),
  1037. MI->getOperand(NumOperands - 1).getImm(),
  1038. ShuffleMask);
  1039. DestName = getRegName(MI->getOperand(0).getReg());
  1040. break;
  1041. case X86::MOVSDrr:
  1042. case X86::VMOVSDrr:
  1043. case X86::VMOVSDZrr:
  1044. Src2Name = getRegName(MI->getOperand(2).getReg());
  1045. Src1Name = getRegName(MI->getOperand(1).getReg());
  1046. LLVM_FALLTHROUGH;
  1047. case X86::MOVSDrm_alt:
  1048. case X86::MOVSDrm:
  1049. case X86::VMOVSDrm_alt:
  1050. case X86::VMOVSDrm:
  1051. case X86::VMOVSDZrm:
  1052. case X86::VMOVSDZrm_alt:
  1053. DecodeScalarMoveMask(2, nullptr == Src2Name, ShuffleMask);
  1054. DestName = getRegName(MI->getOperand(0).getReg());
  1055. break;
  1056. case X86::MOVSSrr:
  1057. case X86::VMOVSSrr:
  1058. case X86::VMOVSSZrr:
  1059. Src2Name = getRegName(MI->getOperand(2).getReg());
  1060. Src1Name = getRegName(MI->getOperand(1).getReg());
  1061. LLVM_FALLTHROUGH;
  1062. case X86::MOVSSrm:
  1063. case X86::MOVSSrm_alt:
  1064. case X86::VMOVSSrm:
  1065. case X86::VMOVSSrm_alt:
  1066. case X86::VMOVSSZrm:
  1067. case X86::VMOVSSZrm_alt:
  1068. DecodeScalarMoveMask(4, nullptr == Src2Name, ShuffleMask);
  1069. DestName = getRegName(MI->getOperand(0).getReg());
  1070. break;
  1071. case X86::MOVPQI2QIrr:
  1072. case X86::MOVZPQILo2PQIrr:
  1073. case X86::VMOVPQI2QIrr:
  1074. case X86::VMOVPQI2QIZrr:
  1075. case X86::VMOVZPQILo2PQIrr:
  1076. case X86::VMOVZPQILo2PQIZrr:
  1077. Src1Name = getRegName(MI->getOperand(1).getReg());
  1078. LLVM_FALLTHROUGH;
  1079. case X86::MOVQI2PQIrm:
  1080. case X86::VMOVQI2PQIrm:
  1081. case X86::VMOVQI2PQIZrm:
  1082. DecodeZeroMoveLowMask(2, ShuffleMask);
  1083. DestName = getRegName(MI->getOperand(0).getReg());
  1084. break;
  1085. case X86::MOVDI2PDIrm:
  1086. case X86::VMOVDI2PDIrm:
  1087. case X86::VMOVDI2PDIZrm:
  1088. DecodeZeroMoveLowMask(4, ShuffleMask);
  1089. DestName = getRegName(MI->getOperand(0).getReg());
  1090. break;
  1091. case X86::EXTRQI:
  1092. if (MI->getOperand(2).isImm() &&
  1093. MI->getOperand(3).isImm())
  1094. DecodeEXTRQIMask(16, 8, MI->getOperand(2).getImm(),
  1095. MI->getOperand(3).getImm(), ShuffleMask);
  1096. DestName = getRegName(MI->getOperand(0).getReg());
  1097. Src1Name = getRegName(MI->getOperand(1).getReg());
  1098. break;
  1099. case X86::INSERTQI:
  1100. if (MI->getOperand(3).isImm() &&
  1101. MI->getOperand(4).isImm())
  1102. DecodeINSERTQIMask(16, 8, MI->getOperand(3).getImm(),
  1103. MI->getOperand(4).getImm(), ShuffleMask);
  1104. DestName = getRegName(MI->getOperand(0).getReg());
  1105. Src1Name = getRegName(MI->getOperand(1).getReg());
  1106. Src2Name = getRegName(MI->getOperand(2).getReg());
  1107. break;
  1108. case X86::VBROADCASTF128:
  1109. case X86::VBROADCASTI128:
  1110. CASE_AVX512_INS_COMMON(BROADCASTF64X2, Z128, rm)
  1111. CASE_AVX512_INS_COMMON(BROADCASTI64X2, Z128, rm)
  1112. DecodeSubVectorBroadcast(4, 2, ShuffleMask);
  1113. DestName = getRegName(MI->getOperand(0).getReg());
  1114. break;
  1115. CASE_AVX512_INS_COMMON(BROADCASTF64X2, , rm)
  1116. CASE_AVX512_INS_COMMON(BROADCASTI64X2, , rm)
  1117. DecodeSubVectorBroadcast(8, 2, ShuffleMask);
  1118. DestName = getRegName(MI->getOperand(0).getReg());
  1119. break;
  1120. CASE_AVX512_INS_COMMON(BROADCASTF64X4, , rm)
  1121. CASE_AVX512_INS_COMMON(BROADCASTI64X4, , rm)
  1122. DecodeSubVectorBroadcast(8, 4, ShuffleMask);
  1123. DestName = getRegName(MI->getOperand(0).getReg());
  1124. break;
  1125. CASE_AVX512_INS_COMMON(BROADCASTF32X4, Z256, rm)
  1126. CASE_AVX512_INS_COMMON(BROADCASTI32X4, Z256, rm)
  1127. DecodeSubVectorBroadcast(8, 4, ShuffleMask);
  1128. DestName = getRegName(MI->getOperand(0).getReg());
  1129. break;
  1130. CASE_AVX512_INS_COMMON(BROADCASTF32X4, , rm)
  1131. CASE_AVX512_INS_COMMON(BROADCASTI32X4, , rm)
  1132. DecodeSubVectorBroadcast(16, 4, ShuffleMask);
  1133. DestName = getRegName(MI->getOperand(0).getReg());
  1134. break;
  1135. CASE_AVX512_INS_COMMON(BROADCASTF32X8, , rm)
  1136. CASE_AVX512_INS_COMMON(BROADCASTI32X8, , rm)
  1137. DecodeSubVectorBroadcast(16, 8, ShuffleMask);
  1138. DestName = getRegName(MI->getOperand(0).getReg());
  1139. break;
  1140. CASE_AVX512_INS_COMMON(BROADCASTI32X2, Z128, rr)
  1141. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1142. LLVM_FALLTHROUGH;
  1143. CASE_AVX512_INS_COMMON(BROADCASTI32X2, Z128, rm)
  1144. DecodeSubVectorBroadcast(4, 2, ShuffleMask);
  1145. DestName = getRegName(MI->getOperand(0).getReg());
  1146. break;
  1147. CASE_AVX512_INS_COMMON(BROADCASTF32X2, Z256, rr)
  1148. CASE_AVX512_INS_COMMON(BROADCASTI32X2, Z256, rr)
  1149. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1150. LLVM_FALLTHROUGH;
  1151. CASE_AVX512_INS_COMMON(BROADCASTF32X2, Z256, rm)
  1152. CASE_AVX512_INS_COMMON(BROADCASTI32X2, Z256, rm)
  1153. DecodeSubVectorBroadcast(8, 2, ShuffleMask);
  1154. DestName = getRegName(MI->getOperand(0).getReg());
  1155. break;
  1156. CASE_AVX512_INS_COMMON(BROADCASTF32X2, Z, rr)
  1157. CASE_AVX512_INS_COMMON(BROADCASTI32X2, Z, rr)
  1158. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1159. LLVM_FALLTHROUGH;
  1160. CASE_AVX512_INS_COMMON(BROADCASTF32X2, Z, rm)
  1161. CASE_AVX512_INS_COMMON(BROADCASTI32X2, Z, rm)
  1162. DecodeSubVectorBroadcast(16, 2, ShuffleMask);
  1163. DestName = getRegName(MI->getOperand(0).getReg());
  1164. break;
  1165. CASE_PMOVZX(PMOVZXBW, r)
  1166. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1167. LLVM_FALLTHROUGH;
  1168. CASE_PMOVZX(PMOVZXBW, m)
  1169. DecodeZeroExtendMask(8, 16, getRegOperandNumElts(MI, 16, 0), false,
  1170. ShuffleMask);
  1171. DestName = getRegName(MI->getOperand(0).getReg());
  1172. break;
  1173. CASE_PMOVZX(PMOVZXBD, r)
  1174. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1175. LLVM_FALLTHROUGH;
  1176. CASE_PMOVZX(PMOVZXBD, m)
  1177. DecodeZeroExtendMask(8, 32, getRegOperandNumElts(MI, 32, 0), false,
  1178. ShuffleMask);
  1179. DestName = getRegName(MI->getOperand(0).getReg());
  1180. break;
  1181. CASE_PMOVZX(PMOVZXBQ, r)
  1182. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1183. LLVM_FALLTHROUGH;
  1184. CASE_PMOVZX(PMOVZXBQ, m)
  1185. DecodeZeroExtendMask(8, 64, getRegOperandNumElts(MI, 64, 0), false,
  1186. ShuffleMask);
  1187. DestName = getRegName(MI->getOperand(0).getReg());
  1188. break;
  1189. CASE_PMOVZX(PMOVZXWD, r)
  1190. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1191. LLVM_FALLTHROUGH;
  1192. CASE_PMOVZX(PMOVZXWD, m)
  1193. DecodeZeroExtendMask(16, 32, getRegOperandNumElts(MI, 32, 0), false,
  1194. ShuffleMask);
  1195. DestName = getRegName(MI->getOperand(0).getReg());
  1196. break;
  1197. CASE_PMOVZX(PMOVZXWQ, r)
  1198. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1199. LLVM_FALLTHROUGH;
  1200. CASE_PMOVZX(PMOVZXWQ, m)
  1201. DecodeZeroExtendMask(16, 64, getRegOperandNumElts(MI, 64, 0), false,
  1202. ShuffleMask);
  1203. DestName = getRegName(MI->getOperand(0).getReg());
  1204. break;
  1205. CASE_PMOVZX(PMOVZXDQ, r)
  1206. Src1Name = getRegName(MI->getOperand(NumOperands - 1).getReg());
  1207. LLVM_FALLTHROUGH;
  1208. CASE_PMOVZX(PMOVZXDQ, m)
  1209. DecodeZeroExtendMask(32, 64, getRegOperandNumElts(MI, 64, 0), false,
  1210. ShuffleMask);
  1211. DestName = getRegName(MI->getOperand(0).getReg());
  1212. break;
  1213. }
  1214. // The only comments we decode are shuffles, so give up if we were unable to
  1215. // decode a shuffle mask.
  1216. if (ShuffleMask.empty())
  1217. return false;
  1218. if (!DestName) DestName = Src1Name;
  1219. if (DestName) {
  1220. OS << DestName;
  1221. printMasking(OS, MI, MCII);
  1222. } else
  1223. OS << "mem";
  1224. OS << " = ";
  1225. // If the two sources are the same, canonicalize the input elements to be
  1226. // from the first src so that we get larger element spans.
  1227. if (Src1Name == Src2Name) {
  1228. for (unsigned i = 0, e = ShuffleMask.size(); i != e; ++i) {
  1229. if ((int)ShuffleMask[i] >= 0 && // Not sentinel.
  1230. ShuffleMask[i] >= (int)e) // From second mask.
  1231. ShuffleMask[i] -= e;
  1232. }
  1233. }
  1234. // The shuffle mask specifies which elements of the src1/src2 fill in the
  1235. // destination, with a few sentinel values. Loop through and print them
  1236. // out.
  1237. for (unsigned i = 0, e = ShuffleMask.size(); i != e; ++i) {
  1238. if (i != 0)
  1239. OS << ',';
  1240. if (ShuffleMask[i] == SM_SentinelZero) {
  1241. OS << "zero";
  1242. continue;
  1243. }
  1244. // Otherwise, it must come from src1 or src2. Print the span of elements
  1245. // that comes from this src.
  1246. bool isSrc1 = ShuffleMask[i] < (int)ShuffleMask.size();
  1247. const char *SrcName = isSrc1 ? Src1Name : Src2Name;
  1248. OS << (SrcName ? SrcName : "mem") << '[';
  1249. bool IsFirst = true;
  1250. while (i != e && (int)ShuffleMask[i] != SM_SentinelZero &&
  1251. (ShuffleMask[i] < (int)ShuffleMask.size()) == isSrc1) {
  1252. if (!IsFirst)
  1253. OS << ',';
  1254. else
  1255. IsFirst = false;
  1256. if (ShuffleMask[i] == SM_SentinelUndef)
  1257. OS << "u";
  1258. else
  1259. OS << ShuffleMask[i] % ShuffleMask.size();
  1260. ++i;
  1261. }
  1262. OS << ']';
  1263. --i; // For loop increments element #.
  1264. }
  1265. OS << '\n';
  1266. // We successfully added a comment to this instruction.
  1267. return true;
  1268. }