Index: lib/CodeGen/RegisterCoalescer.cpp =================================================================== --- lib/CodeGen/RegisterCoalescer.cpp +++ lib/CodeGen/RegisterCoalescer.cpp @@ -686,13 +686,16 @@ /// Copy segments with value number @p SrcValNo from liverange @p Src to live /// range @Dst and use value number @p DstValNo there. -static void addSegmentsWithValNo(LiveRange &Dst, VNInfo *DstValNo, +static bool addSegmentsWithValNo(LiveRange &Dst, VNInfo *DstValNo, const LiveRange &Src, const VNInfo *SrcValNo) { + bool Added = false; for (const LiveRange::Segment &S : Src.segments) { if (S.valno != SrcValNo) continue; + Added = true; Dst.addSegment(LiveRange::Segment(S.start, S.end, DstValNo)); } + return Added; } bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP, @@ -889,7 +892,8 @@ ? SR.getNextValue(CopyIdx, Allocator) : SR.getVNInfoAt(CopyIdx); assert(BSubValNo != nullptr); - addSegmentsWithValNo(SR, BSubValNo, SA, ASubValNo); + if (addSegmentsWithValNo(SR, BSubValNo, SA, ASubValNo)) + BSubValNo->def = ASubValNo->def; }); } } Index: lib/CodeGen/VirtRegMap.cpp =================================================================== --- lib/CodeGen/VirtRegMap.cpp +++ lib/CodeGen/VirtRegMap.cpp @@ -525,7 +525,7 @@ // Preserve semantics of sub-register operands. unsigned SubReg = MO.getSubReg(); if (SubReg != 0) { - if (NoSubRegLiveness) { + if (NoSubRegLiveness || !MRI->shouldTrackSubRegLiveness(VirtReg)) { // A virtual register kill refers to the whole register, so we may // have to add implicit killed operands for the super-register. A // partial redef always kills and redefines the super-register. Index: lib/Target/SystemZ/SystemZSubtarget.h =================================================================== --- lib/Target/SystemZ/SystemZSubtarget.h +++ lib/Target/SystemZ/SystemZSubtarget.h @@ -102,6 +102,8 @@ // Always enable the early if-conversion pass. bool enableEarlyIfConversion() const override { return true; } + bool enableSubRegLiveness() const override { return true; } + // Automatically generated by tblgen. void ParseSubtargetFeatures(StringRef CPU, StringRef FS);