From 3f192450151f4ed9eb656037193651781adf7d41 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. llvm-svn: 267621 --- llvm/include/llvm/CodeGen/MachineInstrBundle.h | 4 ++++ llvm/lib/CodeGen/MachineInstrBundle.cpp | 10 +++++++--- llvm/test/CodeGen/X86/cmpxchg-clobber-flags.ll | 3 +-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineInstrBundle.h b/llvm/include/llvm/CodeGen/MachineInstrBundle.h index 9b374cf..fd828d4 100644 --- a/llvm/include/llvm/CodeGen/MachineInstrBundle.h +++ b/llvm/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/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp index 4619daf..725237b 100644 --- a/llvm/lib/CodeGen/MachineInstrBundle.cpp +++ b/llvm/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/llvm/test/CodeGen/X86/cmpxchg-clobber-flags.ll b/llvm/test/CodeGen/X86/cmpxchg-clobber-flags.ll index 6f54a04..74599cb 100644 --- a/llvm/test/CodeGen/X86/cmpxchg-clobber-flags.ll +++ b/llvm/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 -- 2.7.4