Index: include/llvm/MC/MCRegisterInfo.h =================================================================== --- include/llvm/MC/MCRegisterInfo.h +++ include/llvm/MC/MCRegisterInfo.h @@ -476,6 +476,9 @@ bool isSuperOrSubRegisterEq(unsigned RegA, unsigned RegB) const { return isSubRegisterEq(RegA, RegB) || isSuperRegister(RegA, RegB); } + + /// \brief Returns true if \p RegA and \p RegB alias. + bool checkRegistersAlias(unsigned RegA, unsigned RegB) const; }; //===----------------------------------------------------------------------===// @@ -729,6 +732,16 @@ } }; +// Definition for checkRegistersAlias. Put it down here since it needs the +// iterator defined above in addition to the MCRegisterInfo class itself. +inline bool MCRegisterInfo::checkRegistersAlias(unsigned RegA, + unsigned RegB) const { + for (MCRegAliasIterator I(RegA, this, true); I.isValid(); ++I) + if (*I == RegB) + return true; + return false; +} + } // end namespace llvm #endif // LLVM_MC_MCREGISTERINFO_H Index: lib/Target/X86/X86FixupBWInsts.cpp =================================================================== --- lib/Target/X86/X86FixupBWInsts.cpp +++ lib/Target/X86/X86FixupBWInsts.cpp @@ -249,15 +249,12 @@ assert((MO.isDef() || MO.isUse()) && "Expected Def or Use only!"); - for (MCSuperRegIterator Supers(OrigDestReg, TRI, true); Supers.isValid(); - ++Supers) { - if (*Supers == MO.getReg()) { - if (MO.isDef()) - IsDefined = true; - else - return false; // SuperReg Imp-used' -> live before the MI - } - } + if (MO.isDef() && TRI->isSuperRegisterEq(OrigDestReg, MO.getReg())) + IsDefined = true; + + if (MO.isUse() && !TRI->isSubRegisterEq(OrigDestReg, MO.getReg()) && + TRI->checkRegistersAlias(SuperDestReg, MO.getReg())) + return false; } // Reg is not Imp-def'ed -> it's live both before/after the instruction. if (!IsDefined) Index: test/CodeGen/X86/fixup-bw-inst.mir =================================================================== --- test/CodeGen/X86/fixup-bw-inst.mir +++ test/CodeGen/X86/fixup-bw-inst.mir @@ -32,6 +32,8 @@ %t2 = or i16 undef, %t1 ret i16 %t2 } + + define void @test5() {ret void} ... --- # CHECK-LABEL: name: test1 @@ -199,3 +201,46 @@ %ax = OR16rr undef %ax, %r9w, implicit-def %eflags RETQ %ax ... + +--- +# CHECK-LABEL: name: test5 +name: test5 +alignment: 4 +exposesReturnsTwice: false +legalized: false +regBankSelected: false +selected: false +tracksRegLiveness: true +registers: +liveins: + - { reg: '%ch', reg: '%bl' } +frameInfo: + isFrameAddressTaken: false + isReturnAddressTaken: false + hasStackMap: false + hasPatchPoint: false + stackSize: 0 + offsetAdjustment: 0 + maxAlignment: 0 + adjustsStack: false + hasCalls: false + stackProtector: '' + maxCallFrameSize: 0 + hasOpaqueSPAdjustment: false + hasVAStart: false + hasMustTailInVarArgFunc: false + savePoint: '' + restorePoint: '' +fixedStack: +stack: +constants: +body: | + bb.0: + successors: + liveins: %ch, %bl + + %cl = MOV8rr %bl, implicit-def %cx, implicit killed %ch, implicit-def %eflags + ; CHECK: %cl = MOV8rr %bl, implicit-def %cx, implicit killed %ch, implicit-def %eflags + + RETQ %cx +...