@@ -598,6 +598,9 @@ bool AArch64ExpandPseudo::expand_DestructiveOp(
598598 llvm_unreachable (" Unsupported ElementSize" );
599599 }
600600
601+ // Preserve undef state until DOP's reg is defined.
602+ unsigned DOPRegState = MI.getOperand (DOPIdx).isUndef () ? RegState::Undef : 0 ;
603+
601604 //
602605 // Create the destructive operation (if required)
603606 //
@@ -616,10 +619,11 @@ bool AArch64ExpandPseudo::expand_DestructiveOp(
616619 PRFX = BuildMI (MBB, MBBI, MI.getDebugLoc (), TII->get (MovPrfxZero))
617620 .addReg (DstReg, RegState::Define)
618621 .addReg (MI.getOperand (PredIdx).getReg ())
619- .addReg (MI.getOperand (DOPIdx).getReg ());
622+ .addReg (MI.getOperand (DOPIdx).getReg (), DOPRegState );
620623
621624 // After the movprfx, the destructive operand is same as Dst
622625 DOPIdx = 0 ;
626+ DOPRegState = 0 ;
623627
624628 // Create the additional LSL to zero the lanes when the DstReg is not
625629 // unique. Zeros the lanes in z0 that aren't active in p0 with sequence
@@ -638,19 +642,21 @@ bool AArch64ExpandPseudo::expand_DestructiveOp(
638642 assert (DOPRegIsUnique && " The destructive operand should be unique" );
639643 PRFX = BuildMI (MBB, MBBI, MI.getDebugLoc (), TII->get (MovPrfx))
640644 .addReg (DstReg, RegState::Define)
641- .addReg (MI.getOperand (DOPIdx).getReg ());
645+ .addReg (MI.getOperand (DOPIdx).getReg (), DOPRegState );
642646 DOPIdx = 0 ;
647+ DOPRegState = 0 ;
643648 }
644649
645650 //
646651 // Create the destructive operation
647652 //
648653 DOP = BuildMI (MBB, MBBI, MI.getDebugLoc (), TII->get (Opcode))
649654 .addReg (DstReg, RegState::Define | getDeadRegState (DstIsDead));
655+ DOPRegState = DOPRegState | RegState::Kill;
650656
651657 switch (DType) {
652658 case AArch64::DestructiveUnaryPassthru:
653- DOP.addReg (MI.getOperand (DOPIdx).getReg (), RegState::Kill )
659+ DOP.addReg (MI.getOperand (DOPIdx).getReg (), DOPRegState )
654660 .add (MI.getOperand (PredIdx))
655661 .add (MI.getOperand (SrcIdx));
656662 break ;
@@ -659,12 +665,12 @@ bool AArch64ExpandPseudo::expand_DestructiveOp(
659665 case AArch64::DestructiveBinaryComm:
660666 case AArch64::DestructiveBinaryCommWithRev:
661667 DOP.add (MI.getOperand (PredIdx))
662- .addReg (MI.getOperand (DOPIdx).getReg (), RegState::Kill )
663- .add (MI.getOperand (SrcIdx));
668+ .addReg (MI.getOperand (DOPIdx).getReg (), DOPRegState )
669+ .add (MI.getOperand (SrcIdx));
664670 break ;
665671 case AArch64::DestructiveTernaryCommWithRev:
666672 DOP.add (MI.getOperand (PredIdx))
667- .addReg (MI.getOperand (DOPIdx).getReg (), RegState::Kill )
673+ .addReg (MI.getOperand (DOPIdx).getReg (), DOPRegState )
668674 .add (MI.getOperand (SrcIdx))
669675 .add (MI.getOperand (Src2Idx));
670676 break ;
0 commit comments