@@ -473,13 +473,6 @@ bool M68kInstrInfo::ExpandMOVSZX_RR(MachineInstrBuilder &MIB, bool IsSigned,
473
473
MVT MVTDst, MVT MVTSrc) const {
474
474
LLVM_DEBUG (dbgs () << " Expand " << *MIB.getInstr () << " to " );
475
475
476
- unsigned Move;
477
-
478
- if (MVTDst == MVT::i16 )
479
- Move = M68k::MOV16rr;
480
- else // i32
481
- Move = M68k::MOV32rr;
482
-
483
476
Register Dst = MIB->getOperand (0 ).getReg ();
484
477
Register Src = MIB->getOperand (1 ).getReg ();
485
478
@@ -501,17 +494,45 @@ bool M68kInstrInfo::ExpandMOVSZX_RR(MachineInstrBuilder &MIB, bool IsSigned,
501
494
MachineBasicBlock &MBB = *MIB->getParent ();
502
495
DebugLoc DL = MIB->getDebugLoc ();
503
496
504
- if (Dst != SSrc) {
505
- LLVM_DEBUG (dbgs () << " Move and " << ' \n ' );
506
- BuildMI (MBB, MIB.getInstr (), DL, get (Move), Dst).addReg (SSrc);
497
+ // It's more efficient to clear the destination and *then* move, rather than
498
+ // move and zext.
499
+ if (Dst != SSrc && !IsSigned) {
500
+
501
+ unsigned Move;
502
+ if (MVTSrc == MVT::i8 )
503
+ Move = M68k::MOV8dd;
504
+ else // i16
505
+ Move = M68k::MOV16dd;
506
+ unsigned Clr;
507
+ if (MVTDst == MVT::i16 )
508
+ Clr = M68k::CLR16d;
509
+ else // i32
510
+ Clr = M68k::CLR32d;
511
+
512
+ LLVM_DEBUG (dbgs () << " Clear and Zero Extend" << ' \n ' );
513
+ BuildMI (MBB, MIB.getInstr (), DL, get (Clr), Dst);
514
+ BuildMI (MBB, MIB.getInstr (), DL, get (Move), Dst).addReg (Src);
507
515
}
516
+ else {
508
517
509
- if (IsSigned) {
510
- LLVM_DEBUG (dbgs () << " Sign Extend" << ' \n ' );
511
- AddSExt (MBB, MIB.getInstr (), DL, Dst, MVTSrc, MVTDst);
512
- } else {
513
- LLVM_DEBUG (dbgs () << " Zero Extend" << ' \n ' );
514
- AddZExt (MBB, MIB.getInstr (), DL, Dst, MVTSrc, MVTDst);
518
+ unsigned Move;
519
+ if (MVTDst == MVT::i16 )
520
+ Move = M68k::MOV16dd;
521
+ else // i32
522
+ Move = M68k::MOV32dd;
523
+
524
+ if (Dst != SSrc) {
525
+ LLVM_DEBUG (dbgs () << " Move and " << ' \n ' );
526
+ BuildMI (MBB, MIB.getInstr (), DL, get (Move), Dst).addReg (SSrc);
527
+ }
528
+
529
+ if (IsSigned) {
530
+ LLVM_DEBUG (dbgs () << " Sign Extend" << ' \n ' );
531
+ AddSExt (MBB, MIB.getInstr (), DL, Dst, MVTSrc, MVTDst);
532
+ } else {
533
+ LLVM_DEBUG (dbgs () << " Zero Extend" << ' \n ' );
534
+ AddZExt (MBB, MIB.getInstr (), DL, Dst, MVTSrc, MVTDst);
535
+ }
515
536
}
516
537
517
538
MIB->eraseFromParent ();
@@ -522,7 +543,7 @@ bool M68kInstrInfo::ExpandMOVSZX_RR(MachineInstrBuilder &MIB, bool IsSigned,
522
543
bool M68kInstrInfo::ExpandMOVSZX_RM (MachineInstrBuilder &MIB, bool IsSigned,
523
544
const MCInstrDesc &Desc, MVT MVTDst,
524
545
MVT MVTSrc) const {
525
- LLVM_DEBUG (dbgs () << " Expand " << *MIB.getInstr () << " to LOAD and " );
546
+ LLVM_DEBUG (dbgs () << " Expand " << *MIB.getInstr () << " to " );
526
547
527
548
Register Dst = MIB->getOperand (0 ).getReg ();
528
549
@@ -541,16 +562,34 @@ bool M68kInstrInfo::ExpandMOVSZX_RM(MachineInstrBuilder &MIB, bool IsSigned,
541
562
MIB->getOperand (0 ).setReg (SubDst);
542
563
543
564
MachineBasicBlock::iterator I = MIB.getInstr ();
544
- I++;
545
565
MachineBasicBlock &MBB = *MIB->getParent ();
546
566
DebugLoc DL = MIB->getDebugLoc ();
547
567
548
- if (IsSigned) {
549
- LLVM_DEBUG (dbgs () << " Sign Extend" << ' \n ' );
550
- AddSExt (MBB, I, DL, Dst, MVTSrc, MVTDst);
551
- } else {
552
- LLVM_DEBUG (dbgs () << " Zero Extend" << ' \n ' );
553
- AddZExt (MBB, I, DL, Dst, MVTSrc, MVTDst);
568
+ // We can only clear before loading if the destination register isn't being
569
+ // used as an index for the load.
570
+ if (!IsSigned && !MIB->readsRegister (Dst, Subtarget.getRegisterInfo ())) {
571
+ unsigned Clr;
572
+ if (MVTDst == MVT::i16 ) {
573
+ Clr = M68k::CLR16d;
574
+ } else { // i32
575
+ Clr = M68k::CLR32d;
576
+ }
577
+
578
+ // Clear before load
579
+ LLVM_DEBUG (dbgs () << " Clear and LOAD" << ' \n ' );
580
+ BuildMI (MBB, MIB.getInstr (), DL, get (Clr), Dst);
581
+ I++;
582
+ }
583
+ else {
584
+ // Extend after load
585
+ I++;
586
+ if (IsSigned) {
587
+ LLVM_DEBUG (dbgs () << " LOAD and Sign Extend" << ' \n ' );
588
+ AddSExt (MBB, I, DL, Dst, MVTSrc, MVTDst);
589
+ } else {
590
+ LLVM_DEBUG (dbgs () << " Zero Extend" << ' \n ' );
591
+ AddZExt (MBB, I, DL, Dst, MVTSrc, MVTDst);
592
+ }
554
593
}
555
594
556
595
return true ;
0 commit comments