diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -798,6 +798,7 @@ Last = std::next(CallInst.getReverse()); Iter != Last; Iter++) { MachineInstr *MI = &*Iter; + SmallSet InstrUseRegs; for (MachineOperand &MOP : MI->operands()) { // Skip over anything that isn't a register. if (!MOP.isReg()) @@ -806,7 +807,8 @@ if (MOP.isDef()) { // Introduce DefRegs set to skip the redundant register. DefRegs.insert(MOP.getReg()); - if (!MOP.isDead() && UseRegs.count(MOP.getReg())) + if (UseRegs.count(MOP.getReg()) && + !InstrUseRegs.count(MOP.getReg())) // Since the regiester is modeled as defined, // it is not necessary to be put in use register set. UseRegs.erase(MOP.getReg()); @@ -814,6 +816,7 @@ // Any register which is not undefined should // be put in the use register set. UseRegs.insert(MOP.getReg()); + InstrUseRegs.insert(MOP.getReg()); } } if (MI->isCandidateForCallSiteEntry()) diff --git a/llvm/test/CodeGen/AArch64/machine-outliner-side-effect-2.mir b/llvm/test/CodeGen/AArch64/machine-outliner-side-effect-2.mir --- a/llvm/test/CodeGen/AArch64/machine-outliner-side-effect-2.mir +++ b/llvm/test/CodeGen/AArch64/machine-outliner-side-effect-2.mir @@ -1,6 +1,7 @@ # RUN: llc -mtriple=aarch64 -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s -# The test checks whether the compiler updates the side effect of function @OUTLINED_FUNCTION_0 by adding the use of register x0. +# The test checks whether the compiler updates the side effect of function @OUTLINED_FUNCTION_0 +# when implict-def and implict use of $x0 in the same instruction. --- | declare void @spam() local_unnamed_addr @@ -16,7 +17,8 @@ liveins: $x0, $lr $x1 = ADDXri $sp, 16, 0 - BL @spam, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit killed $x1, implicit-def $sp, implicit-def dead $x0 + BL @spam, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit killed $x1, implicit-def $sp, implicit-def $x0 + renamable $x1 = COPY $x0 RET_ReallyLR @@ -29,7 +31,8 @@ liveins: $x0, $lr $x1 = ADDXri $sp, 16, 0 - BL @spam, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit killed $x1, implicit-def $sp, implicit-def dead $x0 + BL @spam, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit killed $x1, implicit-def $sp, implicit-def $x0 + renamable $x2 = COPY $x0 RET_ReallyLR @@ -42,10 +45,11 @@ liveins: $x0, $lr $x1 = ADDXri $sp, 16, 0 - BL @spam, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit killed $x1, implicit-def $sp, implicit-def dead $x0 + BL @spam, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit killed $x1, implicit-def $sp, implicit-def $x0 + renamable $x3 = COPY $x0 RET_ReallyLR ... -# CHECK: BL @OUTLINED_FUNCTION_0, {{.*}}, implicit $x0 +# CHECK: BL @OUTLINED_FUNCTION_0, {{.*}}, implicit $x0{{.*}} diff --git a/llvm/test/CodeGen/AArch64/machine-outliner-side-effect.mir b/llvm/test/CodeGen/AArch64/machine-outliner-side-effect.mir --- a/llvm/test/CodeGen/AArch64/machine-outliner-side-effect.mir +++ b/llvm/test/CodeGen/AArch64/machine-outliner-side-effect.mir @@ -29,4 +29,4 @@ ... -# CHECK: BL @OUTLINED_FUNCTION_0, {{.*}}, implicit $x20, {{.*}} +# CHECK: BL @OUTLINED_FUNCTION_0, {{.*}}, implicit $x20{{.*}}