Index: include/llvm/Target/TargetRegisterInfo.h =================================================================== --- include/llvm/Target/TargetRegisterInfo.h +++ include/llvm/Target/TargetRegisterInfo.h @@ -17,6 +17,7 @@ #define LLVM_TARGET_TARGETREGISTERINFO_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineValueType.h" #include "llvm/IR/CallingConv.h" @@ -86,6 +87,11 @@ /// Return the number of registers in this class. unsigned getNumRegs() const { return MC->getNumRegs(); } + + iterator_range::const_iterator> + getRegisters() const { + return make_range(MC->begin(), MC->end()); + } /// Return the specified register in the class. unsigned getRegister(unsigned i) const { Index: lib/CodeGen/ExecutionDepsFix.cpp =================================================================== --- lib/CodeGen/ExecutionDepsFix.cpp +++ lib/CodeGen/ExecutionDepsFix.cpp @@ -509,12 +509,15 @@ // max clearance or clearance higher than Pref. unsigned MaxClearance = 0; unsigned MaxClearanceReg = OriginalReg; - for (unsigned rx = 0; rx < OpRC->getNumRegs(); ++rx) { - unsigned Clearance = CurInstr - LiveRegs[rx].Def; + for (auto Reg : OpRC->getRegisters()) { + assert(AliasMap[Reg].size() == 1 && + "Reg is expected to be mapped to a single index"); + int RCrx = *regIndices(Reg).begin(); + unsigned Clearance = CurInstr - LiveRegs[RCrx].Def; if (Clearance <= MaxClearance) continue; MaxClearance = Clearance; - MaxClearanceReg = OpRC->getRegister(rx); + MaxClearanceReg = Reg; if (MaxClearance > Pref) break;