From b62e24784c81605fa82143db6f8f97310bc6ca98 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Tue, 26 Apr 2016 23:14:24 +0000 Subject: [PATCH] [MachineInstrBundle] Improvement the recognition of dead definitions. Now, it is possible to know that partial definitions are dead definitions and recognize that clobbered registers are also dead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267621 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineInstrBundle.h | 4 ++++ lib/CodeGen/MachineInstrBundle.cpp | 10 +++++++--- test/CodeGen/X86/cmpxchg-clobber-flags.ll | 3 +-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/llvm/CodeGen/MachineInstrBundle.h b/include/llvm/CodeGen/MachineInstrBundle.h index 9b374cf7991..fd828d4959d 100644 --- a/include/llvm/CodeGen/MachineInstrBundle.h +++ b/include/llvm/CodeGen/MachineInstrBundle.h @@ -187,6 +187,10 @@ public: /// dead. bool DeadDef; + /// Reg is Defined and all defs of reg or an overlapping register are + /// dead. + bool PartialDeadDef; + /// There is a use operand of reg or a super-register with kill flag set. bool Killed; }; diff --git a/lib/CodeGen/MachineInstrBundle.cpp b/lib/CodeGen/MachineInstrBundle.cpp index 4619daf3014..725237b5644 100644 --- a/lib/CodeGen/MachineInstrBundle.cpp +++ b/lib/CodeGen/MachineInstrBundle.cpp @@ -293,7 +293,7 @@ MachineOperandIteratorBase::PhysRegInfo MachineOperandIteratorBase::analyzePhysReg(unsigned Reg, const TargetRegisterInfo *TRI) { bool AllDefsDead = true; - PhysRegInfo PRI = {false, false, false, false, false, false, false}; + PhysRegInfo PRI = {false, false, false, false, false, false, false, false}; assert(TargetRegisterInfo::isPhysicalRegister(Reg) && "analyzePhysReg not given a physical register!"); @@ -332,8 +332,12 @@ MachineOperandIteratorBase::analyzePhysReg(unsigned Reg, } } - if (AllDefsDead && PRI.FullyDefined) - PRI.DeadDef = true; + if (AllDefsDead) { + if (PRI.FullyDefined || PRI.Clobbered) + PRI.DeadDef = true; + else + PRI.PartialDeadDef = true; + } return PRI; } diff --git a/test/CodeGen/X86/cmpxchg-clobber-flags.ll b/test/CodeGen/X86/cmpxchg-clobber-flags.ll index 6f54a0435f8..74599cbdc17 100644 --- a/test/CodeGen/X86/cmpxchg-clobber-flags.ll +++ b/test/CodeGen/X86/cmpxchg-clobber-flags.ll @@ -63,11 +63,10 @@ define i64 @test_intervening_call(i64* %foo, i64 %bar, i64 %baz) { ; x8664-sahf-NEXT: popq %rax ; x8664-sahf-NEXT: movq %rax, %rdi ; x8664-sahf-NEXT: callq bar -; x8664-sahf-NEXT: pushq %rax +; RAX is dead, no need to push and pop it. ; x8664-sahf-NEXT: movq [[FLAGS]], %rax ; x8664-sahf-NEXT: addb $127, %al ; x8664-sahf-NEXT: sahf -; x8664-sahf-NEXT: popq %rax ; x8664-sahf-NEXT: jne %cx = cmpxchg i64* %foo, i64 %bar, i64 %baz seq_cst seq_cst