1 //===-- AVRInstrInfo.td - AVR Instruction defs -------------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the AVR instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 include "AVRInstrFormats.td"
16 //===----------------------------------------------------------------------===//
18 //===----------------------------------------------------------------------===//
20 def SDT_AVRCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i16>]>;
21 def SDT_AVRCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
22 def SDT_AVRCall : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
23 def SDT_AVRWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
24 def SDT_AVRBrcond : SDTypeProfile<0, 2,
25 [SDTCisVT<0, OtherVT>, SDTCisVT<1, i8>]>;
26 def SDT_AVRCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
27 def SDT_AVRTst : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
28 def SDT_AVRSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
29 SDTCisSameAs<1, 2>, SDTCisVT<3, i8>]>;
31 //===----------------------------------------------------------------------===//
32 // AVR Specific Node Definitions
33 //===----------------------------------------------------------------------===//
35 def AVRretflag : SDNode<"AVRISD::RET_FLAG", SDTNone,
36 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
37 def AVRretiflag : SDNode<"AVRISD::RETI_FLAG", SDTNone,
38 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
40 def AVRcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_AVRCallSeqStart,
41 [SDNPHasChain, SDNPOutGlue]>;
42 def AVRcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_AVRCallSeqEnd,
43 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
45 def AVRcall : SDNode<"AVRISD::CALL", SDT_AVRCall,
46 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
48 def AVRWrapper : SDNode<"AVRISD::WRAPPER", SDT_AVRWrapper>;
50 def AVRbrcond : SDNode<"AVRISD::BRCOND", SDT_AVRBrcond,
51 [SDNPHasChain, SDNPInGlue]>;
52 def AVRcmp : SDNode<"AVRISD::CMP", SDT_AVRCmp, [SDNPOutGlue]>;
53 def AVRcmpc : SDNode<"AVRISD::CMPC", SDT_AVRCmp, [SDNPInGlue, SDNPOutGlue]>;
54 def AVRtst : SDNode<"AVRISD::TST", SDT_AVRTst, [SDNPOutGlue]>;
55 def AVRselectcc: SDNode<"AVRISD::SELECT_CC", SDT_AVRSelectCC, [SDNPInGlue]>;
58 def AVRlsl : SDNode<"AVRISD::LSL", SDTIntUnaryOp>;
59 def AVRlsr : SDNode<"AVRISD::LSR", SDTIntUnaryOp>;
60 def AVRrol : SDNode<"AVRISD::ROL", SDTIntUnaryOp>;
61 def AVRror : SDNode<"AVRISD::ROR", SDTIntUnaryOp>;
62 def AVRasr : SDNode<"AVRISD::ASR", SDTIntUnaryOp>;
64 // Pseudo shift nodes for non-constant shift amounts.
65 def AVRlslLoop : SDNode<"AVRISD::LSLLOOP", SDTIntShiftOp>;
66 def AVRlsrLoop : SDNode<"AVRISD::LSRLOOP", SDTIntShiftOp>;
67 def AVRasrLoop : SDNode<"AVRISD::ASRLOOP", SDTIntShiftOp>;
69 //===----------------------------------------------------------------------===//
70 // AVR Operands, Complex Patterns and Transformations Definitions.
71 //===----------------------------------------------------------------------===//
73 def imm8_neg_XFORM : SDNodeXForm<imm,
75 return CurDAG->getTargetConstant(-N->getAPIntValue(), SDLoc(N), MVT::i8);
78 def imm16_neg_XFORM : SDNodeXForm<imm,
80 return CurDAG->getTargetConstant(-N->getAPIntValue(), SDLoc(N), MVT::i16);
83 def imm0_63_neg : PatLeaf<(imm),
85 int64_t val = -N->getSExtValue();
86 return val >= 0 && val < 64;
89 def uimm6 : PatLeaf<(imm), [{ return isUInt<6>(N->getZExtValue()); }]>;
91 def ioaddr_XFORM : SDNodeXForm<imm,
93 return CurDAG->getTargetConstant(uint8_t(N->getZExtValue()) - 0x20, SDLoc(N), MVT::i8);
96 def iobitpos8_XFORM : SDNodeXForm<imm,
98 return CurDAG->getTargetConstant(Log2_32(uint8_t(N->getZExtValue())),
102 def iobitposn8_XFORM : SDNodeXForm<imm,
104 return CurDAG->getTargetConstant(Log2_32(uint8_t(~N->getZExtValue())),
108 def ioaddr8 : PatLeaf<(imm),
110 uint64_t val = N->getZExtValue();
111 return val >= 0x20 && val < 0x60;
114 def lowioaddr8 : PatLeaf<(imm),
116 uint64_t val = N->getZExtValue();
117 return val >= 0x20 && val < 0x40;
120 def ioaddr16 : PatLeaf<(imm),
122 uint64_t val = N->getZExtValue();
123 return val >= 0x20 && val < 0x5f;
126 def iobitpos8 : PatLeaf<(imm),
128 return isPowerOf2_32(uint8_t(N->getZExtValue()));
129 }], iobitpos8_XFORM>;
131 def iobitposn8 : PatLeaf<(imm),
133 return isPowerOf2_32(uint8_t(~N->getZExtValue()));
134 }], iobitposn8_XFORM>;
136 def MemriAsmOperand : AsmOperandClass {
138 let ParserMethod = "parseMemriOperand";
141 /// Address operand for `reg+imm` used by STD and LDD.
142 def memri : Operand<iPTR>
144 let MIOperandInfo = (ops PTRDISPREGS, i16imm);
146 let PrintMethod = "printMemri";
147 let EncoderMethod = "encodeMemri";
149 let ParserMatchClass = MemriAsmOperand;
152 // Address operand for `SP+imm` used by STD{W}SPQRr
153 def memspi : Operand<iPTR>
155 let MIOperandInfo = (ops GPRSP, i16imm);
158 def i8imm_com : Operand<i8>
160 let EncoderMethod = "encodeComplement";
162 let MIOperandInfo = (ops i8imm);
165 def relbrtarget_7 : Operand<OtherVT>
167 let PrintMethod = "printPCRelImm";
168 let EncoderMethod = "encodeRelCondBrTarget<AVR::fixup_7_pcrel>";
171 def brtarget_13 : Operand<OtherVT>
173 let PrintMethod = "printPCRelImm";
174 let EncoderMethod = "encodeRelCondBrTarget<AVR::fixup_13_pcrel>";
177 // The target of a 22 or 16-bit call/jmp instruction.
178 def call_target : Operand<iPTR>
180 let EncoderMethod = "encodeCallTarget";
183 // Addressing mode pattern reg+imm6
184 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [], [SDNPWantRoot]>;
186 // AsmOperand class for a pointer register.
187 // Used with the LD/ST family of instructions.
188 // See FSTLD in AVRInstrFormats.td
189 def PtrRegAsmOperand : AsmOperandClass
194 // A special operand type for the LD/ST instructions.
195 // It converts the pointer register number into a two-bit field used in the
197 def LDSTPtrReg : Operand<i16>
199 let MIOperandInfo = (ops PTRREGS);
200 let EncoderMethod = "encodeLDSTPtrReg";
202 let ParserMatchClass = PtrRegAsmOperand;
205 // A special operand type for the LDD/STD instructions.
206 // It behaves identically to the LD/ST version, except restricts
207 // the pointer registers to Y and Z.
208 def LDDSTDPtrReg : Operand<i16>
210 let MIOperandInfo = (ops PTRDISPREGS);
211 let EncoderMethod = "encodeLDSTPtrReg";
213 let ParserMatchClass = PtrRegAsmOperand;
216 //===----------------------------------------------------------------------===//
217 // AVR predicates for subtarget features
218 //===----------------------------------------------------------------------===//
220 def HasSRAM : Predicate<"Subtarget->hasSRAM()">,
221 AssemblerPredicate<"FeatureSRAM">;
223 def HasJMPCALL : Predicate<"Subtarget->hasJMPCALL()">,
224 AssemblerPredicate<"FeatureJMPCALL">;
226 def HasIJMPCALL : Predicate<"Subtarget->hasIJMPCALL()">,
227 AssemblerPredicate<"FeatureIJMPCALL">;
229 def HasEIJMPCALL : Predicate<"Subtarget->hasEIJMPCALL()">,
230 AssemblerPredicate<"FeatureEIJMPCALL">;
232 def HasADDSUBIW : Predicate<"Subtarget->hasADDSUBIW()">,
233 AssemblerPredicate<"FeatureADDSUBIW">;
235 def HasSmallStack : Predicate<"Subtarget->HasSmallStack()">,
236 AssemblerPredicate<"FeatureSmallStack">;
238 def HasMOVW : Predicate<"Subtarget->hasMOVW()">,
239 AssemblerPredicate<"FeatureMOVW">;
241 def HasLPM : Predicate<"Subtarget->hasLPM()">,
242 AssemblerPredicate<"FeatureLPM">;
244 def HasLPMX : Predicate<"Subtarget->hasLPMX()">,
245 AssemblerPredicate<"FeatureLPMX">;
247 def HasELPM : Predicate<"Subtarget->hasELPM()">,
248 AssemblerPredicate<"FeatureELPM">;
250 def HasELPMX : Predicate<"Subtarget->hasELPMX()">,
251 AssemblerPredicate<"FeatureELPMX">;
253 def HasSPM : Predicate<"Subtarget->hasSPM()">,
254 AssemblerPredicate<"FeatureSPM">;
256 def HasSPMX : Predicate<"Subtarget->hasSPMX()">,
257 AssemblerPredicate<"FeatureSPMX">;
259 def HasDES : Predicate<"Subtarget->hasDES()">,
260 AssemblerPredicate<"FeatureDES">;
262 def SupportsRMW : Predicate<"Subtarget->supportsRMW()">,
263 AssemblerPredicate<"FeatureRMW">;
265 def SupportsMultiplication : Predicate<"Subtarget->supportsMultiplication()">,
266 AssemblerPredicate<"FeatureMultiplication">;
268 def HasBREAK : Predicate<"Subtarget->hasBREAK()">,
269 AssemblerPredicate<"FeatureBREAK">;
271 def HasTinyEncoding : Predicate<"Subtarget->hasTinyEncoding()">,
272 AssemblerPredicate<"FeatureTinyEncoding">;
275 // AVR specific condition code. These correspond to AVR_*_COND in
276 // AVRInstrInfo.td. They must be kept in synch.
277 def AVR_COND_EQ : PatLeaf<(i8 0)>;
278 def AVR_COND_NE : PatLeaf<(i8 1)>;
279 def AVR_COND_GE : PatLeaf<(i8 2)>;
280 def AVR_COND_LT : PatLeaf<(i8 3)>;
281 def AVR_COND_SH : PatLeaf<(i8 4)>;
282 def AVR_COND_LO : PatLeaf<(i8 5)>;
283 def AVR_COND_MI : PatLeaf<(i8 6)>;
284 def AVR_COND_PL : PatLeaf<(i8 7)>;
287 //===----------------------------------------------------------------------===//
288 //===----------------------------------------------------------------------===//
289 // AVR Instruction list
290 //===----------------------------------------------------------------------===//
291 //===----------------------------------------------------------------------===//
293 // ADJCALLSTACKDOWN/UP implicitly use/def SP because they may be expanded into
294 // a stack adjustment and the codegen must know that they may modify the stack
295 // pointer before prolog-epilog rewriting occurs.
296 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
297 // sub / add which can clobber SREG.
298 let Defs = [SP, SREG],
301 def ADJCALLSTACKDOWN : Pseudo<(outs),
304 [(AVRcallseq_start timm:$amt)]>;
306 // R31R30 is used to update SP, since it is a scratch reg and this instruction
307 // is placed after the function call then R31R30 should be always free.
308 //let Defs = [R31R30],
310 //:TODO: if we enable this, the pseudo is killed because it looks dead
311 def ADJCALLSTACKUP : Pseudo<(outs),
312 (ins i16imm:$amt1, i16imm:$amt2),
314 [(AVRcallseq_end timm:$amt1, timm:$amt2)]>;
317 //===----------------------------------------------------------------------===//
319 //===----------------------------------------------------------------------===//
320 let isCommutable = 1,
321 Constraints = "$src = $rd",
325 // Adds two 8-bit registers.
326 def ADDRdRr : FRdRr<0b0000,
329 (ins GPR8:$src, GPR8:$rr),
331 [(set i8:$rd, (add i8:$src, i8:$rr)),
334 // ADDW Rd+1:Rd, Rr+1:Rr
335 // Pseudo instruction to add four 8-bit registers as two 16-bit values.
340 def ADDWRdRr : Pseudo<(outs DREGS:$rd),
341 (ins DREGS:$src, DREGS:$rr),
343 [(set i16:$rd, (add i16:$src, i16:$rr)),
347 // Adds two 8-bit registers with carry.
349 def ADCRdRr : FRdRr<0b0001,
352 (ins GPR8:$src, GPR8:$rr),
354 [(set i8:$rd, (adde i8:$src, i8:$rr)),
357 // ADCW Rd+1:Rd, Rr+1:Rr
358 // Pseudo instruction to add four 8-bit registers as two 16-bit values with
365 def ADCWRdRr : Pseudo<(outs DREGS:$rd),
366 (ins DREGS:$src, DREGS:$rr),
368 [(set i16:$rd, (adde i16:$src, i16:$rr)),
372 // Adds an immediate 6-bit value K to Rd, placing the result in Rd.
373 def ADIWRdK : FWRdK<0b0,
375 (ins IWREGS:$src, i16imm:$k),
377 [(set i16:$rd, (add i16:$src, uimm6:$k)),
379 Requires<[HasADDSUBIW]>;
382 //===----------------------------------------------------------------------===//
384 //===----------------------------------------------------------------------===//
385 let Constraints = "$src = $rd",
389 // Subtracts the 8-bit value of Rr from Rd and places the value in Rd.
390 def SUBRdRr : FRdRr<0b0001,
393 (ins GPR8:$src, GPR8:$rr),
395 [(set i8:$rd, (sub i8:$src, i8:$rr)),
398 // SUBW Rd+1:Rd, Rr+1:Rr
399 // Subtracts two 16-bit values and places the result into Rd.
404 def SUBWRdRr : Pseudo<(outs DREGS:$rd),
405 (ins DREGS:$src, DREGS:$rr),
407 [(set i16:$rd, (sub i16:$src, i16:$rr)),
410 def SUBIRdK : FRdK<0b0101,
412 (ins LD8:$src, i8imm:$k),
414 [(set i8:$rd, (sub i8:$src, imm:$k)),
417 // SUBIW Rd+1:Rd, K+1:K
422 def SUBIWRdK : Pseudo<(outs DLDREGS:$rd),
423 (ins DLDREGS:$src, i16imm:$rr),
425 [(set i16:$rd, (sub i16:$src, imm:$rr)),
428 def SBIWRdK : FWRdK<0b1,
430 (ins IWREGS:$src, i16imm:$k),
432 [(set i16:$rd, (sub i16:$src, uimm6:$k)),
434 Requires<[HasADDSUBIW]>;
436 // Subtract with carry operations which must read the carry flag in SREG.
439 def SBCRdRr : FRdRr<0b0000,
442 (ins GPR8:$src, GPR8:$rr),
444 [(set i8:$rd, (sube i8:$src, i8:$rr)),
447 // SBCW Rd+1:Rd, Rr+1:Rr
452 def SBCWRdRr : Pseudo<(outs DREGS:$rd),
453 (ins DREGS:$src, DREGS:$rr),
455 [(set i16:$rd, (sube i16:$src, i16:$rr)),
458 def SBCIRdK : FRdK<0b0100,
460 (ins LD8:$src, i8imm:$k),
462 [(set i8:$rd, (sube i8:$src, imm:$k)),
465 // SBCIW Rd+1:Rd, K+1:K
468 def SBCIWRdK : Pseudo<(outs DLDREGS:$rd),
469 (ins DLDREGS:$src, i16imm:$rr),
471 [(set i16:$rd, (sube i16:$src, imm:$rr)),
476 //===----------------------------------------------------------------------===//
477 // Increment and Decrement
478 //===----------------------------------------------------------------------===//
479 let Constraints = "$src = $rd",
482 def INCRd : FRd<0b1001,
487 [(set i8:$rd, (add i8:$src, 1)), (implicit SREG)]>;
489 def DECRd : FRd<0b1001,
494 [(set i8:$rd, (add i8:$src, -1)), (implicit SREG)]>;
497 //===----------------------------------------------------------------------===//
499 //===----------------------------------------------------------------------===//
501 let isCommutable = 1,
502 Defs = [R1, R0, SREG] in
505 // Multiplies Rd by Rr and places the result into R1:R0.
506 let usesCustomInserter = 1 in {
507 def MULRdRr : FRdRr<0b1001, 0b11,
509 (ins GPR8:$lhs, GPR8:$rhs),
511 [/*(set R1, R0, (smullohi i8:$lhs, i8:$rhs))*/]>,
512 Requires<[SupportsMultiplication]>;
514 def MULSRdRr : FMUL2RdRr<0,
516 (ins GPR8:$lhs, GPR8:$rhs),
519 Requires<[SupportsMultiplication]>;
522 def MULSURdRr : FMUL2RdRr<1,
524 (ins GPR8:$lhs, GPR8:$rhs),
527 Requires<[SupportsMultiplication]>;
529 def FMUL : FFMULRdRr<0b01,
531 (ins GPR8:$lhs, GPR8:$rhs),
534 Requires<[SupportsMultiplication]>;
536 def FMULS : FFMULRdRr<0b10,
538 (ins GPR8:$lhs, GPR8:$rhs),
541 Requires<[SupportsMultiplication]>;
543 def FMULSU : FFMULRdRr<0b11,
545 (ins GPR8:$lhs, GPR8:$rhs),
546 "fmulsu\t$lhs, $rhs",
548 Requires<[SupportsMultiplication]>;
551 let Defs = [R15, R14, R13, R12, R11, R10, R9,
552 R8, R7, R6, R5, R4, R3, R2, R1, R0] in
553 def DESK : FDES<(outs),
559 //===----------------------------------------------------------------------===//
561 //===----------------------------------------------------------------------===//
562 let Constraints = "$src = $rd",
565 // Register-Register logic instructions (which have the
566 // property of commutativity).
567 let isCommutable = 1 in
569 def ANDRdRr : FRdRr<0b0010,
572 (ins GPR8:$src, GPR8:$rr),
574 [(set i8:$rd, (and i8:$src, i8:$rr)),
577 // ANDW Rd+1:Rd, Rr+1:Rr
582 def ANDWRdRr : Pseudo<(outs DREGS:$rd),
583 (ins DREGS:$src, DREGS:$rr),
585 [(set i16:$rd, (and i16:$src, i16:$rr)),
588 def ORRdRr : FRdRr<0b0010,
591 (ins GPR8:$src, GPR8:$rr),
593 [(set i8:$rd, (or i8:$src, i8:$rr)),
596 // ORW Rd+1:Rd, Rr+1:Rr
601 def ORWRdRr : Pseudo<(outs DREGS:$rd),
602 (ins DREGS:$src, DREGS:$rr),
604 [(set i16:$rd, (or i16:$src, i16:$rr)),
607 def EORRdRr : FRdRr<0b0010,
610 (ins GPR8:$src, GPR8:$rr),
612 [(set i8:$rd, (xor i8:$src, i8:$rr)),
615 // EORW Rd+1:Rd, Rr+1:Rr
620 def EORWRdRr : Pseudo<(outs DREGS:$rd),
621 (ins DREGS:$src, DREGS:$rr),
623 [(set i16:$rd, (xor i16:$src, i16:$rr)),
627 def ANDIRdK : FRdK<0b0111,
629 (ins LD8:$src, i8imm:$k),
631 [(set i8:$rd, (and i8:$src, imm:$k)),
634 // ANDI Rd+1:Rd, K+1:K
639 def ANDIWRdK : Pseudo<(outs DLDREGS:$rd),
640 (ins DLDREGS:$src, i16imm:$k),
642 [(set i16:$rd, (and i16:$src, imm:$k)),
645 def ORIRdK : FRdK<0b0110,
647 (ins LD8:$src, i8imm:$k),
649 [(set i8:$rd, (or i8:$src, imm:$k)),
652 // ORIW Rd+1:Rd, K+1,K
657 def ORIWRdK : Pseudo<(outs DLDREGS:$rd),
658 (ins DLDREGS:$src, i16imm:$rr),
660 [(set i16:$rd, (or i16:$src, imm:$rr)),
664 //===----------------------------------------------------------------------===//
665 // One's/Two's Compliment
666 //===----------------------------------------------------------------------===//
667 let Constraints = "$src = $rd",
670 def COMRd : FRd<0b1001,
675 [(set i8:$rd, (not i8:$src)), (implicit SREG)]>;
682 def COMWRd : Pseudo<(outs DREGS:$rd),
685 [(set i16:$rd, (not i16:$src)), (implicit SREG)]>;
687 //:TODO: optimize NEG for wider types
688 def NEGRd : FRd<0b1001,
693 [(set i8:$rd, (ineg i8:$src)), (implicit SREG)]>;
697 // Test for zero of minus.
698 // This operation is identical to a `Rd AND Rd`.
699 //def : InstAlias<"tst\t$rd", (ANDRdRr GPR8:$rd, GPR8:$rd), 1>;
702 def TSTRd : FTST<0b0010,
709 //===----------------------------------------------------------------------===//
711 //===----------------------------------------------------------------------===//
718 (ins brtarget_13:$target),
722 let isIndirectBranch = 1,
724 def IJMP : F16<0b1001010000001001,
729 Requires<[HasIJMPCALL]>;
731 let isIndirectBranch = 1,
733 def EIJMP : F16<0b1001010000011001,
738 Requires<[HasEIJMPCALL]>;
740 def JMPk : F32BRk<0b110,
742 (ins call_target:$k),
745 Requires<[HasJMPCALL]>;
748 //===----------------------------------------------------------------------===//
750 //===----------------------------------------------------------------------===//
753 // SP is marked as a use to prevent stack-pointer assignments that appear
754 // immediately before calls from potentially appearing dead.
758 (ins brtarget_13:$target),
762 // SP is marked as a use to prevent stack-pointer assignments that appear
763 // immediately before calls from potentially appearing dead.
764 let Uses = [SP, R31R30] in
765 def ICALL : F16<0b1001010100001001,
770 Requires<[HasIJMPCALL]>;
772 // SP is marked as a use to prevent stack-pointer assignments that appear
773 // immediately before calls from potentially appearing dead.
774 let Uses = [SP, R31R30] in
775 def EICALL : F16<0b1001010100011001,
780 Requires<[HasEIJMPCALL]>;
782 // SP is marked as a use to prevent stack-pointer assignments that appear
783 // immediately before calls from potentially appearing dead.
785 //:TODO: the imm field can be either 16 or 22 bits in devices with more
786 // than 64k of ROM, fix it once we support the largest devices.
788 def CALLk : F32BRk<0b111,
790 (ins call_target:$k),
793 Requires<[HasJMPCALL]>;
796 //===----------------------------------------------------------------------===//
797 // Return instructions.
798 //===----------------------------------------------------------------------===//
799 let isTerminator = 1,
803 def RET : F16<0b1001010100001000,
809 def RETI : F16<0b1001010100011000,
816 //===----------------------------------------------------------------------===//
817 // Compare operations.
818 //===----------------------------------------------------------------------===//
822 // Compare Rd and Rr, skipping the next instruction if they are equal.
826 def CPSE : FRdRr<0b0001,
829 (ins GPR8:$rd, GPR8:$rr),
833 def CPRdRr : FRdRr<0b0001,
836 (ins GPR8:$rd, GPR8:$rr),
838 [(AVRcmp i8:$rd, i8:$rr), (implicit SREG)]>;
840 // CPW Rd+1:Rd, Rr+1:Rr
845 def CPWRdRr : Pseudo<(outs),
846 (ins DREGS:$src, DREGS:$src2),
848 [(AVRcmp i16:$src, i16:$src2), (implicit SREG)]>;
851 def CPCRdRr : FRdRr<0b0000,
854 (ins GPR8:$rd, GPR8:$rr),
856 [(AVRcmpc i8:$rd, i8:$rr), (implicit SREG)]>;
858 // CPCW Rd+1:Rd. Rr+1:Rr
864 def CPCWRdRr : Pseudo<(outs),
865 (ins DREGS:$src, DREGS:$src2),
867 [(AVRcmpc i16:$src, i16:$src2), (implicit SREG)]>;
870 // Compares a register with an 8 bit immediate.
872 def CPIRdK : FRdK<0b0011,
874 (ins GPR8:$rd, i8imm:$k),
876 [(AVRcmp i8:$rd, imm:$k), (implicit SREG)]>;
879 //===----------------------------------------------------------------------===//
880 // Register conditional skipping/branching operations.
881 //===----------------------------------------------------------------------===//
885 // Conditional skipping on GPR register bits, and
886 // conditional skipping on IO register bits.
889 def SBRCRrB : FRdB<0b10,
891 (ins GPR8:$rr, i8imm:$b),
895 def SBRSRrB : FRdB<0b11,
897 (ins GPR8:$rr, i8imm:$b),
901 def SBICAb : FIOBIT<0b01,
903 (ins i16imm:$a, i8imm:$b),
907 def SBISAb : FIOBIT<0b11,
909 (ins i16imm:$a, i8imm:$b),
914 // Relative branches on status flag bits.
918 // Branch if `s` flag in status register is set.
921 (ins i8imm:$s, relbrtarget_7:$k),
926 // Branch if `s` flag in status register is clear.
929 (ins i8imm:$s, relbrtarget_7:$k),
937 // Branch if carry flag is set
938 def : InstAlias<"brcs\t$k", (BRBSsk 0, relbrtarget_7:$k)>;
941 // Branch if carry flag is clear
942 def : InstAlias<"brcc\t$k", (BRBCsk 0, relbrtarget_7:$k)>;
945 // Branch if half carry flag is set
946 def : InstAlias<"brhs\t$k", (BRBSsk 5, relbrtarget_7:$k)>;
949 // Branch if half carry flag is clear
950 def : InstAlias<"brhc\t$k", (BRBCsk 5, relbrtarget_7:$k)>;
953 // Branch if the T flag is set
954 def : InstAlias<"brts\t$k", (BRBSsk 6, relbrtarget_7:$k)>;
957 // Branch if the T flag is clear
958 def : InstAlias<"brtc\t$k", (BRBCsk 6, relbrtarget_7:$k)>;
961 // Branch if the overflow flag is set
962 def : InstAlias<"brvs\t$k", (BRBSsk 3, relbrtarget_7:$k)>;
965 // Branch if the overflow flag is clear
966 def : InstAlias<"brvc\t$k", (BRBCsk 3, relbrtarget_7:$k)>;
969 // Branch if the global interrupt flag is enabled
970 def : InstAlias<"brie\t$k", (BRBSsk 7, relbrtarget_7:$k)>;
973 // Branch if the global interrupt flag is disabled
974 def : InstAlias<"brid\t$k", (BRBCsk 7, relbrtarget_7:$k)>;
976 //===----------------------------------------------------------------------===//
977 // PC-relative conditional branches
978 //===----------------------------------------------------------------------===//
979 // Based on status register. We cannot simplify these into instruction aliases
980 // because we also need to be able to specify a pattern to match for ISel.
988 (ins relbrtarget_7:$target),
990 [(AVRbrcond bb:$target, AVR_COND_EQ)]>;
995 (ins relbrtarget_7:$target),
997 [(AVRbrcond bb:$target, AVR_COND_NE)]>;
1000 def BRSHk : FBRsk<1,
1003 (ins relbrtarget_7:$target),
1005 [(AVRbrcond bb:$target, AVR_COND_SH)]>;
1007 def BRLOk : FBRsk<0,
1010 (ins relbrtarget_7:$target),
1012 [(AVRbrcond bb:$target, AVR_COND_LO)]>;
1014 def BRMIk : FBRsk<0,
1017 (ins relbrtarget_7:$target),
1019 [(AVRbrcond bb:$target, AVR_COND_MI)]>;
1021 def BRPLk : FBRsk<1,
1024 (ins relbrtarget_7:$target),
1026 [(AVRbrcond bb:$target, AVR_COND_PL)]>;
1028 def BRGEk : FBRsk<1,
1031 (ins relbrtarget_7:$target),
1033 [(AVRbrcond bb:$target, AVR_COND_GE)]>;
1035 def BRLTk : FBRsk<0,
1038 (ins relbrtarget_7:$target),
1040 [(AVRbrcond bb:$target, AVR_COND_LT)]>;
1043 //===----------------------------------------------------------------------===//
1044 // Data transfer instructions
1045 //===----------------------------------------------------------------------===//
1046 // 8 and 16-bit register move instructions.
1047 let hasSideEffects = 0 in
1049 def MOVRdRr : FRdRr<0b0010,
1056 def MOVWRdRr : FMOVWRdRr<(outs DREGS:$dst),
1060 Requires<[HasMOVW]>;
1063 // Load immediate values into registers.
1064 let isReMaterializable = 1 in
1066 def LDIRdK : FRdK<0b1110,
1070 [(set i8:$rd, imm:$k)]>;
1072 // LDIW Rd+1:Rd, K+1:K
1077 def LDIWRdK : Pseudo<(outs DLDREGS:$dst),
1080 [(set i16:$dst, imm:$src)]>;
1083 // Load from data space into register.
1084 let canFoldAsLoad = 1,
1085 isReMaterializable = 1 in
1087 def LDSRdK : F32DM<0b0,
1091 [(set i8:$rd, (load imm:$k))]>,
1092 Requires<[HasSRAM]>;
1094 // LDSW Rd+1:Rd, K+1:K
1098 // lds Rd+1 (K+1:K) + 1
1099 def LDSWRdK : Pseudo<(outs DREGS:$dst),
1102 [(set i16:$dst, (load imm:$src))]>,
1103 Requires<[HasSRAM]>;
1107 let canFoldAsLoad = 1,
1108 isReMaterializable = 1 in
1110 def LDRdPtr : FSTLD<0,
1113 (ins LDSTPtrReg:$ptrreg),
1114 "ld\t$reg, $ptrreg",
1115 [(set GPR8:$reg, (load i16:$ptrreg))]>,
1116 Requires<[HasSRAM]>;
1123 let Constraints = "@earlyclobber $reg" in
1124 def LDWRdPtr : Pseudo<(outs DREGS:$reg),
1125 (ins PTRDISPREGS:$ptrreg),
1126 "ldw\t$reg, $ptrreg",
1127 [(set i16:$reg, (load i16:$ptrreg))]>,
1128 Requires<[HasSRAM]>;
1131 // Indirect loads (with postincrement or predecrement).
1134 Constraints = "$ptrreg = $base_wb,@earlyclobber $reg,@earlyclobber $base_wb" in
1136 def LDRdPtrPi : FSTLD<0,
1138 (outs GPR8:$reg, PTRREGS:$base_wb),
1139 (ins LDSTPtrReg:$ptrreg),
1140 "ld\t$reg, $ptrreg+",
1142 Requires<[HasSRAM]>;
1148 def LDWRdPtrPi : Pseudo<(outs DREGS:$reg, PTRREGS:$base_wb),
1149 (ins PTRREGS:$ptrreg),
1150 "ldw\t$reg, $ptrreg+",
1152 Requires<[HasSRAM]>;
1154 def LDRdPtrPd : FSTLD<0,
1156 (outs GPR8:$reg, PTRREGS:$base_wb),
1157 (ins LDSTPtrReg:$ptrreg),
1158 "ld\t$reg, -$ptrreg",
1160 Requires<[HasSRAM]>;
1167 def LDWRdPtrPd : Pseudo<(outs DREGS:$reg, PTRREGS:$base_wb),
1168 (ins PTRREGS:$ptrreg),
1169 "ldw\t$reg, -$ptrreg",
1171 Requires<[HasSRAM]>;
1174 // Load indirect with displacement operations.
1175 let canFoldAsLoad = 1,
1176 isReMaterializable = 1 in
1178 def LDDRdPtrQ : FSTDLDD<0,
1181 "ldd\t$reg, $memri",
1182 [(set i8:$reg, (load addr:$memri))]>,
1183 Requires<[HasSRAM]>;
1185 // LDDW Rd+1:Rd, P+q
1190 let Constraints = "@earlyclobber $dst" in
1191 def LDDWRdPtrQ : Pseudo<(outs DREGS:$dst),
1193 "lddw\t$dst, $memri",
1194 [(set i16:$dst, (load addr:$memri))]>,
1195 Requires<[HasSRAM]>;
1197 //:FIXME: remove this once PR13375 gets fixed
1198 // Bug report: https://llvm.org/bugs/show_bug.cgi?id=13375
1200 hasSideEffects = 0 in
1201 def LDDWRdYQ : Pseudo<(outs DREGS:$dst),
1203 "lddw\t$dst, $memri",
1205 Requires<[HasSRAM]>;
1208 // Indirect store from register to data space.
1209 def STSKRr : F32DM<0b1,
1211 (ins i16imm:$k, GPR8:$rd),
1213 [(store i8:$rd, imm:$k)]>,
1214 Requires<[HasSRAM]>;
1216 // STSW K+1:K, Rr+1:Rr
1219 // sts Rr+1, (K+1:K) + 1
1221 def STSWKRr : Pseudo<(outs),
1222 (ins i16imm:$dst, DREGS:$src),
1224 [(store i16:$src, imm:$dst)]>,
1225 Requires<[HasSRAM]>;
1229 // Stores the value of Rr into the location addressed by pointer P.
1230 def STPtrRr : FSTLD<1,
1233 (ins LDSTPtrReg:$ptrreg, GPR8:$reg),
1234 "st\t$ptrreg, $reg",
1235 [(store GPR8:$reg, i16:$ptrreg)]>,
1236 Requires<[HasSRAM]>;
1239 // Stores the value of Rr into the location addressed by pointer P.
1244 def STWPtrRr : Pseudo<(outs),
1245 (ins PTRDISPREGS:$ptrreg, DREGS:$reg),
1246 "stw\t$ptrreg, $reg",
1247 [(store i16:$reg, i16:$ptrreg)]>,
1248 Requires<[HasSRAM]>;
1250 // Indirect stores (with postincrement or predecrement).
1251 let Constraints = "$ptrreg = $base_wb,@earlyclobber $base_wb" in
1255 // Stores the value of Rr into the location addressed by pointer P.
1256 // Post increments P.
1257 def STPtrPiRr : FSTLD<1,
1259 (outs LDSTPtrReg:$base_wb),
1260 (ins LDSTPtrReg:$ptrreg, GPR8:$reg, i8imm:$offs),
1261 "st\t$ptrreg+, $reg",
1263 (post_store GPR8:$reg, i16:$ptrreg, imm:$offs))]>,
1264 Requires<[HasSRAM]>;
1267 // Stores the value of Rr into the location addressed by pointer P.
1268 // Post increments P.
1273 def STWPtrPiRr : Pseudo<(outs PTRREGS:$base_wb),
1274 (ins PTRREGS:$ptrreg, DREGS:$trh, i8imm:$offs),
1275 "stw\t$ptrreg+, $trh",
1276 [(set PTRREGS:$base_wb,
1277 (post_store DREGS:$trh, PTRREGS:$ptrreg, imm:$offs))]>,
1278 Requires<[HasSRAM]>;
1281 // Stores the value of Rr into the location addressed by pointer P.
1282 // Pre decrements P.
1283 def STPtrPdRr : FSTLD<1,
1285 (outs LDSTPtrReg:$base_wb),
1286 (ins LDSTPtrReg:$ptrreg, GPR8:$reg, i8imm:$offs),
1287 "st\t-$ptrreg, $reg",
1289 (pre_store GPR8:$reg, i16:$ptrreg, imm:$offs))]>,
1290 Requires<[HasSRAM]>;
1293 // Stores the value of Rr into the location addressed by pointer P.
1294 // Pre decrements P.
1299 def STWPtrPdRr : Pseudo<(outs PTRREGS:$base_wb),
1300 (ins PTRREGS:$ptrreg, DREGS:$reg, i8imm:$offs),
1301 "stw\t-$ptrreg, $reg",
1302 [(set PTRREGS:$base_wb,
1303 (pre_store i16:$reg, i16:$ptrreg, imm:$offs))]>,
1304 Requires<[HasSRAM]>;
1307 // Store indirect with displacement operations.
1309 // Stores the value of Rr into the location addressed by pointer P with a
1310 // displacement of q. Does not modify P.
1311 def STDPtrQRr : FSTDLDD<1,
1313 (ins memri:$memri, GPR8:$reg),
1314 "std\t$memri, $reg",
1315 [(store i8:$reg, addr:$memri)]>,
1316 Requires<[HasSRAM]>;
1318 // STDW P+q, Rr+1:Rr
1319 // Stores the value of Rr into the location addressed by pointer P with a
1320 // displacement of q. Does not modify P.
1325 def STDWPtrQRr : Pseudo<(outs),
1326 (ins memri:$memri, DREGS:$src),
1327 "stdw\t$memri, $src",
1328 [(store i16:$src, addr:$memri)]>,
1329 Requires<[HasSRAM]>;
1332 // Load program memory operations.
1333 let canFoldAsLoad = 1,
1334 isReMaterializable = 1,
1335 hasSideEffects = 0 in
1339 def LPM : F16<0b1001010111001000,
1346 def LPMRdZ : FLPMX<0,
1352 Requires<[HasLPMX]>;
1354 def LPMWRdZ : Pseudo<(outs DREGS:$dst),
1358 Requires<[HasLPMX]>;
1360 // Load program memory, while postincrementing the Z register.
1364 def LPMRdZPi : FLPMX<0,
1370 Requires<[HasLPMX]>;
1372 def LPMWRdZPi : Pseudo<(outs DREGS:$dst),
1376 Requires<[HasLPMX]>;
1380 // Extended load program memory operations.
1382 hasSideEffects = 0 in
1386 def ELPM : F16<0b1001010111011000,
1391 Requires<[HasELPM]>;
1393 def ELPMRdZ : FLPMX<1,
1399 Requires<[HasELPMX]>;
1401 let Defs = [R31R30] in
1402 def ELPMRdZPi : FLPMX<1,
1408 Requires<[HasELPMX]>;
1411 // Store program memory operations.
1412 let Uses = [R1, R0] in
1414 let Uses = [R31R30, R1, R0] in
1415 def SPM : F16<0b1001010111101000,
1422 let Defs = [R31R30] in
1423 def SPMZPi : F16<0b1001010111111000,
1428 Requires<[HasSPMX]>;
1431 // Read data from IO location operations.
1432 let canFoldAsLoad = 1,
1433 isReMaterializable = 1 in
1435 def INRdA : FIORdA<(outs GPR8:$dst),
1438 [(set i8:$dst, (load ioaddr8:$src))]>;
1440 def INWRdA : Pseudo<(outs DREGS:$dst),
1443 [(set i16:$dst, (load ioaddr16:$src))]>;
1446 // Write data to IO location operations.
1447 def OUTARr : FIOARr<(outs),
1448 (ins i16imm:$dst, GPR8:$src),
1450 [(store i8:$src, ioaddr8:$dst)]>;
1452 def OUTWARr : Pseudo<(outs),
1453 (ins i16imm:$dst, DREGS:$src),
1455 [(store i16:$src, ioaddr16:$dst)]>;
1457 // Stack push/pop operations.
1460 hasSideEffects = 0 in
1462 // Stack push operations.
1465 def PUSHRr : FRd<0b1001,
1471 Requires<[HasSRAM]>;
1473 def PUSHWRr : Pseudo<(outs),
1477 Requires<[HasSRAM]>;
1480 // Stack pop operations.
1483 def POPRd : FRd<0b1001,
1489 Requires<[HasSRAM]>;
1491 def POPWRd : Pseudo<(outs DREGS:$reg),
1495 Requires<[HasSRAM]>;
1499 // Read-Write-Modify (RMW) instructions.
1500 def XCHZRd : FZRd<0b100,
1505 Requires<[SupportsRMW]>;
1507 def LASZRd : FZRd<0b101,
1512 Requires<[SupportsRMW]>;
1514 def LACZRd : FZRd<0b110,
1519 Requires<[SupportsRMW]>;
1521 def LATZRd : FZRd<0b111,
1526 Requires<[SupportsRMW]>;
1528 //===----------------------------------------------------------------------===//
1529 // Bit and bit-test instructions
1530 //===----------------------------------------------------------------------===//
1532 // Bit shift/rotate operations.
1533 let Constraints = "$src = $rd",
1536 def LSLRd : FRdRr<0b0000,
1541 [(set i8:$rd, (AVRlsl i8:$src)), (implicit SREG)]>;
1543 def LSLWRd : Pseudo<(outs DREGS:$rd),
1546 [(set i16:$rd, (AVRlsl i16:$src)), (implicit SREG)]>;
1548 def LSRRd : FRd<0b1001,
1553 [(set i8:$rd, (AVRlsr i8:$src)), (implicit SREG)]>;
1555 def LSRWRd : Pseudo<(outs DREGS:$rd),
1558 [(set i16:$rd, (AVRlsr i16:$src)), (implicit SREG)]>;
1560 def ASRRd : FRd<0b1001,
1565 [(set i8:$rd, (AVRasr i8:$src)), (implicit SREG)]>;
1567 def ASRWRd : Pseudo<(outs DREGS:$rd),
1570 [(set i16:$rd, (AVRasr i16:$src)), (implicit SREG)]>;
1572 // Bit rotate operations.
1573 let Uses = [SREG] in
1575 def ROLRd : FRdRr<0b0001,
1580 [(set i8:$rd, (AVRrol i8:$src)), (implicit SREG)]>;
1582 def ROLWRd : Pseudo<(outs DREGS:$rd),
1585 [(set i16:$rd, (AVRrol i16:$src)), (implicit SREG)]>;
1587 def RORRd : FRd<0b1001,
1592 [(set i8:$rd, (AVRror i8:$src)), (implicit SREG)]>;
1594 def RORWRd : Pseudo<(outs DREGS:$rd),
1597 [(set i16:$rd, (AVRror i16:$src)), (implicit SREG)]>;
1602 // Swaps the high and low nibbles in a register.
1603 let Constraints = "$src = $rd" in
1604 def SWAPRd : FRd<0b1001,
1609 [(set i8:$rd, (bswap i8:$src))]>;
1611 // IO register bit set/clear operations.
1612 //:TODO: add patterns when popcount(imm)==2 to be expanded with 2 sbi/cbi
1613 // instead of in+ori+out which requires one more instr.
1614 def SBIAb : FIOBIT<0b10,
1616 (ins i16imm:$addr, i8imm:$bit),
1618 [(store (or (i8 (load lowioaddr8:$addr)), iobitpos8:$bit),
1619 lowioaddr8:$addr)]>;
1621 def CBIAb : FIOBIT<0b00,
1623 (ins i16imm:$addr, i8imm:$bit),
1625 [(store (and (i8 (load lowioaddr8:$addr)), iobitposn8:$bit),
1626 lowioaddr8:$addr)]>;
1628 // Status register bit load/store operations.
1629 let Defs = [SREG] in
1630 def BST : FRdB<0b01,
1632 (ins GPR8:$rd, i8imm:$b),
1636 let Uses = [SREG] in
1637 def BLD : FRdB<0b00,
1639 (ins GPR8:$rd, i8imm:$b),
1643 // Set/clear bit in register operations.
1644 let Constraints = "$src = $rd",
1648 // Alias for ORI Rd, K
1649 def SBRRdK : FRdK<0b0110,
1651 (ins LD8:$src, i8imm:$k),
1653 [(set i8:$rd, (or i8:$src, imm:$k)),
1657 // Alias for `ANDI Rd, COM(K)` where COM(K) is the compliment of K.
1658 def CBRRdK : FRdK<0b0111,
1660 (ins LD8:$src, i8imm_com:$k),
1666 // Alias for EOR Rd, Rd
1668 // Clears all bits in a register.
1669 def CLR : InstAlias<"clr\t$rd", (EORRdRr GPR8:$rd, GPR8:$rd)>;
1672 // Alias for LDI Rd, 0xff
1674 // Sets all bits in a register.
1675 def : InstAlias<"ser\t$rd", (LDIRdK LD8:$rd, 0xff), 0>;
1677 let Defs = [SREG] in
1684 let Defs = [SREG] in
1691 // Set/clear aliases for the carry (C) status flag (bit 0).
1692 def : InstAlias<"sec", (BSETs 0)>;
1693 def : InstAlias<"clc", (BCLRs 0)>;
1695 // Set/clear aliases for the zero (Z) status flag (bit 1).
1696 def : InstAlias<"sez", (BSETs 1)>;
1697 def : InstAlias<"clz", (BCLRs 1)>;
1699 // Set/clear aliases for the negative (N) status flag (bit 2).
1700 def : InstAlias<"sen", (BSETs 2)>;
1701 def : InstAlias<"cln", (BCLRs 2)>;
1703 // Set/clear aliases for the overflow (V) status flag (bit 3).
1704 def : InstAlias<"sev", (BSETs 3)>;
1705 def : InstAlias<"clv", (BCLRs 3)>;
1707 // Set/clear aliases for the signed (S) status flag (bit 4).
1708 def : InstAlias<"ses", (BSETs 4)>;
1709 def : InstAlias<"cls", (BCLRs 4)>;
1711 // Set/clear aliases for the half-carry (H) status flag (bit 5).
1712 def : InstAlias<"seh", (BSETs 5)>;
1713 def : InstAlias<"clh", (BCLRs 5)>;
1715 // Set/clear aliases for the T status flag (bit 6).
1716 def : InstAlias<"set", (BSETs 6)>;
1717 def : InstAlias<"clt", (BCLRs 6)>;
1719 // Set/clear aliases for the interrupt (I) status flag (bit 7).
1720 def : InstAlias<"sei", (BSETs 7)>;
1721 def : InstAlias<"cli", (BCLRs 7)>;
1723 //===----------------------------------------------------------------------===//
1724 // Special/Control instructions
1725 //===----------------------------------------------------------------------===//
1728 // Breakpoint instruction
1730 // <|1001|0101|1001|1000>
1731 def BREAK : F16<0b1001010110011000,
1736 Requires<[HasBREAK]>;
1739 // No-operation instruction
1741 // <|0000|0000|0000|0000>
1742 def NOP : F16<0b0000000000000000,
1749 // Sleep instruction
1751 // <|1001|0101|1000|1000>
1752 def SLEEP : F16<0b1001010110001000,
1761 // <|1001|0101|1010|1000>
1762 def WDR : F16<0b1001010110101000,
1768 //===----------------------------------------------------------------------===//
1769 // Pseudo instructions for later expansion
1770 //===----------------------------------------------------------------------===//
1772 //:TODO: Optimize this for wider types AND optimize the following code
1773 // compile int foo(char a, char b, char c, char d) {return d+b;}
1774 // looks like a missed sext_inreg opportunity.
1775 def SEXT : ExtensionPseudo<
1779 [(set i16:$dst, (sext i8:$src)), (implicit SREG)]
1782 def ZEXT : ExtensionPseudo<
1786 [(set i16:$dst, (zext i8:$src)), (implicit SREG)]
1789 // This pseudo gets expanded into a movw+adiw thus it clobbers SREG.
1791 hasSideEffects = 0 in
1792 def FRMIDX : Pseudo<(outs DLDREGS:$dst),
1793 (ins DLDREGS:$src, i16imm:$src2),
1794 "frmidx\t$dst, $src, $src2",
1797 // This pseudo is either converted to a regular store or a push which clobbers
1799 def STDSPQRr : StorePseudo<
1801 (ins memspi:$dst, GPR8:$src),
1802 "stdstk\t$dst, $src",
1803 [(store i8:$src, addr:$dst)]
1806 // This pseudo is either converted to a regular store or a push which clobbers
1808 def STDWSPQRr : StorePseudo<
1810 (ins memspi:$dst, DREGS:$src),
1811 "stdwstk\t$dst, $src",
1812 [(store i16:$src, addr:$dst)]
1815 // SP read/write pseudos.
1816 let hasSideEffects = 0 in
1819 def SPREAD : Pseudo<
1822 "spread\t$dst, $src",
1827 def SPWRITE : Pseudo<
1830 "spwrite\t$dst, $src",
1834 def Select8 : SelectPseudo<
1836 (ins GPR8:$src, GPR8:$src2, i8imm:$cc),
1838 [(set i8:$dst, (AVRselectcc i8:$src, i8:$src2, imm:$cc))]
1841 def Select16 : SelectPseudo<
1843 (ins DREGS:$src, DREGS:$src2, i8imm:$cc),
1844 "# Select16 PSEUDO",
1845 [(set i16:$dst, (AVRselectcc i16:$src, i16:$src2, imm:$cc))]
1848 def Lsl8 : ShiftPseudo<
1850 (ins GPR8:$src, GPR8:$cnt),
1852 [(set i8:$dst, (AVRlslLoop i8:$src, i8:$cnt))]
1855 def Lsl16 : ShiftPseudo<
1857 (ins DREGS:$src, GPR8:$cnt),
1859 [(set i16:$dst, (AVRlslLoop i16:$src, i8:$cnt))]
1862 def Lsr8 : ShiftPseudo<
1864 (ins GPR8:$src, GPR8:$cnt),
1866 [(set i8:$dst, (AVRlsrLoop i8:$src, i8:$cnt))]
1870 def Lsr16 : ShiftPseudo<
1872 (ins DREGS:$src, GPR8:$cnt),
1874 [(set i16:$dst, (AVRlsrLoop i16:$src, i8:$cnt))]
1877 def Asr8 : ShiftPseudo<
1879 (ins GPR8:$src, GPR8:$cnt),
1881 [(set i8:$dst, (AVRasrLoop i8:$src, i8:$cnt))]
1884 def Asr16 : ShiftPseudo<
1886 (ins DREGS:$src, GPR8:$cnt),
1888 [(set i16:$dst, (AVRasrLoop i16:$src, i8:$cnt))]
1892 //===----------------------------------------------------------------------===//
1893 // Non-Instruction Patterns
1894 //===----------------------------------------------------------------------===//
1896 //:TODO: look in x86InstrCompiler.td for odd encoding trick related to
1897 // add x, 128 -> sub x, -128. Clang is emitting an eor for this (ldi+eor)
1899 // the add instruction always writes the carry flag
1900 def : Pat<(addc i8:$src, i8:$src2),
1901 (ADDRdRr i8:$src, i8:$src2)>;
1902 def : Pat<(addc DREGS:$src, DREGS:$src2),
1903 (ADDWRdRr DREGS:$src, DREGS:$src2)>;
1905 // all sub instruction variants always writes the carry flag
1906 def : Pat<(subc i8:$src, i8:$src2),
1907 (SUBRdRr i8:$src, i8:$src2)>;
1908 def : Pat<(subc i16:$src, i16:$src2),
1909 (SUBWRdRr i16:$src, i16:$src2)>;
1910 def : Pat<(subc i8:$src, imm:$src2),
1911 (SUBIRdK i8:$src, imm:$src2)>;
1912 def : Pat<(subc i16:$src, imm:$src2),
1913 (SUBIWRdK i16:$src, imm:$src2)>;
1915 // These patterns convert add (x, -imm) to sub (x, imm) since we dont have
1916 // any add with imm instructions. Also take care of the adiw/sbiw instructions.
1917 def : Pat<(add i16:$src1, imm0_63_neg:$src2),
1918 (SBIWRdK i16:$src1, (imm0_63_neg:$src2))>;
1919 def : Pat<(add i16:$src1, imm:$src2),
1920 (SUBIWRdK i16:$src1, (imm16_neg_XFORM imm:$src2))>;
1921 def : Pat<(addc i16:$src1, imm:$src2),
1922 (SUBIWRdK i16:$src1, (imm16_neg_XFORM imm:$src2))>;
1923 def : Pat<(adde i16:$src1, imm:$src2),
1924 (SBCIWRdK i16:$src1, (imm16_neg_XFORM imm:$src2))>;
1926 def : Pat<(add i8:$src1, imm:$src2),
1927 (SUBIRdK i8:$src1, (imm8_neg_XFORM imm:$src2))>;
1928 def : Pat<(addc i8:$src1, imm:$src2),
1929 (SUBIRdK i8:$src1, (imm8_neg_XFORM imm:$src2))>;
1930 def : Pat<(adde i8:$src1, imm:$src2),
1931 (SBCIRdK i8:$src1, (imm8_neg_XFORM imm:$src2))>;
1934 def : Pat<(AVRcall (i16 tglobaladdr:$dst)),
1935 (CALLk tglobaladdr:$dst)>;
1936 def : Pat<(AVRcall (i16 texternalsym:$dst)),
1937 (CALLk texternalsym:$dst)>;
1940 def : Pat<(i16 (anyext i8:$src)),
1941 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), i8:$src, sub_lo)>;
1944 def : Pat<(i8 (trunc i16:$src)),
1945 (EXTRACT_SUBREG i16:$src, sub_lo)>;
1948 def : Pat<(sext_inreg i16:$src, i8),
1949 (SEXT (i8 (EXTRACT_SUBREG i16:$src, sub_lo)))>;
1952 def : Pat<(i16 (AVRWrapper tglobaladdr:$dst)),
1953 (LDIWRdK tglobaladdr:$dst)>;
1954 def : Pat<(add i16:$src, (AVRWrapper tglobaladdr:$src2)),
1955 (SUBIWRdK i16:$src, tglobaladdr:$src2)>;
1956 def : Pat<(i8 (load (AVRWrapper tglobaladdr:$dst))),
1957 (LDSRdK tglobaladdr:$dst)>;
1958 def : Pat<(i16 (load (AVRWrapper tglobaladdr:$dst))),
1959 (LDSWRdK tglobaladdr:$dst)>;
1960 def : Pat<(store i8:$src, (i16 (AVRWrapper tglobaladdr:$dst))),
1961 (STSKRr tglobaladdr:$dst, i8:$src)>;
1962 def : Pat<(store i16:$src, (i16 (AVRWrapper tglobaladdr:$dst))),
1963 (STSWKRr tglobaladdr:$dst, i16:$src)>;
1966 def : Pat<(i16 (AVRWrapper tblockaddress:$dst)),
1967 (LDIWRdK tblockaddress:$dst)>;
1969 // hi-reg truncation : trunc(int16 >> 8)
1970 //:FIXME: i think it's better to emit an extract subreg node in the DAG than
1971 // all this mess once we get optimal shift code
1972 // lol... I think so, too. [@agnat]
1973 def : Pat<(i8 (trunc (AVRlsr (AVRlsr (AVRlsr (AVRlsr (AVRlsr (AVRlsr (AVRlsr
1974 (AVRlsr DREGS:$src)))))))))),
1975 (EXTRACT_SUBREG DREGS:$src, sub_hi)>;
1977 // :FIXME: DAGCombiner produces an shl node after legalization from these seq:
1978 // BR_JT -> (mul x, 2) -> (shl x, 1)
1979 def : Pat<(shl i16:$src1, (i8 1)),
1980 (LSLWRd i16:$src1)>;