PPCInstr64Bit.td 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981
  1. //===-- PPCInstr64Bit.td - The PowerPC 64-bit Support ------*- 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 PowerPC 64-bit instructions. These patterns are used
  10. // both when in ppc64 mode and when in "use 64-bit extensions in 32-bit" mode.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. // 64-bit operands.
  15. //
  16. def s16imm64 : Operand<i64> {
  17. let PrintMethod = "printS16ImmOperand";
  18. let EncoderMethod = "getImm16Encoding";
  19. let ParserMatchClass = PPCS16ImmAsmOperand;
  20. let DecoderMethod = "decodeSImmOperand<16>";
  21. let OperandType = "OPERAND_IMMEDIATE";
  22. }
  23. def u16imm64 : Operand<i64> {
  24. let PrintMethod = "printU16ImmOperand";
  25. let EncoderMethod = "getImm16Encoding";
  26. let ParserMatchClass = PPCU16ImmAsmOperand;
  27. let DecoderMethod = "decodeUImmOperand<16>";
  28. let OperandType = "OPERAND_IMMEDIATE";
  29. }
  30. def s17imm64 : Operand<i64> {
  31. // This operand type is used for addis/lis to allow the assembler parser
  32. // to accept immediates in the range -65536..65535 for compatibility with
  33. // the GNU assembler. The operand is treated as 16-bit otherwise.
  34. let PrintMethod = "printS16ImmOperand";
  35. let EncoderMethod = "getImm16Encoding";
  36. let ParserMatchClass = PPCS17ImmAsmOperand;
  37. let DecoderMethod = "decodeSImmOperand<16>";
  38. let OperandType = "OPERAND_IMMEDIATE";
  39. }
  40. def tocentry : Operand<iPTR> {
  41. let MIOperandInfo = (ops i64imm:$imm);
  42. }
  43. def tlsreg : Operand<i64> {
  44. let EncoderMethod = "getTLSRegEncoding";
  45. let ParserMatchClass = PPCTLSRegOperand;
  46. }
  47. def tlsgd : Operand<i64> {}
  48. def tlscall : Operand<i64> {
  49. let PrintMethod = "printTLSCall";
  50. let MIOperandInfo = (ops calltarget:$func, tlsgd:$sym);
  51. let EncoderMethod = "getTLSCallEncoding";
  52. }
  53. //===----------------------------------------------------------------------===//
  54. // 64-bit transformation functions.
  55. //
  56. def SHL64 : SDNodeXForm<imm, [{
  57. // Transformation function: 63 - imm
  58. return getI32Imm(63 - N->getZExtValue(), SDLoc(N));
  59. }]>;
  60. def SRL64 : SDNodeXForm<imm, [{
  61. // Transformation function: 64 - imm
  62. return N->getZExtValue() ? getI32Imm(64 - N->getZExtValue(), SDLoc(N))
  63. : getI32Imm(0, SDLoc(N));
  64. }]>;
  65. //===----------------------------------------------------------------------===//
  66. // Calls.
  67. //
  68. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  69. let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7, hasSideEffects = 0 in {
  70. let isReturn = 1, isPredicable = 1, Uses = [LR8, RM] in
  71. def BLR8 : XLForm_2_ext<19, 16, 20, 0, 0, (outs), (ins), "blr", IIC_BrB,
  72. [(retflag)]>, Requires<[In64BitMode]>;
  73. let isBranch = 1, isIndirectBranch = 1, Uses = [CTR8] in {
  74. let isPredicable = 1 in
  75. def BCTR8 : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", IIC_BrB,
  76. []>,
  77. Requires<[In64BitMode]>;
  78. def BCCCTR8 : XLForm_2_br<19, 528, 0, (outs), (ins pred:$cond),
  79. "b${cond:cc}ctr${cond:pm} ${cond:reg}", IIC_BrB,
  80. []>,
  81. Requires<[In64BitMode]>;
  82. def BCCTR8 : XLForm_2_br2<19, 528, 12, 0, (outs), (ins crbitrc:$bi),
  83. "bcctr 12, $bi, 0", IIC_BrB, []>,
  84. Requires<[In64BitMode]>;
  85. def BCCTR8n : XLForm_2_br2<19, 528, 4, 0, (outs), (ins crbitrc:$bi),
  86. "bcctr 4, $bi, 0", IIC_BrB, []>,
  87. Requires<[In64BitMode]>;
  88. }
  89. }
  90. let Defs = [LR8] in
  91. def MovePCtoLR8 : PPCEmitTimePseudo<(outs), (ins), "#MovePCtoLR8", []>,
  92. PPC970_Unit_BRU;
  93. let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7, hasSideEffects = 0 in {
  94. let Defs = [CTR8], Uses = [CTR8] in {
  95. def BDZ8 : BForm_1<16, 18, 0, 0, (outs), (ins condbrtarget:$dst),
  96. "bdz $dst">;
  97. def BDNZ8 : BForm_1<16, 16, 0, 0, (outs), (ins condbrtarget:$dst),
  98. "bdnz $dst">;
  99. }
  100. let isReturn = 1, Defs = [CTR8], Uses = [CTR8, LR8, RM] in {
  101. def BDZLR8 : XLForm_2_ext<19, 16, 18, 0, 0, (outs), (ins),
  102. "bdzlr", IIC_BrB, []>;
  103. def BDNZLR8 : XLForm_2_ext<19, 16, 16, 0, 0, (outs), (ins),
  104. "bdnzlr", IIC_BrB, []>;
  105. }
  106. }
  107. let isCall = 1, PPC970_Unit = 7, Defs = [LR8], hasSideEffects = 0 in {
  108. // Convenient aliases for call instructions
  109. let Uses = [RM] in {
  110. def BL8 : IForm<18, 0, 1, (outs), (ins calltarget:$func),
  111. "bl $func", IIC_BrB, []>; // See Pat patterns below.
  112. def BL8_TLS : IForm<18, 0, 1, (outs), (ins tlscall:$func),
  113. "bl $func", IIC_BrB, []>;
  114. def BLA8 : IForm<18, 1, 1, (outs), (ins abscalltarget:$func),
  115. "bla $func", IIC_BrB, [(PPCcall (i64 imm:$func))]>;
  116. }
  117. let Uses = [RM], isCodeGenOnly = 1 in {
  118. def BL8_NOP : IForm_and_DForm_4_zero<18, 0, 1, 24,
  119. (outs), (ins calltarget:$func),
  120. "bl $func\n\tnop", IIC_BrB, []>;
  121. def BL8_NOP_TLS : IForm_and_DForm_4_zero<18, 0, 1, 24,
  122. (outs), (ins tlscall:$func),
  123. "bl $func\n\tnop", IIC_BrB, []>;
  124. def BLA8_NOP : IForm_and_DForm_4_zero<18, 1, 1, 24,
  125. (outs), (ins abscalltarget:$func),
  126. "bla $func\n\tnop", IIC_BrB,
  127. [(PPCcall_nop (i64 imm:$func))]>;
  128. let Predicates = [PCRelativeMemops] in {
  129. // BL8_NOTOC means that the caller does not use the TOC pointer and if
  130. // it does use R2 then it is just a caller saved register. Therefore it is
  131. // safe to emit only the bl and not the nop for this instruction. The
  132. // linker will not try to restore R2 after the call.
  133. def BL8_NOTOC : IForm<18, 0, 1, (outs),
  134. (ins calltarget:$func),
  135. "bl $func", IIC_BrB, []>;
  136. def BL8_NOTOC_TLS : IForm<18, 0, 1, (outs),
  137. (ins tlscall:$func),
  138. "bl $func", IIC_BrB, []>;
  139. }
  140. }
  141. let Uses = [CTR8, RM] in {
  142. let isPredicable = 1 in
  143. def BCTRL8 : XLForm_2_ext<19, 528, 20, 0, 1, (outs), (ins),
  144. "bctrl", IIC_BrB, [(PPCbctrl)]>,
  145. Requires<[In64BitMode]>;
  146. let isCodeGenOnly = 1 in {
  147. def BCCCTRL8 : XLForm_2_br<19, 528, 1, (outs), (ins pred:$cond),
  148. "b${cond:cc}ctrl${cond:pm} ${cond:reg}", IIC_BrB,
  149. []>,
  150. Requires<[In64BitMode]>;
  151. def BCCTRL8 : XLForm_2_br2<19, 528, 12, 1, (outs), (ins crbitrc:$bi),
  152. "bcctrl 12, $bi, 0", IIC_BrB, []>,
  153. Requires<[In64BitMode]>;
  154. def BCCTRL8n : XLForm_2_br2<19, 528, 4, 1, (outs), (ins crbitrc:$bi),
  155. "bcctrl 4, $bi, 0", IIC_BrB, []>,
  156. Requires<[In64BitMode]>;
  157. }
  158. }
  159. }
  160. let isCall = 1, PPC970_Unit = 7, Defs = [LR8, RM], hasSideEffects = 0,
  161. isCodeGenOnly = 1, Uses = [RM] in {
  162. // Convenient aliases for call instructions
  163. def BL8_RM : IForm<18, 0, 1, (outs), (ins calltarget:$func),
  164. "bl $func", IIC_BrB, []>; // See Pat patterns below.
  165. def BLA8_RM : IForm<18, 1, 1, (outs), (ins abscalltarget:$func),
  166. "bla $func", IIC_BrB, [(PPCcall_rm (i64 imm:$func))]>;
  167. def BL8_NOP_RM : IForm_and_DForm_4_zero<18, 0, 1, 24,
  168. (outs), (ins calltarget:$func),
  169. "bl $func\n\tnop", IIC_BrB, []>;
  170. def BLA8_NOP_RM : IForm_and_DForm_4_zero<18, 1, 1, 24,
  171. (outs), (ins abscalltarget:$func),
  172. "bla $func\n\tnop", IIC_BrB,
  173. [(PPCcall_nop_rm (i64 imm:$func))]>;
  174. let Predicates = [PCRelativeMemops] in {
  175. // BL8_NOTOC means that the caller does not use the TOC pointer and if
  176. // it does use R2 then it is just a caller saved register. Therefore it is
  177. // safe to emit only the bl and not the nop for this instruction. The
  178. // linker will not try to restore R2 after the call.
  179. def BL8_NOTOC_RM : IForm<18, 0, 1, (outs),
  180. (ins calltarget:$func),
  181. "bl $func", IIC_BrB, []>;
  182. }
  183. let Uses = [CTR8, RM] in {
  184. let isPredicable = 1 in
  185. def BCTRL8_RM : XLForm_2_ext<19, 528, 20, 0, 1, (outs), (ins),
  186. "bctrl", IIC_BrB, [(PPCbctrl_rm)]>,
  187. Requires<[In64BitMode]>;
  188. }
  189. }
  190. let isCall = 1, PPC970_Unit = 7, isCodeGenOnly = 1,
  191. Defs = [LR8, X2], Uses = [CTR8, RM], RST = 2 in {
  192. def BCTRL8_LDinto_toc :
  193. XLForm_2_ext_and_DSForm_1<19, 528, 20, 0, 1, 58, 0, (outs),
  194. (ins memrix:$src),
  195. "bctrl\n\tld 2, $src", IIC_BrB,
  196. [(PPCbctrl_load_toc iaddrX4:$src)]>,
  197. Requires<[In64BitMode]>;
  198. }
  199. let isCall = 1, PPC970_Unit = 7, isCodeGenOnly = 1,
  200. Defs = [LR8, X2, RM], Uses = [CTR8, RM], RST = 2 in {
  201. def BCTRL8_LDinto_toc_RM :
  202. XLForm_2_ext_and_DSForm_1<19, 528, 20, 0, 1, 58, 0, (outs),
  203. (ins memrix:$src),
  204. "bctrl\n\tld 2, $src", IIC_BrB,
  205. [(PPCbctrl_load_toc_rm iaddrX4:$src)]>,
  206. Requires<[In64BitMode]>;
  207. }
  208. } // Interpretation64Bit
  209. // FIXME: Duplicating this for the asm parser should be unnecessary, but the
  210. // previous definition must be marked as CodeGen only to prevent decoding
  211. // conflicts.
  212. let Interpretation64Bit = 1, isAsmParserOnly = 1, hasSideEffects = 0 in
  213. let isCall = 1, PPC970_Unit = 7, Defs = [LR8], Uses = [RM] in
  214. def BL8_TLS_ : IForm<18, 0, 1, (outs), (ins tlscall:$func),
  215. "bl $func", IIC_BrB, []>;
  216. // Calls
  217. def : Pat<(PPCcall (i64 tglobaladdr:$dst)),
  218. (BL8 tglobaladdr:$dst)>;
  219. def : Pat<(PPCcall_nop (i64 tglobaladdr:$dst)),
  220. (BL8_NOP tglobaladdr:$dst)>;
  221. def : Pat<(PPCcall (i64 texternalsym:$dst)),
  222. (BL8 texternalsym:$dst)>;
  223. def : Pat<(PPCcall_nop (i64 texternalsym:$dst)),
  224. (BL8_NOP texternalsym:$dst)>;
  225. def : Pat<(PPCcall_notoc (i64 tglobaladdr:$dst)),
  226. (BL8_NOTOC tglobaladdr:$dst)>;
  227. def : Pat<(PPCcall_notoc (i64 texternalsym:$dst)),
  228. (BL8_NOTOC texternalsym:$dst)>;
  229. def : Pat<(PPCcall_rm (i64 tglobaladdr:$dst)),
  230. (BL8_RM tglobaladdr:$dst)>;
  231. def : Pat<(PPCcall_nop_rm (i64 tglobaladdr:$dst)),
  232. (BL8_NOP_RM tglobaladdr:$dst)>;
  233. def : Pat<(PPCcall_rm (i64 texternalsym:$dst)),
  234. (BL8_RM texternalsym:$dst)>;
  235. def : Pat<(PPCcall_nop_rm (i64 texternalsym:$dst)),
  236. (BL8_NOP_RM texternalsym:$dst)>;
  237. def : Pat<(PPCcall_notoc_rm (i64 tglobaladdr:$dst)),
  238. (BL8_NOTOC_RM tglobaladdr:$dst)>;
  239. def : Pat<(PPCcall_notoc_rm (i64 texternalsym:$dst)),
  240. (BL8_NOTOC_RM texternalsym:$dst)>;
  241. // Calls for AIX
  242. def : Pat<(PPCcall (i64 mcsym:$dst)),
  243. (BL8 mcsym:$dst)>;
  244. def : Pat<(PPCcall_nop (i64 mcsym:$dst)),
  245. (BL8_NOP mcsym:$dst)>;
  246. def : Pat<(PPCcall_rm (i64 mcsym:$dst)),
  247. (BL8_RM mcsym:$dst)>;
  248. def : Pat<(PPCcall_nop_rm (i64 mcsym:$dst)),
  249. (BL8_NOP_RM mcsym:$dst)>;
  250. // Atomic operations
  251. // FIXME: some of these might be used with constant operands. This will result
  252. // in constant materialization instructions that may be redundant. We currently
  253. // clean this up in PPCMIPeephole with calls to
  254. // PPCInstrInfo::convertToImmediateForm() but we should probably not emit them
  255. // in the first place.
  256. let Defs = [CR0] in {
  257. def ATOMIC_LOAD_ADD_I64 : PPCCustomInserterPseudo<
  258. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_ADD_I64",
  259. [(set i64:$dst, (atomic_load_add_64 ForceXForm:$ptr, i64:$incr))]>;
  260. def ATOMIC_LOAD_SUB_I64 : PPCCustomInserterPseudo<
  261. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_SUB_I64",
  262. [(set i64:$dst, (atomic_load_sub_64 ForceXForm:$ptr, i64:$incr))]>;
  263. def ATOMIC_LOAD_OR_I64 : PPCCustomInserterPseudo<
  264. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_OR_I64",
  265. [(set i64:$dst, (atomic_load_or_64 ForceXForm:$ptr, i64:$incr))]>;
  266. def ATOMIC_LOAD_XOR_I64 : PPCCustomInserterPseudo<
  267. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_XOR_I64",
  268. [(set i64:$dst, (atomic_load_xor_64 ForceXForm:$ptr, i64:$incr))]>;
  269. def ATOMIC_LOAD_AND_I64 : PPCCustomInserterPseudo<
  270. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_AND_i64",
  271. [(set i64:$dst, (atomic_load_and_64 ForceXForm:$ptr, i64:$incr))]>;
  272. def ATOMIC_LOAD_NAND_I64 : PPCCustomInserterPseudo<
  273. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_NAND_I64",
  274. [(set i64:$dst, (atomic_load_nand_64 ForceXForm:$ptr, i64:$incr))]>;
  275. def ATOMIC_LOAD_MIN_I64 : PPCCustomInserterPseudo<
  276. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_MIN_I64",
  277. [(set i64:$dst, (atomic_load_min_64 ForceXForm:$ptr, i64:$incr))]>;
  278. def ATOMIC_LOAD_MAX_I64 : PPCCustomInserterPseudo<
  279. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_MAX_I64",
  280. [(set i64:$dst, (atomic_load_max_64 ForceXForm:$ptr, i64:$incr))]>;
  281. def ATOMIC_LOAD_UMIN_I64 : PPCCustomInserterPseudo<
  282. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_UMIN_I64",
  283. [(set i64:$dst, (atomic_load_umin_64 ForceXForm:$ptr, i64:$incr))]>;
  284. def ATOMIC_LOAD_UMAX_I64 : PPCCustomInserterPseudo<
  285. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$incr), "#ATOMIC_LOAD_UMAX_I64",
  286. [(set i64:$dst, (atomic_load_umax_64 ForceXForm:$ptr, i64:$incr))]>;
  287. def ATOMIC_CMP_SWAP_I64 : PPCCustomInserterPseudo<
  288. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$old, g8rc:$new), "#ATOMIC_CMP_SWAP_I64",
  289. [(set i64:$dst, (atomic_cmp_swap_64 ForceXForm:$ptr, i64:$old, i64:$new))]>;
  290. def ATOMIC_SWAP_I64 : PPCCustomInserterPseudo<
  291. (outs g8rc:$dst), (ins memrr:$ptr, g8rc:$new), "#ATOMIC_SWAP_I64",
  292. [(set i64:$dst, (atomic_swap_64 ForceXForm:$ptr, i64:$new))]>;
  293. }
  294. // Instructions to support atomic operations
  295. let mayLoad = 1, hasSideEffects = 0 in {
  296. def LDARX : XForm_1_memOp<31, 84, (outs g8rc:$rD), (ins memrr:$ptr),
  297. "ldarx $rD, $ptr", IIC_LdStLDARX, []>;
  298. // TODO: Add scheduling info.
  299. let hasNoSchedulingInfo = 1 in
  300. def LQARX : XForm_1_memOp<31, 276, (outs g8prc:$RTp), (ins memrr:$ptr),
  301. "lqarx $RTp, $ptr", IIC_LdStLQARX, []>, isPPC64;
  302. // Instruction to support lock versions of atomics
  303. // (EH=1 - see Power ISA 2.07 Book II 4.4.2)
  304. def LDARXL : XForm_1<31, 84, (outs g8rc:$rD), (ins memrr:$ptr),
  305. "ldarx $rD, $ptr, 1", IIC_LdStLDARX, []>, isRecordForm;
  306. // TODO: Add scheduling info.
  307. let hasNoSchedulingInfo = 1 in
  308. // FIXME: We have to seek a way to remove isRecordForm since
  309. // LQARXL is not really altering CR0.
  310. def LQARXL : XForm_1<31, 276, (outs g8prc:$RTp), (ins memrr:$ptr),
  311. "lqarx $RTp, $ptr, 1", IIC_LdStLQARX, []>,
  312. isPPC64, isRecordForm;
  313. let hasExtraDefRegAllocReq = 1 in
  314. def LDAT : X_RD5_RS5_IM5<31, 614, (outs g8rc:$rD), (ins g8rc:$rA, u5imm:$FC),
  315. "ldat $rD, $rA, $FC", IIC_LdStLoad>, isPPC64,
  316. Requires<[IsISA3_0]>;
  317. }
  318. let Defs = [CR0], mayStore = 1, mayLoad = 0, hasSideEffects = 0 in {
  319. def STDCX : XForm_1_memOp<31, 214, (outs), (ins g8rc:$rS, memrr:$dst),
  320. "stdcx. $rS, $dst", IIC_LdStSTDCX, []>, isRecordForm;
  321. // TODO: Add scheduling info.
  322. let hasNoSchedulingInfo = 1 in
  323. def STQCX : XForm_1_memOp<31, 182, (outs), (ins g8prc:$RSp, memrr:$dst),
  324. "stqcx. $RSp, $dst", IIC_LdStSTQCX, []>,
  325. isPPC64, isRecordForm;
  326. }
  327. def SPLIT_QUADWORD : PPCCustomInserterPseudo<(outs g8rc:$lo, g8rc:$hi),
  328. (ins g8prc:$src),
  329. "#SPLIT_QUADWORD", []>;
  330. class AtomicRMW128<string asmstr>
  331. : PPCPostRAExpPseudo<(outs g8prc:$RTp, g8prc:$scratch),
  332. (ins memrr:$ptr, g8rc:$incr_lo, g8rc:$incr_hi),
  333. asmstr, []>;
  334. // We have to keep values in MI's uses during LL/SC looping as they are,
  335. // so set both $RTp and $scratch earlyclobber.
  336. let mayStore = 1, mayLoad = 1,
  337. Defs = [CR0],
  338. Constraints = "@earlyclobber $scratch,@earlyclobber $RTp" in {
  339. // Atomic pseudo instructions expanded post-ra.
  340. def ATOMIC_SWAP_I128 : AtomicRMW128<"#ATOMIC_SWAP_I128">;
  341. def ATOMIC_LOAD_ADD_I128 : AtomicRMW128<"#ATOMIC_LOAD_ADD_I128">;
  342. def ATOMIC_LOAD_SUB_I128 : AtomicRMW128<"#ATOMIC_LOAD_SUB_I128">;
  343. def ATOMIC_LOAD_AND_I128 : AtomicRMW128<"#ATOMIC_LOAD_AND_I128">;
  344. def ATOMIC_LOAD_XOR_I128 : AtomicRMW128<"#ATOMIC_LOAD_XOR_I128">;
  345. def ATOMIC_LOAD_OR_I128 : AtomicRMW128<"#ATOMIC_LOAD_OR_I128">;
  346. def ATOMIC_LOAD_NAND_I128 : AtomicRMW128<"#ATOMIC_LOAD_NAND_I128">;
  347. def ATOMIC_CMP_SWAP_I128 : PPCPostRAExpPseudo<
  348. (outs g8prc:$RTp, g8prc:$scratch),
  349. (ins memrr:$ptr, g8rc:$cmp_lo, g8rc:$cmp_hi,
  350. g8rc:$new_lo, g8rc:$new_hi),
  351. "#ATOMIC_CMP_SWAP_I128", []>;
  352. }
  353. def : Pat<(int_ppc_atomicrmw_add_i128 ForceXForm:$ptr,
  354. i64:$incr_lo,
  355. i64:$incr_hi),
  356. (SPLIT_QUADWORD (ATOMIC_LOAD_ADD_I128 memrr:$ptr,
  357. g8rc:$incr_lo,
  358. g8rc:$incr_hi))>;
  359. def : Pat<(int_ppc_atomicrmw_sub_i128 ForceXForm:$ptr,
  360. i64:$incr_lo,
  361. i64:$incr_hi),
  362. (SPLIT_QUADWORD (ATOMIC_LOAD_SUB_I128 memrr:$ptr,
  363. g8rc:$incr_lo,
  364. g8rc:$incr_hi))>;
  365. def : Pat<(int_ppc_atomicrmw_xor_i128 ForceXForm:$ptr,
  366. i64:$incr_lo,
  367. i64:$incr_hi),
  368. (SPLIT_QUADWORD (ATOMIC_LOAD_XOR_I128 memrr:$ptr,
  369. g8rc:$incr_lo,
  370. g8rc:$incr_hi))>;
  371. def : Pat<(int_ppc_atomicrmw_and_i128 ForceXForm:$ptr,
  372. i64:$incr_lo,
  373. i64:$incr_hi),
  374. (SPLIT_QUADWORD (ATOMIC_LOAD_AND_I128 memrr:$ptr,
  375. g8rc:$incr_lo,
  376. g8rc:$incr_hi))>;
  377. def : Pat<(int_ppc_atomicrmw_nand_i128 ForceXForm:$ptr,
  378. i64:$incr_lo,
  379. i64:$incr_hi),
  380. (SPLIT_QUADWORD (ATOMIC_LOAD_NAND_I128 memrr:$ptr,
  381. g8rc:$incr_lo,
  382. g8rc:$incr_hi))>;
  383. def : Pat<(int_ppc_atomicrmw_or_i128 ForceXForm:$ptr,
  384. i64:$incr_lo,
  385. i64:$incr_hi),
  386. (SPLIT_QUADWORD (ATOMIC_LOAD_OR_I128 memrr:$ptr,
  387. g8rc:$incr_lo,
  388. g8rc:$incr_hi))>;
  389. def : Pat<(int_ppc_atomicrmw_xchg_i128 ForceXForm:$ptr,
  390. i64:$incr_lo,
  391. i64:$incr_hi),
  392. (SPLIT_QUADWORD (ATOMIC_SWAP_I128 memrr:$ptr,
  393. g8rc:$incr_lo,
  394. g8rc:$incr_hi))>;
  395. def : Pat<(int_ppc_cmpxchg_i128 ForceXForm:$ptr,
  396. i64:$cmp_lo,
  397. i64:$cmp_hi,
  398. i64:$new_lo,
  399. i64:$new_hi),
  400. (SPLIT_QUADWORD (ATOMIC_CMP_SWAP_I128
  401. memrr:$ptr,
  402. g8rc:$cmp_lo,
  403. g8rc:$cmp_hi,
  404. g8rc:$new_lo,
  405. g8rc:$new_hi))>;
  406. let mayStore = 1, mayLoad = 0, hasSideEffects = 0 in
  407. def STDAT : X_RD5_RS5_IM5<31, 742, (outs), (ins g8rc:$rS, g8rc:$rA, u5imm:$FC),
  408. "stdat $rS, $rA, $FC", IIC_LdStStore>, isPPC64,
  409. Requires<[IsISA3_0]>;
  410. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  411. let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
  412. def TCRETURNdi8 :PPCEmitTimePseudo< (outs),
  413. (ins calltarget:$dst, i32imm:$offset),
  414. "#TC_RETURNd8 $dst $offset",
  415. []>;
  416. let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
  417. def TCRETURNai8 :PPCEmitTimePseudo<(outs), (ins abscalltarget:$func, i32imm:$offset),
  418. "#TC_RETURNa8 $func $offset",
  419. [(PPCtc_return (i64 imm:$func), imm:$offset)]>;
  420. let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
  421. def TCRETURNri8 : PPCEmitTimePseudo<(outs), (ins CTRRC8:$dst, i32imm:$offset),
  422. "#TC_RETURNr8 $dst $offset",
  423. []>;
  424. let hasSideEffects = 0 in {
  425. let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7, isBranch = 1,
  426. isIndirectBranch = 1, isCall = 1, isReturn = 1, Uses = [CTR8, RM] in
  427. def TAILBCTR8 : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", IIC_BrB,
  428. []>,
  429. Requires<[In64BitMode]>;
  430. let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
  431. isBarrier = 1, isCall = 1, isReturn = 1, Uses = [RM] in
  432. def TAILB8 : IForm<18, 0, 0, (outs), (ins calltarget:$dst),
  433. "b $dst", IIC_BrB,
  434. []>;
  435. let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
  436. isBarrier = 1, isCall = 1, isReturn = 1, Uses = [RM] in
  437. def TAILBA8 : IForm<18, 0, 0, (outs), (ins abscalltarget:$dst),
  438. "ba $dst", IIC_BrB,
  439. []>;
  440. }
  441. } // Interpretation64Bit
  442. def : Pat<(PPCtc_return (i64 tglobaladdr:$dst), imm:$imm),
  443. (TCRETURNdi8 tglobaladdr:$dst, imm:$imm)>;
  444. def : Pat<(PPCtc_return (i64 texternalsym:$dst), imm:$imm),
  445. (TCRETURNdi8 texternalsym:$dst, imm:$imm)>;
  446. def : Pat<(PPCtc_return CTRRC8:$dst, imm:$imm),
  447. (TCRETURNri8 CTRRC8:$dst, imm:$imm)>;
  448. // 64-bit CR instructions
  449. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  450. let hasSideEffects = 0 in {
  451. // mtocrf's input needs to be prepared by shifting by an amount dependent
  452. // on the cr register selected. Thus, post-ra anti-dep breaking must not
  453. // later change that register assignment.
  454. let hasExtraDefRegAllocReq = 1 in {
  455. def MTOCRF8: XFXForm_5a<31, 144, (outs crbitm:$FXM), (ins g8rc:$ST),
  456. "mtocrf $FXM, $ST", IIC_BrMCRX>,
  457. PPC970_DGroup_First, PPC970_Unit_CRU;
  458. // Similarly to mtocrf, the mask for mtcrf must be prepared in a way that
  459. // is dependent on the cr fields being set.
  460. def MTCRF8 : XFXForm_5<31, 144, (outs), (ins i32imm:$FXM, g8rc:$rS),
  461. "mtcrf $FXM, $rS", IIC_BrMCRX>,
  462. PPC970_MicroCode, PPC970_Unit_CRU;
  463. } // hasExtraDefRegAllocReq = 1
  464. // mfocrf's input needs to be prepared by shifting by an amount dependent
  465. // on the cr register selected. Thus, post-ra anti-dep breaking must not
  466. // later change that register assignment.
  467. let hasExtraSrcRegAllocReq = 1 in {
  468. def MFOCRF8: XFXForm_5a<31, 19, (outs g8rc:$rT), (ins crbitm:$FXM),
  469. "mfocrf $rT, $FXM", IIC_SprMFCRF>,
  470. PPC970_DGroup_First, PPC970_Unit_CRU;
  471. // Similarly to mfocrf, the mask for mfcrf must be prepared in a way that
  472. // is dependent on the cr fields being copied.
  473. def MFCR8 : XFXForm_3<31, 19, (outs g8rc:$rT), (ins),
  474. "mfcr $rT", IIC_SprMFCR>,
  475. PPC970_MicroCode, PPC970_Unit_CRU;
  476. } // hasExtraSrcRegAllocReq = 1
  477. } // hasSideEffects = 0
  478. // While longjmp is a control-flow barrier (fallthrough isn't allowed), setjmp
  479. // is not.
  480. let hasSideEffects = 1 in {
  481. let Defs = [CTR8] in
  482. def EH_SjLj_SetJmp64 : PPCCustomInserterPseudo<(outs gprc:$dst), (ins memr:$buf),
  483. "#EH_SJLJ_SETJMP64",
  484. [(set i32:$dst, (PPCeh_sjlj_setjmp addr:$buf))]>,
  485. Requires<[In64BitMode]>;
  486. }
  487. let hasSideEffects = 1, isBarrier = 1 in {
  488. let isTerminator = 1 in
  489. def EH_SjLj_LongJmp64 : PPCCustomInserterPseudo<(outs), (ins memr:$buf),
  490. "#EH_SJLJ_LONGJMP64",
  491. [(PPCeh_sjlj_longjmp addr:$buf)]>,
  492. Requires<[In64BitMode]>;
  493. }
  494. def MFSPR8 : XFXForm_1<31, 339, (outs g8rc:$RT), (ins i32imm:$SPR),
  495. "mfspr $RT, $SPR", IIC_SprMFSPR>;
  496. def MTSPR8 : XFXForm_1<31, 467, (outs), (ins i32imm:$SPR, g8rc:$RT),
  497. "mtspr $SPR, $RT", IIC_SprMTSPR>;
  498. //===----------------------------------------------------------------------===//
  499. // 64-bit SPR manipulation instrs.
  500. let Uses = [CTR8] in {
  501. def MFCTR8 : XFXForm_1_ext<31, 339, 9, (outs g8rc:$rT), (ins),
  502. "mfctr $rT", IIC_SprMFSPR>,
  503. PPC970_DGroup_First, PPC970_Unit_FXU;
  504. }
  505. let Pattern = [(PPCmtctr i64:$rS)], Defs = [CTR8] in {
  506. def MTCTR8 : XFXForm_7_ext<31, 467, 9, (outs), (ins g8rc:$rS),
  507. "mtctr $rS", IIC_SprMTSPR>,
  508. PPC970_DGroup_First, PPC970_Unit_FXU;
  509. }
  510. // MTCTR[8|]loop must be inside a loop-preheader, duplicating
  511. // the loop-preheader block will break this assumption.
  512. let hasSideEffects = 1, isNotDuplicable = 1, Defs = [CTR8] in {
  513. let Pattern = [(int_set_loop_iterations i64:$rS)] in
  514. def MTCTR8loop : XFXForm_7_ext<31, 467, 9, (outs), (ins g8rc:$rS),
  515. "mtctr $rS", IIC_SprMTSPR>,
  516. PPC970_DGroup_First, PPC970_Unit_FXU;
  517. }
  518. let hasSideEffects = 1, hasNoSchedulingInfo = 1, isNotDuplicable = 1, Uses = [CTR8], Defs = [CTR8] in
  519. def DecreaseCTR8loop : PPCEmitTimePseudo<(outs crbitrc:$rT), (ins i64imm:$stride),
  520. "#DecreaseCTR8loop", [(set i1:$rT, (int_loop_decrement (i64 imm:$stride)))]>;
  521. let Pattern = [(set i64:$rT, readcyclecounter)] in
  522. def MFTB8 : XFXForm_1_ext<31, 339, 268, (outs g8rc:$rT), (ins),
  523. "mfspr $rT, 268", IIC_SprMFTB>,
  524. PPC970_DGroup_First, PPC970_Unit_FXU;
  525. // Note that encoding mftb using mfspr is now the preferred form,
  526. // and has been since at least ISA v2.03. The mftb instruction has
  527. // now been phased out. Using mfspr, however, is known not to work on
  528. // the POWER3.
  529. let Defs = [X1], Uses = [X1] in
  530. def DYNALLOC8 : PPCEmitTimePseudo<(outs g8rc:$result), (ins g8rc:$negsize, memri:$fpsi),"#DYNALLOC8",
  531. [(set i64:$result,
  532. (PPCdynalloc i64:$negsize, iaddr:$fpsi))]>;
  533. def DYNAREAOFFSET8 : PPCEmitTimePseudo<(outs i64imm:$result), (ins memri:$fpsi), "#DYNAREAOFFSET8",
  534. [(set i64:$result, (PPCdynareaoffset iaddr:$fpsi))]>;
  535. // Probed alloca to support stack clash protection.
  536. let Defs = [X1], Uses = [X1], hasNoSchedulingInfo = 1 in {
  537. def PROBED_ALLOCA_64 : PPCCustomInserterPseudo<(outs g8rc:$result),
  538. (ins g8rc:$negsize, memri:$fpsi), "#PROBED_ALLOCA_64",
  539. [(set i64:$result,
  540. (PPCprobedalloca i64:$negsize, iaddr:$fpsi))]>;
  541. def PREPARE_PROBED_ALLOCA_64 : PPCEmitTimePseudo<(outs
  542. g8rc:$fp, g8rc:$actual_negsize),
  543. (ins g8rc:$negsize, memri:$fpsi), "#PREPARE_PROBED_ALLOCA_64", []>;
  544. def PREPARE_PROBED_ALLOCA_NEGSIZE_SAME_REG_64 : PPCEmitTimePseudo<(outs
  545. g8rc:$fp, g8rc:$actual_negsize),
  546. (ins g8rc:$negsize, memri:$fpsi),
  547. "#PREPARE_PROBED_ALLOCA_NEGSIZE_SAME_REG_64", []>,
  548. RegConstraint<"$actual_negsize = $negsize">;
  549. def PROBED_STACKALLOC_64 : PPCEmitTimePseudo<(outs g8rc:$scratch, g8rc:$temp),
  550. (ins i64imm:$stacksize),
  551. "#PROBED_STACKALLOC_64", []>;
  552. }
  553. let hasSideEffects = 0 in {
  554. let Defs = [LR8] in {
  555. def MTLR8 : XFXForm_7_ext<31, 467, 8, (outs), (ins g8rc:$rS),
  556. "mtlr $rS", IIC_SprMTSPR>,
  557. PPC970_DGroup_First, PPC970_Unit_FXU;
  558. }
  559. let Uses = [LR8] in {
  560. def MFLR8 : XFXForm_1_ext<31, 339, 8, (outs g8rc:$rT), (ins),
  561. "mflr $rT", IIC_SprMFSPR>,
  562. PPC970_DGroup_First, PPC970_Unit_FXU;
  563. }
  564. } // Interpretation64Bit
  565. }
  566. //===----------------------------------------------------------------------===//
  567. // Fixed point instructions.
  568. //
  569. let PPC970_Unit = 1 in { // FXU Operations.
  570. let Interpretation64Bit = 1 in {
  571. let hasSideEffects = 0 in {
  572. let isCodeGenOnly = 1 in {
  573. let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in {
  574. def LI8 : DForm_2_r0<14, (outs g8rc:$rD), (ins s16imm64:$imm),
  575. "li $rD, $imm", IIC_IntSimple,
  576. [(set i64:$rD, imm64SExt16:$imm)]>, SExt32To64;
  577. def LIS8 : DForm_2_r0<15, (outs g8rc:$rD), (ins s17imm64:$imm),
  578. "lis $rD, $imm", IIC_IntSimple,
  579. [(set i64:$rD, imm16ShiftedSExt:$imm)]>, SExt32To64;
  580. }
  581. // Logical ops.
  582. let isCommutable = 1 in {
  583. defm NAND8: XForm_6r<31, 476, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  584. "nand", "$rA, $rS, $rB", IIC_IntSimple,
  585. [(set i64:$rA, (not (and i64:$rS, i64:$rB)))]>;
  586. defm AND8 : XForm_6r<31, 28, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  587. "and", "$rA, $rS, $rB", IIC_IntSimple,
  588. [(set i64:$rA, (and i64:$rS, i64:$rB))]>;
  589. } // isCommutable
  590. defm ANDC8: XForm_6r<31, 60, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  591. "andc", "$rA, $rS, $rB", IIC_IntSimple,
  592. [(set i64:$rA, (and i64:$rS, (not i64:$rB)))]>;
  593. let isCommutable = 1 in {
  594. defm OR8 : XForm_6r<31, 444, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  595. "or", "$rA, $rS, $rB", IIC_IntSimple,
  596. [(set i64:$rA, (or i64:$rS, i64:$rB))]>;
  597. defm NOR8 : XForm_6r<31, 124, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  598. "nor", "$rA, $rS, $rB", IIC_IntSimple,
  599. [(set i64:$rA, (not (or i64:$rS, i64:$rB)))]>;
  600. } // isCommutable
  601. defm ORC8 : XForm_6r<31, 412, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  602. "orc", "$rA, $rS, $rB", IIC_IntSimple,
  603. [(set i64:$rA, (or i64:$rS, (not i64:$rB)))]>;
  604. let isCommutable = 1 in {
  605. defm EQV8 : XForm_6r<31, 284, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  606. "eqv", "$rA, $rS, $rB", IIC_IntSimple,
  607. [(set i64:$rA, (not (xor i64:$rS, i64:$rB)))]>;
  608. defm XOR8 : XForm_6r<31, 316, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  609. "xor", "$rA, $rS, $rB", IIC_IntSimple,
  610. [(set i64:$rA, (xor i64:$rS, i64:$rB))]>;
  611. } // let isCommutable = 1
  612. // Logical ops with immediate.
  613. let Defs = [CR0] in {
  614. def ANDI8_rec : DForm_4<28, (outs g8rc:$dst), (ins g8rc:$src1, u16imm64:$src2),
  615. "andi. $dst, $src1, $src2", IIC_IntGeneral,
  616. [(set i64:$dst, (and i64:$src1, immZExt16:$src2))]>,
  617. isRecordForm, SExt32To64, ZExt32To64;
  618. def ANDIS8_rec : DForm_4<29, (outs g8rc:$dst), (ins g8rc:$src1, u16imm64:$src2),
  619. "andis. $dst, $src1, $src2", IIC_IntGeneral,
  620. [(set i64:$dst, (and i64:$src1, imm16ShiftedZExt:$src2))]>,
  621. isRecordForm, ZExt32To64;
  622. }
  623. def ORI8 : DForm_4<24, (outs g8rc:$dst), (ins g8rc:$src1, u16imm64:$src2),
  624. "ori $dst, $src1, $src2", IIC_IntSimple,
  625. [(set i64:$dst, (or i64:$src1, immZExt16:$src2))]>;
  626. def ORIS8 : DForm_4<25, (outs g8rc:$dst), (ins g8rc:$src1, u16imm64:$src2),
  627. "oris $dst, $src1, $src2", IIC_IntSimple,
  628. [(set i64:$dst, (or i64:$src1, imm16ShiftedZExt:$src2))]>;
  629. def XORI8 : DForm_4<26, (outs g8rc:$dst), (ins g8rc:$src1, u16imm64:$src2),
  630. "xori $dst, $src1, $src2", IIC_IntSimple,
  631. [(set i64:$dst, (xor i64:$src1, immZExt16:$src2))]>;
  632. def XORIS8 : DForm_4<27, (outs g8rc:$dst), (ins g8rc:$src1, u16imm64:$src2),
  633. "xoris $dst, $src1, $src2", IIC_IntSimple,
  634. [(set i64:$dst, (xor i64:$src1, imm16ShiftedZExt:$src2))]>;
  635. let isCommutable = 1 in
  636. defm ADD8 : XOForm_1rx<31, 266, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  637. "add", "$rT, $rA, $rB", IIC_IntSimple,
  638. [(set i64:$rT, (add i64:$rA, i64:$rB))]>;
  639. // ADD8 has a special form: reg = ADD8(reg, sym@tls) for use by the
  640. // initial-exec thread-local storage model. We need to forbid r0 here -
  641. // while it works for add just fine, the linker can relax this to local-exec
  642. // addi, which won't work for r0.
  643. def ADD8TLS : XOForm_1<31, 266, 0, (outs g8rc:$rT), (ins g8rc_nox0:$rA, tlsreg:$rB),
  644. "add $rT, $rA, $rB", IIC_IntSimple,
  645. [(set i64:$rT, (add i64:$rA, tglobaltlsaddr:$rB))]>;
  646. let mayLoad = 1 in {
  647. def LBZXTLS : XForm_1<31, 87, (outs g8rc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  648. "lbzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  649. def LHZXTLS : XForm_1<31, 279, (outs g8rc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  650. "lhzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  651. def LWZXTLS : XForm_1<31, 23, (outs g8rc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  652. "lwzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  653. def LDXTLS : XForm_1<31, 21, (outs g8rc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  654. "ldx $rD, $rA, $rB", IIC_LdStLD, []>, isPPC64;
  655. def LBZXTLS_32 : XForm_1<31, 87, (outs gprc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  656. "lbzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  657. def LHZXTLS_32 : XForm_1<31, 279, (outs gprc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  658. "lhzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  659. def LWZXTLS_32 : XForm_1<31, 23, (outs gprc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  660. "lwzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  661. }
  662. let mayStore = 1 in {
  663. def STBXTLS : XForm_8<31, 215, (outs), (ins g8rc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  664. "stbx $rS, $rA, $rB", IIC_LdStStore, []>,
  665. PPC970_DGroup_Cracked;
  666. def STHXTLS : XForm_8<31, 407, (outs), (ins g8rc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  667. "sthx $rS, $rA, $rB", IIC_LdStStore, []>,
  668. PPC970_DGroup_Cracked;
  669. def STWXTLS : XForm_8<31, 151, (outs), (ins g8rc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  670. "stwx $rS, $rA, $rB", IIC_LdStStore, []>,
  671. PPC970_DGroup_Cracked;
  672. def STDXTLS : XForm_8<31, 149, (outs), (ins g8rc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  673. "stdx $rS, $rA, $rB", IIC_LdStSTD, []>, isPPC64,
  674. PPC970_DGroup_Cracked;
  675. def STBXTLS_32 : XForm_8<31, 215, (outs), (ins gprc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  676. "stbx $rS, $rA, $rB", IIC_LdStStore, []>,
  677. PPC970_DGroup_Cracked;
  678. def STHXTLS_32 : XForm_8<31, 407, (outs), (ins gprc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  679. "sthx $rS, $rA, $rB", IIC_LdStStore, []>,
  680. PPC970_DGroup_Cracked;
  681. def STWXTLS_32 : XForm_8<31, 151, (outs), (ins gprc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  682. "stwx $rS, $rA, $rB", IIC_LdStStore, []>,
  683. PPC970_DGroup_Cracked;
  684. }
  685. let isCommutable = 1 in
  686. defm ADDC8 : XOForm_1rc<31, 10, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  687. "addc", "$rT, $rA, $rB", IIC_IntGeneral,
  688. [(set i64:$rT, (addc i64:$rA, i64:$rB))]>,
  689. PPC970_DGroup_Cracked;
  690. let Defs = [CARRY] in
  691. def ADDIC8 : DForm_2<12, (outs g8rc:$rD), (ins g8rc:$rA, s16imm64:$imm),
  692. "addic $rD, $rA, $imm", IIC_IntGeneral,
  693. [(set i64:$rD, (addc i64:$rA, imm64SExt16:$imm))]>;
  694. def ADDI8 : DForm_2<14, (outs g8rc:$rD), (ins g8rc_nox0:$rA, s16imm64:$imm),
  695. "addi $rD, $rA, $imm", IIC_IntSimple,
  696. [(set i64:$rD, (add i64:$rA, imm64SExt16:$imm))]>;
  697. def ADDIS8 : DForm_2<15, (outs g8rc:$rD), (ins g8rc_nox0:$rA, s17imm64:$imm),
  698. "addis $rD, $rA, $imm", IIC_IntSimple,
  699. [(set i64:$rD, (add i64:$rA, imm16ShiftedSExt:$imm))]>;
  700. def LA8 : DForm_2<14, (outs g8rc:$rD), (ins g8rc_nox0:$rA, s16imm64:$sym),
  701. "la $rD, $sym($rA)", IIC_IntGeneral,
  702. [(set i64:$rD, (add i64:$rA,
  703. (PPClo tglobaladdr:$sym, 0)))]>;
  704. let Defs = [CARRY] in {
  705. def SUBFIC8: DForm_2< 8, (outs g8rc:$rD), (ins g8rc:$rA, s16imm64:$imm),
  706. "subfic $rD, $rA, $imm", IIC_IntGeneral,
  707. [(set i64:$rD, (subc imm64SExt16:$imm, i64:$rA))]>;
  708. }
  709. defm SUBFC8 : XOForm_1rc<31, 8, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  710. "subfc", "$rT, $rA, $rB", IIC_IntGeneral,
  711. [(set i64:$rT, (subc i64:$rB, i64:$rA))]>,
  712. PPC970_DGroup_Cracked;
  713. defm SUBF8 : XOForm_1rx<31, 40, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  714. "subf", "$rT, $rA, $rB", IIC_IntGeneral,
  715. [(set i64:$rT, (sub i64:$rB, i64:$rA))]>;
  716. defm NEG8 : XOForm_3r<31, 104, 0, (outs g8rc:$rT), (ins g8rc:$rA),
  717. "neg", "$rT, $rA", IIC_IntSimple,
  718. [(set i64:$rT, (ineg i64:$rA))]>;
  719. let Uses = [CARRY] in {
  720. let isCommutable = 1 in
  721. defm ADDE8 : XOForm_1rc<31, 138, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  722. "adde", "$rT, $rA, $rB", IIC_IntGeneral,
  723. [(set i64:$rT, (adde i64:$rA, i64:$rB))]>;
  724. defm ADDME8 : XOForm_3rc<31, 234, 0, (outs g8rc:$rT), (ins g8rc:$rA),
  725. "addme", "$rT, $rA", IIC_IntGeneral,
  726. [(set i64:$rT, (adde i64:$rA, -1))]>;
  727. defm ADDZE8 : XOForm_3rc<31, 202, 0, (outs g8rc:$rT), (ins g8rc:$rA),
  728. "addze", "$rT, $rA", IIC_IntGeneral,
  729. [(set i64:$rT, (adde i64:$rA, 0))]>;
  730. defm SUBFE8 : XOForm_1rc<31, 136, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  731. "subfe", "$rT, $rA, $rB", IIC_IntGeneral,
  732. [(set i64:$rT, (sube i64:$rB, i64:$rA))]>;
  733. defm SUBFME8 : XOForm_3rc<31, 232, 0, (outs g8rc:$rT), (ins g8rc:$rA),
  734. "subfme", "$rT, $rA", IIC_IntGeneral,
  735. [(set i64:$rT, (sube -1, i64:$rA))]>;
  736. defm SUBFZE8 : XOForm_3rc<31, 200, 0, (outs g8rc:$rT), (ins g8rc:$rA),
  737. "subfze", "$rT, $rA", IIC_IntGeneral,
  738. [(set i64:$rT, (sube 0, i64:$rA))]>;
  739. }
  740. } // isCodeGenOnly
  741. // FIXME: Duplicating this for the asm parser should be unnecessary, but the
  742. // previous definition must be marked as CodeGen only to prevent decoding
  743. // conflicts.
  744. let isAsmParserOnly = 1 in {
  745. def ADD8TLS_ : XOForm_1<31, 266, 0, (outs g8rc:$rT), (ins g8rc:$rA, tlsreg:$rB),
  746. "add $rT, $rA, $rB", IIC_IntSimple, []>;
  747. let mayLoad = 1 in {
  748. def LBZXTLS_ : XForm_1<31, 87, (outs g8rc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  749. "lbzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  750. def LHZXTLS_ : XForm_1<31, 279, (outs g8rc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  751. "lhzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  752. def LWZXTLS_ : XForm_1<31, 23, (outs g8rc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  753. "lwzx $rD, $rA, $rB", IIC_LdStLoad, []>;
  754. def LDXTLS_ : XForm_1<31, 21, (outs g8rc:$rD), (ins ptr_rc_nor0:$rA, tlsreg:$rB),
  755. "ldx $rD, $rA, $rB", IIC_LdStLD, []>, isPPC64;
  756. }
  757. let mayStore = 1 in {
  758. def STBXTLS_ : XForm_8<31, 215, (outs), (ins g8rc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  759. "stbx $rS, $rA, $rB", IIC_LdStStore, []>,
  760. PPC970_DGroup_Cracked;
  761. def STHXTLS_ : XForm_8<31, 407, (outs), (ins g8rc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  762. "sthx $rS, $rA, $rB", IIC_LdStStore, []>,
  763. PPC970_DGroup_Cracked;
  764. def STWXTLS_ : XForm_8<31, 151, (outs), (ins g8rc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  765. "stwx $rS, $rA, $rB", IIC_LdStStore, []>,
  766. PPC970_DGroup_Cracked;
  767. def STDXTLS_ : XForm_8<31, 149, (outs), (ins g8rc:$rS, ptr_rc_nor0:$rA, tlsreg:$rB),
  768. "stdx $rS, $rA, $rB", IIC_LdStSTD, []>, isPPC64,
  769. PPC970_DGroup_Cracked;
  770. }
  771. }
  772. let isCommutable = 1 in {
  773. defm MULHD : XOForm_1r<31, 73, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  774. "mulhd", "$rT, $rA, $rB", IIC_IntMulHW,
  775. [(set i64:$rT, (mulhs i64:$rA, i64:$rB))]>;
  776. defm MULHDU : XOForm_1r<31, 9, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  777. "mulhdu", "$rT, $rA, $rB", IIC_IntMulHWU,
  778. [(set i64:$rT, (mulhu i64:$rA, i64:$rB))]>;
  779. } // isCommutable
  780. }
  781. } // Interpretation64Bit
  782. let isCompare = 1, hasSideEffects = 0 in {
  783. def CMPD : XForm_16_ext<31, 0, (outs crrc:$crD), (ins g8rc:$rA, g8rc:$rB),
  784. "cmpd $crD, $rA, $rB", IIC_IntCompare>, isPPC64;
  785. def CMPLD : XForm_16_ext<31, 32, (outs crrc:$crD), (ins g8rc:$rA, g8rc:$rB),
  786. "cmpld $crD, $rA, $rB", IIC_IntCompare>, isPPC64;
  787. def CMPDI : DForm_5_ext<11, (outs crrc:$crD), (ins g8rc:$rA, s16imm64:$imm),
  788. "cmpdi $crD, $rA, $imm", IIC_IntCompare>, isPPC64;
  789. def CMPLDI : DForm_6_ext<10, (outs crrc:$dst), (ins g8rc:$src1, u16imm64:$src2),
  790. "cmpldi $dst, $src1, $src2",
  791. IIC_IntCompare>, isPPC64;
  792. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  793. def CMPRB8 : X_BF3_L1_RS5_RS5<31, 192, (outs crrc:$BF),
  794. (ins u1imm:$L, g8rc:$rA, g8rc:$rB),
  795. "cmprb $BF, $L, $rA, $rB", IIC_IntCompare, []>,
  796. Requires<[IsISA3_0]>;
  797. def CMPEQB : X_BF3_RS5_RS5<31, 224, (outs crrc:$BF),
  798. (ins g8rc:$rA, g8rc:$rB), "cmpeqb $BF, $rA, $rB",
  799. IIC_IntCompare, []>, Requires<[IsISA3_0]>;
  800. }
  801. let hasSideEffects = 0 in {
  802. defm SLD : XForm_6r<31, 27, (outs g8rc:$rA), (ins g8rc:$rS, gprc:$rB),
  803. "sld", "$rA, $rS, $rB", IIC_IntRotateD,
  804. [(set i64:$rA, (PPCshl i64:$rS, i32:$rB))]>, isPPC64;
  805. defm SRD : XForm_6r<31, 539, (outs g8rc:$rA), (ins g8rc:$rS, gprc:$rB),
  806. "srd", "$rA, $rS, $rB", IIC_IntRotateD,
  807. [(set i64:$rA, (PPCsrl i64:$rS, i32:$rB))]>, isPPC64;
  808. defm SRAD : XForm_6rc<31, 794, (outs g8rc:$rA), (ins g8rc:$rS, gprc:$rB),
  809. "srad", "$rA, $rS, $rB", IIC_IntRotateD,
  810. [(set i64:$rA, (PPCsra i64:$rS, i32:$rB))]>, isPPC64;
  811. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  812. defm CNTLZW8 : XForm_11r<31, 26, (outs g8rc:$rA), (ins g8rc:$rS),
  813. "cntlzw", "$rA, $rS", IIC_IntGeneral, []>,
  814. ZExt32To64, SExt32To64;
  815. defm CNTTZW8 : XForm_11r<31, 538, (outs g8rc:$rA), (ins g8rc:$rS),
  816. "cnttzw", "$rA, $rS", IIC_IntGeneral, []>,
  817. Requires<[IsISA3_0]>, ZExt32To64, SExt32To64;
  818. defm EXTSB8 : XForm_11r<31, 954, (outs g8rc:$rA), (ins g8rc:$rS),
  819. "extsb", "$rA, $rS", IIC_IntSimple,
  820. [(set i64:$rA, (sext_inreg i64:$rS, i8))]>, SExt32To64;
  821. defm EXTSH8 : XForm_11r<31, 922, (outs g8rc:$rA), (ins g8rc:$rS),
  822. "extsh", "$rA, $rS", IIC_IntSimple,
  823. [(set i64:$rA, (sext_inreg i64:$rS, i16))]>, SExt32To64;
  824. defm SLW8 : XForm_6r<31, 24, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  825. "slw", "$rA, $rS, $rB", IIC_IntGeneral, []>, ZExt32To64;
  826. defm SRW8 : XForm_6r<31, 536, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  827. "srw", "$rA, $rS, $rB", IIC_IntGeneral, []>, ZExt32To64;
  828. } // Interpretation64Bit
  829. // For fast-isel:
  830. let isCodeGenOnly = 1 in {
  831. def EXTSB8_32_64 : XForm_11<31, 954, (outs g8rc:$rA), (ins gprc:$rS),
  832. "extsb $rA, $rS", IIC_IntSimple, []>, isPPC64,
  833. SExt32To64;
  834. def EXTSH8_32_64 : XForm_11<31, 922, (outs g8rc:$rA), (ins gprc:$rS),
  835. "extsh $rA, $rS", IIC_IntSimple, []>, isPPC64,
  836. SExt32To64;
  837. } // isCodeGenOnly for fast-isel
  838. defm EXTSW : XForm_11r<31, 986, (outs g8rc:$rA), (ins g8rc:$rS),
  839. "extsw", "$rA, $rS", IIC_IntSimple,
  840. [(set i64:$rA, (sext_inreg i64:$rS, i32))]>, isPPC64,
  841. SExt32To64;
  842. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  843. defm EXTSW_32_64 : XForm_11r<31, 986, (outs g8rc:$rA), (ins gprc:$rS),
  844. "extsw", "$rA, $rS", IIC_IntSimple,
  845. [(set i64:$rA, (sext i32:$rS))]>, isPPC64,
  846. SExt32To64;
  847. let isCodeGenOnly = 1 in
  848. def EXTSW_32 : XForm_11<31, 986, (outs gprc:$rA), (ins gprc:$rS),
  849. "extsw $rA, $rS", IIC_IntSimple,
  850. []>, isPPC64;
  851. defm SRADI : XSForm_1rc<31, 413, (outs g8rc:$rA), (ins g8rc:$rS, u6imm:$SH),
  852. "sradi", "$rA, $rS, $SH", IIC_IntRotateDI,
  853. [(set i64:$rA, (sra i64:$rS, (i32 imm:$SH)))]>, isPPC64;
  854. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  855. defm EXTSWSLI_32_64 : XSForm_1r<31, 445, (outs g8rc:$rA),
  856. (ins gprc:$rS, u6imm:$SH),
  857. "extswsli", "$rA, $rS, $SH", IIC_IntRotateDI,
  858. [(set i64:$rA,
  859. (PPCextswsli i32:$rS, (i32 imm:$SH)))]>,
  860. isPPC64, Requires<[IsISA3_0]>;
  861. defm EXTSWSLI : XSForm_1rc<31, 445, (outs g8rc:$rA), (ins g8rc:$rS, u6imm:$SH),
  862. "extswsli", "$rA, $rS, $SH", IIC_IntRotateDI,
  863. []>, isPPC64, Requires<[IsISA3_0]>;
  864. // For fast-isel:
  865. let isCodeGenOnly = 1, Defs = [CARRY] in
  866. def SRADI_32 : XSForm_1<31, 413, (outs gprc:$rA), (ins gprc:$rS, u6imm:$SH),
  867. "sradi $rA, $rS, $SH", IIC_IntRotateDI, []>, isPPC64;
  868. defm CNTLZD : XForm_11r<31, 58, (outs g8rc:$rA), (ins g8rc:$rS),
  869. "cntlzd", "$rA, $rS", IIC_IntGeneral,
  870. [(set i64:$rA, (ctlz i64:$rS))]>,
  871. ZExt32To64, SExt32To64;
  872. defm CNTTZD : XForm_11r<31, 570, (outs g8rc:$rA), (ins g8rc:$rS),
  873. "cnttzd", "$rA, $rS", IIC_IntGeneral,
  874. [(set i64:$rA, (cttz i64:$rS))]>, Requires<[IsISA3_0]>,
  875. ZExt32To64, SExt32To64;
  876. def POPCNTD : XForm_11<31, 506, (outs g8rc:$rA), (ins g8rc:$rS),
  877. "popcntd $rA, $rS", IIC_IntGeneral,
  878. [(set i64:$rA, (ctpop i64:$rS))]>,
  879. ZExt32To64, SExt32To64;
  880. def BPERMD : XForm_6<31, 252, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  881. "bpermd $rA, $rS, $rB", IIC_IntGeneral,
  882. [(set i64:$rA, (int_ppc_bpermd g8rc:$rS, g8rc:$rB))]>,
  883. isPPC64, Requires<[HasBPERMD]>;
  884. let isCodeGenOnly = 1, isCommutable = 1 in
  885. def CMPB8 : XForm_6<31, 508, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
  886. "cmpb $rA, $rS, $rB", IIC_IntGeneral,
  887. [(set i64:$rA, (PPCcmpb i64:$rS, i64:$rB))]>;
  888. // popcntw also does a population count on the high 32 bits (storing the
  889. // results in the high 32-bits of the output). We'll ignore that here (which is
  890. // safe because we never separately use the high part of the 64-bit registers).
  891. def POPCNTW : XForm_11<31, 378, (outs gprc:$rA), (ins gprc:$rS),
  892. "popcntw $rA, $rS", IIC_IntGeneral,
  893. [(set i32:$rA, (ctpop i32:$rS))]>;
  894. let isCodeGenOnly = 1 in
  895. def POPCNTB8 : XForm_11<31, 122, (outs g8rc:$rA), (ins g8rc:$rS),
  896. "popcntb $rA, $rS", IIC_IntGeneral,
  897. [(set i64:$rA, (int_ppc_popcntb i64:$rS))]>;
  898. defm DIVD : XOForm_1rcr<31, 489, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  899. "divd", "$rT, $rA, $rB", IIC_IntDivD,
  900. [(set i64:$rT, (sdiv i64:$rA, i64:$rB))]>, isPPC64;
  901. defm DIVDU : XOForm_1rcr<31, 457, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  902. "divdu", "$rT, $rA, $rB", IIC_IntDivD,
  903. [(set i64:$rT, (udiv i64:$rA, i64:$rB))]>, isPPC64;
  904. defm DIVDE : XOForm_1rcr<31, 425, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  905. "divde", "$rT, $rA, $rB", IIC_IntDivD,
  906. [(set i64:$rT, (int_ppc_divde g8rc:$rA, g8rc:$rB))]>,
  907. isPPC64, Requires<[HasExtDiv]>;
  908. let Predicates = [IsISA3_0] in {
  909. def MADDHD : VAForm_1a<48, (outs g8rc :$RT), (ins g8rc:$RA, g8rc:$RB, g8rc:$RC),
  910. "maddhd $RT, $RA, $RB, $RC", IIC_IntMulHD, []>, isPPC64;
  911. def MADDHDU : VAForm_1a<49,
  912. (outs g8rc :$RT), (ins g8rc:$RA, g8rc:$RB, g8rc:$RC),
  913. "maddhdu $RT, $RA, $RB, $RC", IIC_IntMulHD, []>, isPPC64;
  914. def MADDLD : VAForm_1a<51, (outs gprc :$RT), (ins gprc:$RA, gprc:$RB, gprc:$RC),
  915. "maddld $RT, $RA, $RB, $RC", IIC_IntMulHD,
  916. [(set i32:$RT, (add_without_simm16 (mul_without_simm16 i32:$RA, i32:$RB), i32:$RC))]>,
  917. isPPC64;
  918. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  919. def MADDLD8 : VAForm_1a<51,
  920. (outs g8rc :$RT), (ins g8rc:$RA, g8rc:$RB, g8rc:$RC),
  921. "maddld $RT, $RA, $RB, $RC", IIC_IntMulHD,
  922. [(set i64:$RT, (add_without_simm16 (mul_without_simm16 i64:$RA, i64:$RB), i64:$RC))]>,
  923. isPPC64;
  924. def SETB8 : XForm_44<31, 128, (outs g8rc:$RT), (ins crrc:$BFA),
  925. "setb $RT, $BFA", IIC_IntGeneral>, isPPC64, SExt32To64;
  926. }
  927. def ADDPCIS : DXForm<19, 2, (outs g8rc:$RT), (ins i32imm:$D),
  928. "addpcis $RT, $D", IIC_BrB, []>, isPPC64;
  929. def MODSD : XForm_8<31, 777, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  930. "modsd $rT, $rA, $rB", IIC_IntDivW,
  931. [(set i64:$rT, (srem i64:$rA, i64:$rB))]>;
  932. def MODUD : XForm_8<31, 265, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  933. "modud $rT, $rA, $rB", IIC_IntDivW,
  934. [(set i64:$rT, (urem i64:$rA, i64:$rB))]>;
  935. }
  936. defm DIVDEU : XOForm_1rcr<31, 393, 0, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  937. "divdeu", "$rT, $rA, $rB", IIC_IntDivD,
  938. [(set i64:$rT, (int_ppc_divdeu g8rc:$rA, g8rc:$rB))]>,
  939. isPPC64, Requires<[HasExtDiv]>;
  940. let isCommutable = 1 in
  941. defm MULLD : XOForm_1rx<31, 233, (outs g8rc:$rT), (ins g8rc:$rA, g8rc:$rB),
  942. "mulld", "$rT, $rA, $rB", IIC_IntMulHD,
  943. [(set i64:$rT, (mul i64:$rA, i64:$rB))]>, isPPC64;
  944. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  945. def MULLI8 : DForm_2<7, (outs g8rc:$rD), (ins g8rc:$rA, s16imm64:$imm),
  946. "mulli $rD, $rA, $imm", IIC_IntMulLI,
  947. [(set i64:$rD, (mul i64:$rA, imm64SExt16:$imm))]>;
  948. }
  949. let hasSideEffects = 1 in {
  950. def DARN : XForm_45<31, 755, (outs g8rc:$RT), (ins u2imm:$L),
  951. "darn $RT, $L", IIC_LdStLD>, isPPC64;
  952. }
  953. let hasSideEffects = 0 in {
  954. defm RLDIMI : MDForm_1r<30, 3, (outs g8rc:$rA),
  955. (ins g8rc:$rSi, g8rc:$rS, u6imm:$SH, u6imm:$MBE),
  956. "rldimi", "$rA, $rS, $SH, $MBE", IIC_IntRotateDI,
  957. []>, isPPC64, RegConstraint<"$rSi = $rA">,
  958. NoEncode<"$rSi">;
  959. // Rotate instructions.
  960. defm RLDCL : MDSForm_1r<30, 8,
  961. (outs g8rc:$rA), (ins g8rc:$rS, gprc:$rB, u6imm:$MBE),
  962. "rldcl", "$rA, $rS, $rB, $MBE", IIC_IntRotateD,
  963. []>, isPPC64;
  964. defm RLDCR : MDSForm_1r<30, 9,
  965. (outs g8rc:$rA), (ins g8rc:$rS, gprc:$rB, u6imm:$MBE),
  966. "rldcr", "$rA, $rS, $rB, $MBE", IIC_IntRotateD,
  967. []>, isPPC64;
  968. defm RLDICL : MDForm_1r<30, 0,
  969. (outs g8rc:$rA), (ins g8rc:$rS, u6imm:$SH, u6imm:$MBE),
  970. "rldicl", "$rA, $rS, $SH, $MBE", IIC_IntRotateDI,
  971. []>, isPPC64;
  972. // For fast-isel:
  973. let isCodeGenOnly = 1 in
  974. def RLDICL_32_64 : MDForm_1<30, 0,
  975. (outs g8rc:$rA),
  976. (ins gprc:$rS, u6imm:$SH, u6imm:$MBE),
  977. "rldicl $rA, $rS, $SH, $MBE", IIC_IntRotateDI,
  978. []>, isPPC64;
  979. // End fast-isel.
  980. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  981. defm RLDICL_32 : MDForm_1r<30, 0,
  982. (outs gprc:$rA),
  983. (ins gprc:$rS, u6imm:$SH, u6imm:$MBE),
  984. "rldicl", "$rA, $rS, $SH, $MBE", IIC_IntRotateDI,
  985. []>, isPPC64;
  986. defm RLDICR : MDForm_1r<30, 1,
  987. (outs g8rc:$rA), (ins g8rc:$rS, u6imm:$SH, u6imm:$MBE),
  988. "rldicr", "$rA, $rS, $SH, $MBE", IIC_IntRotateDI,
  989. []>, isPPC64;
  990. let isCodeGenOnly = 1 in
  991. def RLDICR_32 : MDForm_1<30, 1,
  992. (outs gprc:$rA), (ins gprc:$rS, u6imm:$SH, u6imm:$MBE),
  993. "rldicr $rA, $rS, $SH, $MBE", IIC_IntRotateDI,
  994. []>, isPPC64;
  995. defm RLDIC : MDForm_1r<30, 2,
  996. (outs g8rc:$rA), (ins g8rc:$rS, u6imm:$SH, u6imm:$MBE),
  997. "rldic", "$rA, $rS, $SH, $MBE", IIC_IntRotateDI,
  998. []>, isPPC64;
  999. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  1000. defm RLWINM8 : MForm_2r<21, (outs g8rc:$rA),
  1001. (ins g8rc:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
  1002. "rlwinm", "$rA, $rS, $SH, $MB, $ME", IIC_IntGeneral,
  1003. []>;
  1004. defm RLWNM8 : MForm_2r<23, (outs g8rc:$rA),
  1005. (ins g8rc:$rS, g8rc:$rB, u5imm:$MB, u5imm:$ME),
  1006. "rlwnm", "$rA, $rS, $rB, $MB, $ME", IIC_IntGeneral,
  1007. []>;
  1008. // RLWIMI can be commuted if the rotate amount is zero.
  1009. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  1010. defm RLWIMI8 : MForm_2r<20, (outs g8rc:$rA),
  1011. (ins g8rc:$rSi, g8rc:$rS, u5imm:$SH, u5imm:$MB,
  1012. u5imm:$ME), "rlwimi", "$rA, $rS, $SH, $MB, $ME",
  1013. IIC_IntRotate, []>, PPC970_DGroup_Cracked,
  1014. RegConstraint<"$rSi = $rA">, NoEncode<"$rSi">;
  1015. let isSelect = 1 in
  1016. def ISEL8 : AForm_4<31, 15,
  1017. (outs g8rc:$rT), (ins g8rc_nox0:$rA, g8rc:$rB, crbitrc:$cond),
  1018. "isel $rT, $rA, $rB, $cond", IIC_IntISEL,
  1019. []>;
  1020. } // Interpretation64Bit
  1021. } // hasSideEffects = 0
  1022. } // End FXU Operations.
  1023. def : InstAlias<"li $rD, $imm", (ADDI8 g8rc:$rD, ZERO8, s16imm64:$imm)>;
  1024. def : InstAlias<"lis $rD, $imm", (ADDIS8 g8rc:$rD, ZERO8, s17imm64:$imm)>;
  1025. def : InstAlias<"mr $rA, $rB", (OR8 g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
  1026. def : InstAlias<"mr. $rA, $rB", (OR8_rec g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
  1027. def : InstAlias<"not $rA, $rB", (NOR8 g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
  1028. def : InstAlias<"not. $rA, $rB", (NOR8_rec g8rc:$rA, g8rc:$rB, g8rc:$rB)>;
  1029. def : InstAlias<"mtcr $rA", (MTCRF8 255, g8rc:$rA)>;
  1030. def : InstAlias<"sub $rA, $rB, $rC", (SUBF8 g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
  1031. def : InstAlias<"sub. $rA, $rB, $rC", (SUBF8_rec g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
  1032. def : InstAlias<"subc $rA, $rB, $rC", (SUBFC8 g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
  1033. def : InstAlias<"subc. $rA, $rB, $rC", (SUBFC8_rec g8rc:$rA, g8rc:$rC, g8rc:$rB)>;
  1034. def : InstAlias<"rotlwi $rA, $rS, $n", (RLWINM8 g8rc:$rA, g8rc:$rS, u5imm:$n, 0, 31)>;
  1035. def : InstAlias<"rotlwi. $rA, $rS, $n", (RLWINM8_rec g8rc:$rA, g8rc:$rS, u5imm:$n, 0, 31)>;
  1036. def : InstAlias<"rotlw $rA, $rS, $rB", (RLWNM8 g8rc:$rA, g8rc:$rS, g8rc:$rB, 0, 31)>;
  1037. def : InstAlias<"rotlw. $rA, $rS, $rB", (RLWNM8_rec g8rc:$rA, g8rc:$rS, g8rc:$rB, 0, 31)>;
  1038. def : InstAlias<"clrlwi $rA, $rS, $n", (RLWINM8 g8rc:$rA, g8rc:$rS, 0, u5imm:$n, 31)>;
  1039. def : InstAlias<"clrlwi. $rA, $rS, $n", (RLWINM8_rec g8rc:$rA, g8rc:$rS, 0, u5imm:$n, 31)>;
  1040. def : InstAlias<"isellt $rT, $rA, $rB",
  1041. (ISEL8 g8rc:$rT, g8rc_nox0:$rA, g8rc:$rB, CR0LT)>;
  1042. def : InstAlias<"iselgt $rT, $rA, $rB",
  1043. (ISEL8 g8rc:$rT, g8rc_nox0:$rA, g8rc:$rB, CR0GT)>;
  1044. def : InstAlias<"iseleq $rT, $rA, $rB",
  1045. (ISEL8 g8rc:$rT, g8rc_nox0:$rA, g8rc:$rB, CR0EQ)>;
  1046. def : InstAlias<"nop", (ORI8 X0, X0, 0)>;
  1047. def : InstAlias<"xnop", (XORI8 X0, X0, 0)>;
  1048. def : InstAlias<"cntlzw $rA, $rS", (CNTLZW8 g8rc:$rA, g8rc:$rS)>;
  1049. def : InstAlias<"cntlzw. $rA, $rS", (CNTLZW8_rec g8rc:$rA, g8rc:$rS)>;
  1050. def : InstAlias<"mtxer $Rx", (MTSPR8 1, g8rc:$Rx)>;
  1051. def : InstAlias<"mfxer $Rx", (MFSPR8 g8rc:$Rx, 1)>;
  1052. //Disable this alias on AIX for now because as does not support them.
  1053. let Predicates = [ModernAs] in {
  1054. def : InstAlias<"mtudscr $Rx", (MTSPR8 3, g8rc:$Rx)>;
  1055. def : InstAlias<"mfudscr $Rx", (MFSPR8 g8rc:$Rx, 3)>;
  1056. def : InstAlias<"mfrtcu $Rx", (MFSPR8 g8rc:$Rx, 4)>;
  1057. def : InstAlias<"mfrtcl $Rx", (MFSPR8 g8rc:$Rx, 5)>;
  1058. def : InstAlias<"mtlr $Rx", (MTSPR8 8, g8rc:$Rx)>;
  1059. def : InstAlias<"mflr $Rx", (MFSPR8 g8rc:$Rx, 8)>;
  1060. def : InstAlias<"mtctr $Rx", (MTSPR8 9, g8rc:$Rx)>;
  1061. def : InstAlias<"mfctr $Rx", (MFSPR8 g8rc:$Rx, 9)>;
  1062. def : InstAlias<"mtuamr $Rx", (MTSPR8 13, g8rc:$Rx)>;
  1063. def : InstAlias<"mfuamr $Rx", (MFSPR8 g8rc:$Rx, 13)>;
  1064. def : InstAlias<"mtdscr $Rx", (MTSPR8 17, g8rc:$Rx)>;
  1065. def : InstAlias<"mfdscr $Rx", (MFSPR8 g8rc:$Rx, 17)>;
  1066. def : InstAlias<"mtdsisr $Rx", (MTSPR8 18, g8rc:$Rx)>;
  1067. def : InstAlias<"mfdsisr $Rx", (MFSPR8 g8rc:$Rx, 18)>;
  1068. def : InstAlias<"mtdar $Rx", (MTSPR8 19, g8rc:$Rx)>;
  1069. def : InstAlias<"mfdar $Rx", (MFSPR8 g8rc:$Rx, 19)>;
  1070. def : InstAlias<"mtdec $Rx", (MTSPR8 22, g8rc:$Rx)>;
  1071. def : InstAlias<"mfdec $Rx", (MFSPR8 g8rc:$Rx, 22)>;
  1072. def : InstAlias<"mtsdr1 $Rx", (MTSPR8 25, g8rc:$Rx)>;
  1073. def : InstAlias<"mfsdr1 $Rx", (MFSPR8 g8rc:$Rx, 25)>;
  1074. def : InstAlias<"mtsrr0 $Rx", (MTSPR8 26, g8rc:$Rx)>;
  1075. def : InstAlias<"mfsrr0 $Rx", (MFSPR8 g8rc:$Rx, 26)>;
  1076. def : InstAlias<"mtsrr1 $Rx", (MTSPR8 27, g8rc:$Rx)>;
  1077. def : InstAlias<"mfsrr1 $Rx", (MFSPR8 g8rc:$Rx, 27)>;
  1078. def : InstAlias<"mtcfar $Rx", (MTSPR8 28, g8rc:$Rx)>;
  1079. def : InstAlias<"mfcfar $Rx", (MFSPR8 g8rc:$Rx, 28)>;
  1080. def : InstAlias<"mtamr $Rx", (MTSPR8 29, g8rc:$Rx)>;
  1081. def : InstAlias<"mfamr $Rx", (MFSPR8 g8rc:$Rx, 29)>;
  1082. foreach SPRG = 0-3 in {
  1083. def : InstAlias<"mfsprg $RT, "#SPRG, (MFSPR8 g8rc:$RT, !add(SPRG, 272))>;
  1084. def : InstAlias<"mfsprg"#SPRG#" $RT", (MFSPR8 g8rc:$RT, !add(SPRG, 272))>;
  1085. def : InstAlias<"mtsprg "#SPRG#", $RT", (MTSPR8 !add(SPRG, 272), g8rc:$RT)>;
  1086. def : InstAlias<"mtsprg"#SPRG#" $RT", (MTSPR8 !add(SPRG, 272), g8rc:$RT)>;
  1087. }
  1088. def : InstAlias<"mfasr $RT", (MFSPR8 g8rc:$RT, 280)>;
  1089. def : InstAlias<"mtasr $RT", (MTSPR8 280, g8rc:$RT)>;
  1090. def : InstAlias<"mttbl $Rx", (MTSPR8 284, g8rc:$Rx)>;
  1091. def : InstAlias<"mttbu $Rx", (MTSPR8 285, g8rc:$Rx)>;
  1092. def : InstAlias<"mfpvr $RT", (MFSPR8 g8rc:$RT, 287)>;
  1093. def : InstAlias<"mfspefscr $Rx", (MFSPR8 g8rc:$Rx, 512)>;
  1094. def : InstAlias<"mtspefscr $Rx", (MTSPR8 512, g8rc:$Rx)>;
  1095. }
  1096. //===----------------------------------------------------------------------===//
  1097. // Load/Store instructions.
  1098. //
  1099. // Sign extending loads.
  1100. let PPC970_Unit = 2 in {
  1101. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  1102. def LHA8: DForm_1<42, (outs g8rc:$rD), (ins memri:$src),
  1103. "lha $rD, $src", IIC_LdStLHA,
  1104. [(set i64:$rD, (sextloadi16 DForm:$src))]>,
  1105. PPC970_DGroup_Cracked, SExt32To64;
  1106. def LWA : DSForm_1<58, 2, (outs g8rc:$rD), (ins memrix:$src),
  1107. "lwa $rD, $src", IIC_LdStLWA,
  1108. [(set i64:$rD,
  1109. (sextloadi32 DSForm:$src))]>, isPPC64,
  1110. PPC970_DGroup_Cracked, SExt32To64;
  1111. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  1112. def LHAX8: XForm_1_memOp<31, 343, (outs g8rc:$rD), (ins memrr:$src),
  1113. "lhax $rD, $src", IIC_LdStLHA,
  1114. [(set i64:$rD, (sextloadi16 XForm:$src))]>,
  1115. PPC970_DGroup_Cracked, SExt32To64;
  1116. def LWAX : XForm_1_memOp<31, 341, (outs g8rc:$rD), (ins memrr:$src),
  1117. "lwax $rD, $src", IIC_LdStLHA,
  1118. [(set i64:$rD, (sextloadi32 XForm:$src))]>, isPPC64,
  1119. PPC970_DGroup_Cracked, SExt32To64;
  1120. // For fast-isel:
  1121. let isCodeGenOnly = 1, mayLoad = 1, hasSideEffects = 0 in {
  1122. def LWA_32 : DSForm_1<58, 2, (outs gprc:$rD), (ins memrix:$src),
  1123. "lwa $rD, $src", IIC_LdStLWA, []>, isPPC64,
  1124. PPC970_DGroup_Cracked, SExt32To64;
  1125. def LWAX_32 : XForm_1_memOp<31, 341, (outs gprc:$rD), (ins memrr:$src),
  1126. "lwax $rD, $src", IIC_LdStLHA, []>, isPPC64,
  1127. PPC970_DGroup_Cracked, SExt32To64;
  1128. } // end fast-isel isCodeGenOnly
  1129. // Update forms.
  1130. let mayLoad = 1, hasSideEffects = 0 in {
  1131. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  1132. def LHAU8 : DForm_1<43, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1133. (ins memri:$addr),
  1134. "lhau $rD, $addr", IIC_LdStLHAU,
  1135. []>, RegConstraint<"$addr.reg = $ea_result">,
  1136. NoEncode<"$ea_result">;
  1137. // NO LWAU!
  1138. let Interpretation64Bit = 1, isCodeGenOnly = 1 in
  1139. def LHAUX8 : XForm_1_memOp<31, 375, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1140. (ins memrr:$addr),
  1141. "lhaux $rD, $addr", IIC_LdStLHAUX,
  1142. []>, RegConstraint<"$addr.ptrreg = $ea_result">,
  1143. NoEncode<"$ea_result">;
  1144. def LWAUX : XForm_1_memOp<31, 373, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1145. (ins memrr:$addr),
  1146. "lwaux $rD, $addr", IIC_LdStLHAUX,
  1147. []>, RegConstraint<"$addr.ptrreg = $ea_result">,
  1148. NoEncode<"$ea_result">, isPPC64;
  1149. }
  1150. }
  1151. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  1152. // Zero extending loads.
  1153. let PPC970_Unit = 2 in {
  1154. def LBZ8 : DForm_1<34, (outs g8rc:$rD), (ins memri:$src),
  1155. "lbz $rD, $src", IIC_LdStLoad,
  1156. [(set i64:$rD, (zextloadi8 DForm:$src))]>, ZExt32To64,
  1157. SExt32To64;
  1158. def LHZ8 : DForm_1<40, (outs g8rc:$rD), (ins memri:$src),
  1159. "lhz $rD, $src", IIC_LdStLoad,
  1160. [(set i64:$rD, (zextloadi16 DForm:$src))]>, ZExt32To64,
  1161. SExt32To64;
  1162. def LWZ8 : DForm_1<32, (outs g8rc:$rD), (ins memri:$src),
  1163. "lwz $rD, $src", IIC_LdStLoad,
  1164. [(set i64:$rD, (zextloadi32 DForm:$src))]>, isPPC64,
  1165. ZExt32To64;
  1166. def LBZX8 : XForm_1_memOp<31, 87, (outs g8rc:$rD), (ins memrr:$src),
  1167. "lbzx $rD, $src", IIC_LdStLoad,
  1168. [(set i64:$rD, (zextloadi8 XForm:$src))]>, ZExt32To64,
  1169. SExt32To64;
  1170. def LHZX8 : XForm_1_memOp<31, 279, (outs g8rc:$rD), (ins memrr:$src),
  1171. "lhzx $rD, $src", IIC_LdStLoad,
  1172. [(set i64:$rD, (zextloadi16 XForm:$src))]>,
  1173. ZExt32To64, SExt32To64;
  1174. def LWZX8 : XForm_1_memOp<31, 23, (outs g8rc:$rD), (ins memrr:$src),
  1175. "lwzx $rD, $src", IIC_LdStLoad,
  1176. [(set i64:$rD, (zextloadi32 XForm:$src))]>,
  1177. ZExt32To64;
  1178. // Update forms.
  1179. let mayLoad = 1, hasSideEffects = 0 in {
  1180. def LBZU8 : DForm_1<35, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1181. (ins memri:$addr),
  1182. "lbzu $rD, $addr", IIC_LdStLoadUpd,
  1183. []>, RegConstraint<"$addr.reg = $ea_result">,
  1184. NoEncode<"$ea_result">;
  1185. def LHZU8 : DForm_1<41, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1186. (ins memri:$addr),
  1187. "lhzu $rD, $addr", IIC_LdStLoadUpd,
  1188. []>, RegConstraint<"$addr.reg = $ea_result">,
  1189. NoEncode<"$ea_result">;
  1190. def LWZU8 : DForm_1<33, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1191. (ins memri:$addr),
  1192. "lwzu $rD, $addr", IIC_LdStLoadUpd,
  1193. []>, RegConstraint<"$addr.reg = $ea_result">,
  1194. NoEncode<"$ea_result">;
  1195. def LBZUX8 : XForm_1_memOp<31, 119, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1196. (ins memrr:$addr),
  1197. "lbzux $rD, $addr", IIC_LdStLoadUpdX,
  1198. []>, RegConstraint<"$addr.ptrreg = $ea_result">,
  1199. NoEncode<"$ea_result">;
  1200. def LHZUX8 : XForm_1_memOp<31, 311, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1201. (ins memrr:$addr),
  1202. "lhzux $rD, $addr", IIC_LdStLoadUpdX,
  1203. []>, RegConstraint<"$addr.ptrreg = $ea_result">,
  1204. NoEncode<"$ea_result">;
  1205. def LWZUX8 : XForm_1_memOp<31, 55, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1206. (ins memrr:$addr),
  1207. "lwzux $rD, $addr", IIC_LdStLoadUpdX,
  1208. []>, RegConstraint<"$addr.ptrreg = $ea_result">,
  1209. NoEncode<"$ea_result">;
  1210. }
  1211. }
  1212. } // Interpretation64Bit
  1213. // Full 8-byte loads.
  1214. let PPC970_Unit = 2 in {
  1215. def LD : DSForm_1<58, 0, (outs g8rc:$rD), (ins memrix:$src),
  1216. "ld $rD, $src", IIC_LdStLD,
  1217. [(set i64:$rD, (load DSForm:$src))]>, isPPC64;
  1218. // The following four definitions are selected for small code model only.
  1219. // Otherwise, we need to create two instructions to form a 32-bit offset,
  1220. // so we have a custom matcher for TOC_ENTRY in PPCDAGToDAGIsel::Select().
  1221. def LDtoc: PPCEmitTimePseudo<(outs g8rc:$rD), (ins tocentry:$disp, g8rc:$reg),
  1222. "#LDtoc",
  1223. [(set i64:$rD,
  1224. (PPCtoc_entry tglobaladdr:$disp, i64:$reg))]>, isPPC64;
  1225. def LDtocJTI: PPCEmitTimePseudo<(outs g8rc:$rD), (ins tocentry:$disp, g8rc:$reg),
  1226. "#LDtocJTI",
  1227. [(set i64:$rD,
  1228. (PPCtoc_entry tjumptable:$disp, i64:$reg))]>, isPPC64;
  1229. def LDtocCPT: PPCEmitTimePseudo<(outs g8rc:$rD), (ins tocentry:$disp, g8rc:$reg),
  1230. "#LDtocCPT",
  1231. [(set i64:$rD,
  1232. (PPCtoc_entry tconstpool:$disp, i64:$reg))]>, isPPC64;
  1233. def LDtocBA: PPCEmitTimePseudo<(outs g8rc:$rD), (ins tocentry:$disp, g8rc:$reg),
  1234. "#LDtocCPT",
  1235. [(set i64:$rD,
  1236. (PPCtoc_entry tblockaddress:$disp, i64:$reg))]>, isPPC64;
  1237. def LDX : XForm_1_memOp<31, 21, (outs g8rc:$rD), (ins memrr:$src),
  1238. "ldx $rD, $src", IIC_LdStLD,
  1239. [(set i64:$rD, (load XForm:$src))]>, isPPC64;
  1240. let Predicates = [IsISA2_06] in {
  1241. def LDBRX : XForm_1_memOp<31, 532, (outs g8rc:$rD), (ins memrr:$src),
  1242. "ldbrx $rD, $src", IIC_LdStLoad,
  1243. [(set i64:$rD, (PPClbrx ForceXForm:$src, i64))]>, isPPC64;
  1244. }
  1245. let mayLoad = 1, hasSideEffects = 0, isCodeGenOnly = 1 in {
  1246. def LHBRX8 : XForm_1_memOp<31, 790, (outs g8rc:$rD), (ins memrr:$src),
  1247. "lhbrx $rD, $src", IIC_LdStLoad, []>, ZExt32To64;
  1248. def LWBRX8 : XForm_1_memOp<31, 534, (outs g8rc:$rD), (ins memrr:$src),
  1249. "lwbrx $rD, $src", IIC_LdStLoad, []>, ZExt32To64;
  1250. }
  1251. let mayLoad = 1, hasSideEffects = 0 in {
  1252. def LDU : DSForm_1<58, 1, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1253. (ins memrix:$addr),
  1254. "ldu $rD, $addr", IIC_LdStLDU,
  1255. []>, RegConstraint<"$addr.reg = $ea_result">, isPPC64,
  1256. NoEncode<"$ea_result">;
  1257. def LDUX : XForm_1_memOp<31, 53, (outs g8rc:$rD, ptr_rc_nor0:$ea_result),
  1258. (ins memrr:$addr),
  1259. "ldux $rD, $addr", IIC_LdStLDUX,
  1260. []>, RegConstraint<"$addr.ptrreg = $ea_result">,
  1261. NoEncode<"$ea_result">, isPPC64;
  1262. }
  1263. let mayLoad = 1, hasNoSchedulingInfo = 1 in {
  1264. // Full 16-byte load.
  1265. // Early clobber $RTp to avoid assigned to the same register as RA.
  1266. // TODO: Add scheduling info.
  1267. def LQ : DQForm_RTp5_RA17_MEM<56, 0,
  1268. (outs g8prc:$RTp),
  1269. (ins memrix16:$src),
  1270. "lq $RTp, $src", IIC_LdStLQ,
  1271. []>,
  1272. RegConstraint<"@earlyclobber $RTp">,
  1273. isPPC64;
  1274. // We don't really have LQX in the ISA, make a pseudo one so that we can
  1275. // handle x-form during isel. Make it pre-ra may expose
  1276. // oppotunities to some opts(CSE, LICM and etc.) for the result of adding
  1277. // RA and RB.
  1278. def LQX_PSEUDO : PPCCustomInserterPseudo<(outs g8prc:$RTp),
  1279. (ins memrr:$src), "#LQX_PSEUDO", []>;
  1280. def RESTORE_QUADWORD : PPCEmitTimePseudo<(outs g8prc:$RTp), (ins memrix:$src),
  1281. "#RESTORE_QUADWORD", []>;
  1282. }
  1283. }
  1284. def : Pat<(int_ppc_atomic_load_i128 iaddrX16:$src),
  1285. (SPLIT_QUADWORD (LQ memrix16:$src))>;
  1286. def : Pat<(int_ppc_atomic_load_i128 ForceXForm:$src),
  1287. (SPLIT_QUADWORD (LQX_PSEUDO memrr:$src))>;
  1288. // Support for medium and large code model.
  1289. let hasSideEffects = 0 in {
  1290. let isReMaterializable = 1 in {
  1291. def ADDIStocHA8: PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, tocentry:$disp),
  1292. "#ADDIStocHA8", []>, isPPC64;
  1293. def ADDItocL: PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, tocentry:$disp),
  1294. "#ADDItocL", []>, isPPC64;
  1295. }
  1296. // Local Data Transform
  1297. def ADDItoc8 : PPCEmitTimePseudo<(outs g8rc:$rD), (ins tocentry:$disp, g8rc_nox0:$reg),
  1298. "#ADDItoc8",
  1299. [(set i64:$rD,
  1300. (PPCtoc_entry tglobaladdr:$disp, i64:$reg))]>, isPPC64;
  1301. let mayLoad = 1 in
  1302. def LDtocL: PPCEmitTimePseudo<(outs g8rc:$rD), (ins tocentry:$disp, g8rc_nox0:$reg),
  1303. "#LDtocL", []>, isPPC64;
  1304. }
  1305. // Support for thread-local storage.
  1306. def ADDISgotTprelHA: PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
  1307. "#ADDISgotTprelHA",
  1308. [(set i64:$rD,
  1309. (PPCaddisGotTprelHA i64:$reg,
  1310. tglobaltlsaddr:$disp))]>,
  1311. isPPC64;
  1312. def LDgotTprelL: PPCEmitTimePseudo<(outs g8rc_nox0:$rD), (ins s16imm64:$disp, g8rc_nox0:$reg),
  1313. "#LDgotTprelL",
  1314. [(set i64:$rD,
  1315. (PPCldGotTprelL tglobaltlsaddr:$disp, i64:$reg))]>,
  1316. isPPC64;
  1317. let Defs = [CR7], Itinerary = IIC_LdStSync in
  1318. def CFENCE8 : PPCPostRAExpPseudo<(outs), (ins g8rc:$cr), "#CFENCE8", []>;
  1319. def : Pat<(PPCaddTls i64:$in, tglobaltlsaddr:$g),
  1320. (ADD8TLS $in, tglobaltlsaddr:$g)>;
  1321. def ADDIStlsgdHA: PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
  1322. "#ADDIStlsgdHA",
  1323. [(set i64:$rD,
  1324. (PPCaddisTlsgdHA i64:$reg, tglobaltlsaddr:$disp))]>,
  1325. isPPC64;
  1326. def ADDItlsgdL : PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
  1327. "#ADDItlsgdL",
  1328. [(set i64:$rD,
  1329. (PPCaddiTlsgdL i64:$reg, tglobaltlsaddr:$disp))]>,
  1330. isPPC64;
  1331. class GETtlsADDRPseudo <string asmstr> : PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc:$reg, tlsgd:$sym),
  1332. asmstr,
  1333. [(set i64:$rD,
  1334. (PPCgetTlsAddr i64:$reg, tglobaltlsaddr:$sym))]>,
  1335. isPPC64;
  1336. class GETtlsldADDRPseudo <string asmstr> : PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc:$reg, tlsgd:$sym),
  1337. asmstr,
  1338. [(set i64:$rD,
  1339. (PPCgetTlsldAddr i64:$reg, tglobaltlsaddr:$sym))]>,
  1340. isPPC64;
  1341. let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1 in {
  1342. // LR8 is a true define, while the rest of the Defs are clobbers. X3 is
  1343. // explicitly defined when this op is created, so not mentioned here.
  1344. // This is lowered to BL8_NOP_TLS by the assembly printer, so the size must be
  1345. // correct because the branch select pass is relying on it.
  1346. let Defs = [X0,X4,X5,X6,X7,X8,X9,X10,X11,X12,LR8,CTR8,CR0,CR1,CR5,CR6,CR7], Size = 8 in
  1347. def GETtlsADDR : GETtlsADDRPseudo <"#GETtlsADDR">;
  1348. let Defs = [X0,X2,X4,X5,X6,X7,X8,X9,X10,X11,X12,LR8,CTR8,CR0,CR1,CR5,CR6,CR7], Size = 8 in
  1349. def GETtlsADDRPCREL : GETtlsADDRPseudo <"#GETtlsADDRPCREL">;
  1350. // LR8 is a true define, while the rest of the Defs are clobbers. X3 is
  1351. // explicitly defined when this op is created, so not mentioned here.
  1352. let Defs = [X0,X4,X5,X6,X7,X8,X9,X10,X11,X12,LR8,CTR8,CR0,CR1,CR5,CR6,CR7] in
  1353. def GETtlsldADDR : GETtlsldADDRPseudo <"#GETtlsldADDR">;
  1354. let Defs = [X0,X2,X4,X5,X6,X7,X8,X9,X10,X11,X12,LR8,CTR8,CR0,CR1,CR5,CR6,CR7] in
  1355. def GETtlsldADDRPCREL : GETtlsldADDRPseudo <"#GETtlsldADDRPCREL">;
  1356. // On AIX, the call to __tls_get_addr needs two inputs in X3/X4 for the
  1357. // offset and region handle respectively. The call is not followed by a nop
  1358. // so we don't need to mark it with a size of 8 bytes. Finally, the assembly
  1359. // manual mentions this exact set of registers as the clobbered set, others
  1360. // are guaranteed not to be clobbered.
  1361. let Defs = [X0,X4,X5,X11,LR8,CR0] in
  1362. def GETtlsADDR64AIX :
  1363. PPCEmitTimePseudo<(outs g8rc:$rD),(ins g8rc:$offset, g8rc:$handle),
  1364. "GETtlsADDR64AIX",
  1365. [(set i64:$rD,
  1366. (PPCgetTlsAddr i64:$offset, i64:$handle))]>, isPPC64;
  1367. }
  1368. // Combined op for ADDItlsgdL and GETtlsADDR, late expanded. X3 and LR8
  1369. // are true defines while the rest of the Defs are clobbers.
  1370. let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1,
  1371. Defs = [X0,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,LR8,CTR8,CR0,CR1,CR5,CR6,CR7]
  1372. in
  1373. def ADDItlsgdLADDR : PPCEmitTimePseudo<(outs g8rc:$rD),
  1374. (ins g8rc_nox0:$reg, s16imm64:$disp, tlsgd:$sym),
  1375. "#ADDItlsgdLADDR",
  1376. [(set i64:$rD,
  1377. (PPCaddiTlsgdLAddr i64:$reg,
  1378. tglobaltlsaddr:$disp,
  1379. tglobaltlsaddr:$sym))]>,
  1380. isPPC64;
  1381. def ADDIStlsldHA: PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
  1382. "#ADDIStlsldHA",
  1383. [(set i64:$rD,
  1384. (PPCaddisTlsldHA i64:$reg, tglobaltlsaddr:$disp))]>,
  1385. isPPC64;
  1386. def ADDItlsldL : PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
  1387. "#ADDItlsldL",
  1388. [(set i64:$rD,
  1389. (PPCaddiTlsldL i64:$reg, tglobaltlsaddr:$disp))]>,
  1390. isPPC64;
  1391. // This pseudo is expanded to two copies to put the variable offset in R4 and
  1392. // the region handle in R3 and GETtlsADDR64AIX.
  1393. def TLSGDAIX8 :
  1394. PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc:$offset, g8rc:$handle),
  1395. "#TLSGDAIX8",
  1396. [(set i64:$rD,
  1397. (PPCTlsgdAIX i64:$offset, i64:$handle))]>;
  1398. // Combined op for ADDItlsldL and GETtlsADDR, late expanded. X3 and LR8
  1399. // are true defines, while the rest of the Defs are clobbers.
  1400. let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1,
  1401. Defs = [X0,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,LR8,CTR8,CR0,CR1,CR5,CR6,CR7]
  1402. in
  1403. def ADDItlsldLADDR : PPCEmitTimePseudo<(outs g8rc:$rD),
  1404. (ins g8rc_nox0:$reg, s16imm64:$disp, tlsgd:$sym),
  1405. "#ADDItlsldLADDR",
  1406. [(set i64:$rD,
  1407. (PPCaddiTlsldLAddr i64:$reg,
  1408. tglobaltlsaddr:$disp,
  1409. tglobaltlsaddr:$sym))]>,
  1410. isPPC64;
  1411. def ADDISdtprelHA: PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
  1412. "#ADDISdtprelHA",
  1413. [(set i64:$rD,
  1414. (PPCaddisDtprelHA i64:$reg,
  1415. tglobaltlsaddr:$disp))]>,
  1416. isPPC64;
  1417. def ADDIdtprelL : PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
  1418. "#ADDIdtprelL",
  1419. [(set i64:$rD,
  1420. (PPCaddiDtprelL i64:$reg, tglobaltlsaddr:$disp))]>,
  1421. isPPC64;
  1422. def PADDIdtprel : PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
  1423. "#PADDIdtprel",
  1424. [(set i64:$rD,
  1425. (PPCpaddiDtprel i64:$reg, tglobaltlsaddr:$disp))]>,
  1426. isPPC64;
  1427. let PPC970_Unit = 2 in {
  1428. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  1429. // Truncating stores.
  1430. def STB8 : DForm_1<38, (outs), (ins g8rc:$rS, memri:$src),
  1431. "stb $rS, $src", IIC_LdStStore,
  1432. [(truncstorei8 i64:$rS, DForm:$src)]>;
  1433. def STH8 : DForm_1<44, (outs), (ins g8rc:$rS, memri:$src),
  1434. "sth $rS, $src", IIC_LdStStore,
  1435. [(truncstorei16 i64:$rS, DForm:$src)]>;
  1436. def STW8 : DForm_1<36, (outs), (ins g8rc:$rS, memri:$src),
  1437. "stw $rS, $src", IIC_LdStStore,
  1438. [(truncstorei32 i64:$rS, DForm:$src)]>;
  1439. def STBX8 : XForm_8_memOp<31, 215, (outs), (ins g8rc:$rS, memrr:$dst),
  1440. "stbx $rS, $dst", IIC_LdStStore,
  1441. [(truncstorei8 i64:$rS, XForm:$dst)]>,
  1442. PPC970_DGroup_Cracked;
  1443. def STHX8 : XForm_8_memOp<31, 407, (outs), (ins g8rc:$rS, memrr:$dst),
  1444. "sthx $rS, $dst", IIC_LdStStore,
  1445. [(truncstorei16 i64:$rS, XForm:$dst)]>,
  1446. PPC970_DGroup_Cracked;
  1447. def STWX8 : XForm_8_memOp<31, 151, (outs), (ins g8rc:$rS, memrr:$dst),
  1448. "stwx $rS, $dst", IIC_LdStStore,
  1449. [(truncstorei32 i64:$rS, XForm:$dst)]>,
  1450. PPC970_DGroup_Cracked;
  1451. } // Interpretation64Bit
  1452. // Normal 8-byte stores.
  1453. def STD : DSForm_1<62, 0, (outs), (ins g8rc:$rS, memrix:$dst),
  1454. "std $rS, $dst", IIC_LdStSTD,
  1455. [(store i64:$rS, DSForm:$dst)]>, isPPC64;
  1456. def STDX : XForm_8_memOp<31, 149, (outs), (ins g8rc:$rS, memrr:$dst),
  1457. "stdx $rS, $dst", IIC_LdStSTD,
  1458. [(store i64:$rS, XForm:$dst)]>, isPPC64,
  1459. PPC970_DGroup_Cracked;
  1460. let Predicates = [IsISA2_06] in {
  1461. def STDBRX: XForm_8_memOp<31, 660, (outs), (ins g8rc:$rS, memrr:$dst),
  1462. "stdbrx $rS, $dst", IIC_LdStStore,
  1463. [(PPCstbrx i64:$rS, ForceXForm:$dst, i64)]>, isPPC64,
  1464. PPC970_DGroup_Cracked;
  1465. }
  1466. let mayStore = 1, hasNoSchedulingInfo = 1 in {
  1467. // Normal 16-byte stores.
  1468. // TODO: Add scheduling info.
  1469. def STQ : DSForm_1<62, 2, (outs), (ins g8prc:$RSp, memrix:$dst),
  1470. "stq $RSp, $dst", IIC_LdStSTQ,
  1471. []>, isPPC64;
  1472. def STQX_PSEUDO : PPCCustomInserterPseudo<(outs),
  1473. (ins g8prc:$RSp, memrr:$dst),
  1474. "#STQX_PSEUDO", []>;
  1475. def SPILL_QUADWORD : PPCEmitTimePseudo<(outs), (ins g8prc:$RSp, memrix:$dst),
  1476. "#SPILL_QUADWORD", []>;
  1477. }
  1478. }
  1479. def BUILD_QUADWORD : PPCPostRAExpPseudo<
  1480. (outs g8prc:$RTp),
  1481. (ins g8rc:$lo, g8rc:$hi),
  1482. "#BUILD_QUADWORD", []>;
  1483. def : Pat<(int_ppc_atomic_store_i128 i64:$lo, i64:$hi, DSForm:$dst),
  1484. (STQ (BUILD_QUADWORD g8rc:$lo, g8rc:$hi), memrix:$dst)>;
  1485. def : Pat<(int_ppc_atomic_store_i128 i64:$lo, i64:$hi, ForceXForm:$dst),
  1486. (STQX_PSEUDO (BUILD_QUADWORD g8rc:$lo, g8rc:$hi), memrr:$dst)>;
  1487. // Stores with Update (pre-inc).
  1488. let PPC970_Unit = 2, mayStore = 1, mayLoad = 0 in {
  1489. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  1490. def STBU8 : DForm_1<39, (outs ptr_rc_nor0:$ea_res), (ins g8rc:$rS, memri:$dst),
  1491. "stbu $rS, $dst", IIC_LdStSTU, []>,
  1492. RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
  1493. def STHU8 : DForm_1<45, (outs ptr_rc_nor0:$ea_res), (ins g8rc:$rS, memri:$dst),
  1494. "sthu $rS, $dst", IIC_LdStSTU, []>,
  1495. RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
  1496. def STWU8 : DForm_1<37, (outs ptr_rc_nor0:$ea_res), (ins g8rc:$rS, memri:$dst),
  1497. "stwu $rS, $dst", IIC_LdStSTU, []>,
  1498. RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
  1499. def STBUX8: XForm_8_memOp<31, 247, (outs ptr_rc_nor0:$ea_res),
  1500. (ins g8rc:$rS, memrr:$dst),
  1501. "stbux $rS, $dst", IIC_LdStSTUX, []>,
  1502. RegConstraint<"$dst.ptrreg = $ea_res">,
  1503. NoEncode<"$ea_res">,
  1504. PPC970_DGroup_Cracked;
  1505. def STHUX8: XForm_8_memOp<31, 439, (outs ptr_rc_nor0:$ea_res),
  1506. (ins g8rc:$rS, memrr:$dst),
  1507. "sthux $rS, $dst", IIC_LdStSTUX, []>,
  1508. RegConstraint<"$dst.ptrreg = $ea_res">,
  1509. NoEncode<"$ea_res">,
  1510. PPC970_DGroup_Cracked;
  1511. def STWUX8: XForm_8_memOp<31, 183, (outs ptr_rc_nor0:$ea_res),
  1512. (ins g8rc:$rS, memrr:$dst),
  1513. "stwux $rS, $dst", IIC_LdStSTUX, []>,
  1514. RegConstraint<"$dst.ptrreg = $ea_res">,
  1515. NoEncode<"$ea_res">,
  1516. PPC970_DGroup_Cracked;
  1517. } // Interpretation64Bit
  1518. def STDU : DSForm_1<62, 1, (outs ptr_rc_nor0:$ea_res),
  1519. (ins g8rc:$rS, memrix:$dst),
  1520. "stdu $rS, $dst", IIC_LdStSTU, []>,
  1521. RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">,
  1522. isPPC64;
  1523. def STDUX : XForm_8_memOp<31, 181, (outs ptr_rc_nor0:$ea_res),
  1524. (ins g8rc:$rS, memrr:$dst),
  1525. "stdux $rS, $dst", IIC_LdStSTUX, []>,
  1526. RegConstraint<"$dst.ptrreg = $ea_res">,
  1527. NoEncode<"$ea_res">,
  1528. PPC970_DGroup_Cracked, isPPC64;
  1529. }
  1530. // Patterns to match the pre-inc stores. We can't put the patterns on
  1531. // the instruction definitions directly as ISel wants the address base
  1532. // and offset to be separate operands, not a single complex operand.
  1533. def : Pat<(pre_truncsti8 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
  1534. (STBU8 $rS, iaddroff:$ptroff, $ptrreg)>;
  1535. def : Pat<(pre_truncsti16 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
  1536. (STHU8 $rS, iaddroff:$ptroff, $ptrreg)>;
  1537. def : Pat<(pre_truncsti32 i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
  1538. (STWU8 $rS, iaddroff:$ptroff, $ptrreg)>;
  1539. def : Pat<(DSFormPreStore i64:$rS, iPTR:$ptrreg, iaddroff:$ptroff),
  1540. (STDU $rS, iaddroff:$ptroff, $ptrreg)>;
  1541. def : Pat<(pre_truncsti8 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
  1542. (STBUX8 $rS, $ptrreg, $ptroff)>;
  1543. def : Pat<(pre_truncsti16 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
  1544. (STHUX8 $rS, $ptrreg, $ptroff)>;
  1545. def : Pat<(pre_truncsti32 i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
  1546. (STWUX8 $rS, $ptrreg, $ptroff)>;
  1547. def : Pat<(pre_store i64:$rS, iPTR:$ptrreg, iPTR:$ptroff),
  1548. (STDUX $rS, $ptrreg, $ptroff)>;
  1549. //===----------------------------------------------------------------------===//
  1550. // Floating point instructions.
  1551. //
  1552. let PPC970_Unit = 3, hasSideEffects = 0, mayRaiseFPException = 1,
  1553. Uses = [RM] in { // FPU Operations.
  1554. defm FCFID : XForm_26r<63, 846, (outs f8rc:$frD), (ins f8rc:$frB),
  1555. "fcfid", "$frD, $frB", IIC_FPGeneral,
  1556. [(set f64:$frD, (PPCany_fcfid f64:$frB))]>, isPPC64;
  1557. defm FCTID : XForm_26r<63, 814, (outs f8rc:$frD), (ins f8rc:$frB),
  1558. "fctid", "$frD, $frB", IIC_FPGeneral,
  1559. []>, isPPC64;
  1560. defm FCTIDU : XForm_26r<63, 942, (outs f8rc:$frD), (ins f8rc:$frB),
  1561. "fctidu", "$frD, $frB", IIC_FPGeneral,
  1562. []>, isPPC64;
  1563. defm FCTIDZ : XForm_26r<63, 815, (outs f8rc:$frD), (ins f8rc:$frB),
  1564. "fctidz", "$frD, $frB", IIC_FPGeneral,
  1565. [(set f64:$frD, (PPCany_fctidz f64:$frB))]>, isPPC64;
  1566. defm FCFIDU : XForm_26r<63, 974, (outs f8rc:$frD), (ins f8rc:$frB),
  1567. "fcfidu", "$frD, $frB", IIC_FPGeneral,
  1568. [(set f64:$frD, (PPCany_fcfidu f64:$frB))]>, isPPC64;
  1569. defm FCFIDS : XForm_26r<59, 846, (outs f4rc:$frD), (ins f8rc:$frB),
  1570. "fcfids", "$frD, $frB", IIC_FPGeneral,
  1571. [(set f32:$frD, (PPCany_fcfids f64:$frB))]>, isPPC64;
  1572. defm FCFIDUS : XForm_26r<59, 974, (outs f4rc:$frD), (ins f8rc:$frB),
  1573. "fcfidus", "$frD, $frB", IIC_FPGeneral,
  1574. [(set f32:$frD, (PPCany_fcfidus f64:$frB))]>, isPPC64;
  1575. defm FCTIDUZ : XForm_26r<63, 943, (outs f8rc:$frD), (ins f8rc:$frB),
  1576. "fctiduz", "$frD, $frB", IIC_FPGeneral,
  1577. [(set f64:$frD, (PPCany_fctiduz f64:$frB))]>, isPPC64;
  1578. defm FCTIWUZ : XForm_26r<63, 143, (outs f8rc:$frD), (ins f8rc:$frB),
  1579. "fctiwuz", "$frD, $frB", IIC_FPGeneral,
  1580. [(set f64:$frD, (PPCany_fctiwuz f64:$frB))]>, isPPC64;
  1581. }
  1582. // These instructions store a hash computed from the value of the link register
  1583. // and the value of the stack pointer.
  1584. let mayStore = 1, Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  1585. def HASHST8 : XForm_XD6_RA5_RB5<31, 722, (outs),
  1586. (ins g8rc:$RB, memrihash:$D_RA_XD),
  1587. "hashst $RB, $D_RA_XD", IIC_IntGeneral, []>;
  1588. def HASHSTP8 : XForm_XD6_RA5_RB5<31, 658, (outs),
  1589. (ins g8rc:$RB, memrihash:$D_RA_XD),
  1590. "hashstp $RB, $D_RA_XD", IIC_IntGeneral, []>;
  1591. }
  1592. // These instructions check a hash computed from the value of the link register
  1593. // and the value of the stack pointer. The hasSideEffects flag is needed as the
  1594. // instruction may TRAP if the hash does not match the hash stored at the
  1595. // specified address.
  1596. let mayLoad = 1, hasSideEffects = 1,
  1597. Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  1598. def HASHCHK8 : XForm_XD6_RA5_RB5<31, 754, (outs),
  1599. (ins g8rc:$RB, memrihash:$D_RA_XD),
  1600. "hashchk $RB, $D_RA_XD", IIC_IntGeneral, []>;
  1601. def HASHCHKP8 : XForm_XD6_RA5_RB5<31, 690, (outs),
  1602. (ins g8rc:$RB, memrihash:$D_RA_XD),
  1603. "hashchkp $RB, $D_RA_XD", IIC_IntGeneral, []>;
  1604. }
  1605. let Interpretation64Bit = 1, isCodeGenOnly = 1, hasSideEffects = 1 in
  1606. def ADDEX8 : Z23Form_RTAB5_CY2<31, 170, (outs g8rc:$rT),
  1607. (ins g8rc:$rA, g8rc:$rB, u2imm:$CY),
  1608. "addex $rT, $rA, $rB, $CY", IIC_IntGeneral,
  1609. [(set i64:$rT, (int_ppc_addex i64:$rA, i64:$rB,
  1610. timm:$CY))]>;
  1611. //===----------------------------------------------------------------------===//
  1612. // Instruction Patterns
  1613. //
  1614. // Extensions and truncates to/from 32-bit regs.
  1615. def : Pat<(i64 (zext i32:$in)),
  1616. (RLDICL (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $in, sub_32),
  1617. 0, 32)>;
  1618. def : Pat<(i64 (anyext i32:$in)),
  1619. (INSERT_SUBREG (i64 (IMPLICIT_DEF)), $in, sub_32)>;
  1620. def : Pat<(i32 (trunc i64:$in)),
  1621. (EXTRACT_SUBREG $in, sub_32)>;
  1622. // Implement the 'not' operation with the NOR instruction.
  1623. // (we could use the default xori pattern, but nor has lower latency on some
  1624. // cores (such as the A2)).
  1625. def i64not : OutPatFrag<(ops node:$in),
  1626. (NOR8 $in, $in)>;
  1627. def : Pat<(not i64:$in),
  1628. (i64not $in)>;
  1629. // Extending loads with i64 targets.
  1630. def : Pat<(zextloadi1 DForm:$src),
  1631. (LBZ8 DForm:$src)>;
  1632. def : Pat<(zextloadi1 XForm:$src),
  1633. (LBZX8 XForm:$src)>;
  1634. def : Pat<(extloadi1 DForm:$src),
  1635. (LBZ8 DForm:$src)>;
  1636. def : Pat<(extloadi1 XForm:$src),
  1637. (LBZX8 XForm:$src)>;
  1638. def : Pat<(extloadi8 DForm:$src),
  1639. (LBZ8 DForm:$src)>;
  1640. def : Pat<(extloadi8 XForm:$src),
  1641. (LBZX8 XForm:$src)>;
  1642. def : Pat<(extloadi16 DForm:$src),
  1643. (LHZ8 DForm:$src)>;
  1644. def : Pat<(extloadi16 XForm:$src),
  1645. (LHZX8 XForm:$src)>;
  1646. def : Pat<(extloadi32 DForm:$src),
  1647. (LWZ8 DForm:$src)>;
  1648. def : Pat<(extloadi32 XForm:$src),
  1649. (LWZX8 XForm:$src)>;
  1650. // Standard shifts. These are represented separately from the real shifts above
  1651. // so that we can distinguish between shifts that allow 6-bit and 7-bit shift
  1652. // amounts.
  1653. def : Pat<(sra i64:$rS, i32:$rB),
  1654. (SRAD $rS, $rB)>;
  1655. def : Pat<(srl i64:$rS, i32:$rB),
  1656. (SRD $rS, $rB)>;
  1657. def : Pat<(shl i64:$rS, i32:$rB),
  1658. (SLD $rS, $rB)>;
  1659. // SUBFIC
  1660. def : Pat<(sub imm64SExt16:$imm, i64:$in),
  1661. (SUBFIC8 $in, imm:$imm)>;
  1662. // SHL/SRL
  1663. def : Pat<(shl i64:$in, (i32 imm:$imm)),
  1664. (RLDICR $in, imm:$imm, (SHL64 imm:$imm))>;
  1665. def : Pat<(srl i64:$in, (i32 imm:$imm)),
  1666. (RLDICL $in, (SRL64 imm:$imm), imm:$imm)>;
  1667. // ROTL
  1668. def : Pat<(rotl i64:$in, i32:$sh),
  1669. (RLDCL $in, $sh, 0)>;
  1670. def : Pat<(rotl i64:$in, (i32 imm:$imm)),
  1671. (RLDICL $in, imm:$imm, 0)>;
  1672. // Hi and Lo for Darwin Global Addresses.
  1673. def : Pat<(PPChi tglobaladdr:$in, 0), (LIS8 tglobaladdr:$in)>;
  1674. def : Pat<(PPClo tglobaladdr:$in, 0), (LI8 tglobaladdr:$in)>;
  1675. def : Pat<(PPChi tconstpool:$in , 0), (LIS8 tconstpool:$in)>;
  1676. def : Pat<(PPClo tconstpool:$in , 0), (LI8 tconstpool:$in)>;
  1677. def : Pat<(PPChi tjumptable:$in , 0), (LIS8 tjumptable:$in)>;
  1678. def : Pat<(PPClo tjumptable:$in , 0), (LI8 tjumptable:$in)>;
  1679. def : Pat<(PPChi tblockaddress:$in, 0), (LIS8 tblockaddress:$in)>;
  1680. def : Pat<(PPClo tblockaddress:$in, 0), (LI8 tblockaddress:$in)>;
  1681. def : Pat<(PPChi tglobaltlsaddr:$g, i64:$in),
  1682. (ADDIS8 $in, tglobaltlsaddr:$g)>;
  1683. def : Pat<(PPClo tglobaltlsaddr:$g, i64:$in),
  1684. (ADDI8 $in, tglobaltlsaddr:$g)>;
  1685. def : Pat<(add i64:$in, (PPChi tglobaladdr:$g, 0)),
  1686. (ADDIS8 $in, tglobaladdr:$g)>;
  1687. def : Pat<(add i64:$in, (PPChi tconstpool:$g, 0)),
  1688. (ADDIS8 $in, tconstpool:$g)>;
  1689. def : Pat<(add i64:$in, (PPChi tjumptable:$g, 0)),
  1690. (ADDIS8 $in, tjumptable:$g)>;
  1691. def : Pat<(add i64:$in, (PPChi tblockaddress:$g, 0)),
  1692. (ADDIS8 $in, tblockaddress:$g)>;
  1693. // AIX 64-bit small code model TLS access.
  1694. def : Pat<(i64 (PPCtoc_entry tglobaltlsaddr:$disp, i64:$reg)),
  1695. (i64 (LDtoc tglobaltlsaddr:$disp, i64:$reg))>;
  1696. // 64-bits atomic loads and stores
  1697. def : Pat<(atomic_load_64 DSForm:$src), (LD memrix:$src)>;
  1698. def : Pat<(atomic_load_64 XForm:$src), (LDX memrr:$src)>;
  1699. def : Pat<(atomic_store_64 DSForm:$ptr, i64:$val), (STD g8rc:$val, memrix:$ptr)>;
  1700. def : Pat<(atomic_store_64 XForm:$ptr, i64:$val), (STDX g8rc:$val, memrr:$ptr)>;
  1701. let Predicates = [IsISA3_0, In64BitMode] in {
  1702. def : Pat<(i64 (int_ppc_cmpeqb g8rc:$a, g8rc:$b)),
  1703. (i64 (SETB8 (CMPEQB $a, $b)))>;
  1704. def : Pat<(i64 (int_ppc_setb g8rc:$a, g8rc:$b)),
  1705. (i64 (SETB8 (CMPD $a, $b)))>;
  1706. def : Pat<(i64 (int_ppc_maddhd g8rc:$a, g8rc:$b, g8rc:$c)),
  1707. (i64 (MADDHD $a, $b, $c))>;
  1708. def : Pat<(i64 (int_ppc_maddhdu g8rc:$a, g8rc:$b, g8rc:$c)),
  1709. (i64 (MADDHDU $a, $b, $c))>;
  1710. def : Pat<(i64 (int_ppc_maddld g8rc:$a, g8rc:$b, g8rc:$c)),
  1711. (i64 (MADDLD8 $a, $b, $c))>;
  1712. }
  1713. let Predicates = [In64BitMode] in {
  1714. def : Pat<(i64 (int_ppc_mulhd g8rc:$a, g8rc:$b)),
  1715. (i64 (MULHD $a, $b))>;
  1716. def : Pat<(i64 (int_ppc_mulhdu g8rc:$a, g8rc:$b)),
  1717. (i64 (MULHDU $a, $b))>;
  1718. def : Pat<(int_ppc_load8r ForceXForm:$ptr),
  1719. (LDBRX ForceXForm:$ptr)>;
  1720. def : Pat<(int_ppc_store8r g8rc:$a, ForceXForm:$ptr),
  1721. (STDBRX g8rc:$a, ForceXForm:$ptr)>;
  1722. }
  1723. def : Pat<(i64 (int_ppc_cmpb g8rc:$a, g8rc:$b)),
  1724. (i64 (CMPB8 $a, $b))>;
  1725. let Predicates = [IsISA3_0] in {
  1726. // DARN (deliver random number)
  1727. // L=0 for 32-bit, L=1 for conditioned random, L=2 for raw random
  1728. def : Pat<(int_ppc_darn32), (EXTRACT_SUBREG (DARN 0), sub_32)>;
  1729. def : Pat<(int_ppc_darn), (DARN 1)>;
  1730. def : Pat<(int_ppc_darnraw), (DARN 2)>;
  1731. class X_RA5_RB5<bits<6> opcode, bits<10> xo, string opc, RegisterOperand ty,
  1732. InstrItinClass itin, list<dag> pattern>
  1733. : X_L1_RS5_RS5<opcode, xo, (outs), (ins ty:$rA, ty:$rB, u1imm:$L),
  1734. !strconcat(opc, " $rA, $rB"), itin, pattern>{
  1735. let L = 1;
  1736. }
  1737. class X_L1_RA5_RB5<bits<6> opcode, bits<10> xo, string opc, RegisterOperand ty,
  1738. InstrItinClass itin, list<dag> pattern>
  1739. : X_L1_RS5_RS5<opcode, xo, (outs), (ins ty:$rA, ty:$rB, u1imm:$L),
  1740. !strconcat(opc, " $rA, $rB, $L"), itin, pattern>;
  1741. let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
  1742. def CP_COPY8 : X_RA5_RB5<31, 774, "copy" , g8rc, IIC_LdStCOPY, []>;
  1743. def CP_PASTE8_rec : X_L1_RA5_RB5<31, 902, "paste.", g8rc, IIC_LdStPASTE, []>,isRecordForm;
  1744. }
  1745. // SLB Invalidate Entry Global
  1746. def SLBIEG : XForm_26<31, 466, (outs), (ins gprc:$RS, gprc:$RB),
  1747. "slbieg $RS, $RB", IIC_SprSLBIEG, []>;
  1748. // SLB Synchronize
  1749. def SLBSYNC : XForm_0<31, 338, (outs), (ins), "slbsync", IIC_SprSLBSYNC, []>;
  1750. } // IsISA3_0
  1751. def : Pat<(int_ppc_stdcx ForceXForm:$dst, g8rc:$A),
  1752. (STDCX g8rc:$A, ForceXForm:$dst)>;
  1753. def : Pat<(PPCStoreCond ForceXForm:$dst, g8rc:$A, 8),
  1754. (STDCX g8rc:$A, ForceXForm:$dst)>;
  1755. def : Pat<(i64 (int_ppc_mfspr timm:$SPR)),
  1756. (MFSPR8 $SPR)>;
  1757. def : Pat<(int_ppc_mtspr timm:$SPR, g8rc:$RT),
  1758. (MTSPR8 $SPR, $RT)>;