const SmallSet<Register, 2> &TargetReg,
RecurrenceCycle &RC);
- /// If copy instruction \p MI is a virtual register copy, track it in
- /// the set \p CopyMIs. If this virtual register was previously seen as a
+ /// If copy instruction \p MI is a virtual register copy or a copy of a
+ /// constant physical register to a virtual register, track it in the
+ /// set \p CopyMIs. If this virtual register was previously seen as a
/// copy, replace the uses of this copy with the previously seen copy's
/// destination register.
bool foldRedundantCopy(MachineInstr &MI,
Register SrcReg = MI.getOperand(1).getReg();
unsigned SrcSubReg = MI.getOperand(1).getSubReg();
- if (!SrcReg.isVirtual())
+ if (!SrcReg.isVirtual() && !MRI->isConstantPhysReg(SrcReg))
return false;
Register DstReg = MI.getOperand(0).getReg();
// without any intervening re-definition of $physreg.
DenseMap<Register, MachineInstr *> NAPhysToVirtMIs;
- // Set of pairs of virtual registers and their subregs that are copied
- // from.
+ // Set of copies to virtual registers keyed by source register. Never
+ // holds any physreg which requires def tracking.
DenseMap<RegSubRegPair, MachineInstr *> CopySrcMIs;
bool IsLoopHeader = MLI->isLoopHeader(&MBB);
; CHECK-LABEL: simple_cse:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: csrr a0, vlenb
-; CHECK-NEXT: csrr a1, vlenb
-; CHECK-NEXT: sub a0, a0, a1
+; CHECK-NEXT: sub a0, a0, a0
; CHECK-NEXT: ret
entry:
%v1 = call i32 @llvm.read_register.i32(metadata !0)