From da1abaaf13ccb66e985f33398d672dcd38fad34e Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 30 Aug 2018 07:18:19 +0000 Subject: [PATCH] Don't count debug instructions towards neighborhood count In computeRegisterLiveness, the max instructions to search was counting dbg_value instructions, which could potentially cause an observable codegen change from the presence of debug info. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341028 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineBasicBlock.cpp | 16 +- .../AMDGPU/fold-immediate-operand-shrink.mir | 183 ++++++++++++++++++ 2 files changed, 196 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp index 71fdb0f90f2..3e040711052 100644 --- a/lib/CodeGen/MachineBasicBlock.cpp +++ b/lib/CodeGen/MachineBasicBlock.cpp @@ -1379,7 +1379,12 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, const_iterator I(Before); // If this is the last insn in the block, don't search forwards. if (I != end()) { - for (++I; I != end() && N > 0; ++I, --N) { + for (++I; I != end() && N > 0; ++I) { + if (I->isDebugInstr()) + continue; + + --N; + MachineOperandIteratorBase::PhysRegInfo Info = ConstMIOperands(*I).analyzePhysReg(Reg, TRI); @@ -1416,6 +1421,11 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, do { --I; + if (I->isDebugInstr()) + continue; + + --N; + MachineOperandIteratorBase::PhysRegInfo Info = ConstMIOperands(*I).analyzePhysReg(Reg, TRI); @@ -1440,7 +1450,8 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, // Register must be live if we read it. if (Info.Read) return LQR_Live; - } while (I != begin() && --N > 0); + + } while (I != begin() && N > 0); } // Did we get to the start of the block? @@ -1454,7 +1465,6 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, return LQR_Dead; } - // At this point we have no idea of the liveness of the register. return LQR_Unknown; } diff --git a/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir b/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir index 62d8e59a335..847c2b720cd 100644 --- a/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir +++ b/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir @@ -407,3 +407,186 @@ body: | S_ENDPGM implicit %2 ... +--- + +# This requires searching through many DBG_VALUE instructions before the insert poitn, which +# should not count against the search limit. + +name: vcc_liveness_dbg_value_search_before +tracksRegLiveness: true + +body: | + bb.0: + ; GCN-LABEL: name: vcc_liveness_dbg_value_search_before + ; GCN: [[S_MOV_B32_:%[0-9]+]]:sreg_32_xm0 = S_MOV_B32 12345 + ; GCN: [[DEF:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: [[V_ADD_I32_e32_:%[0-9]+]]:vgpr_32 = V_ADD_I32_e32 [[S_MOV_B32_]], [[DEF]], implicit-def $vcc, implicit $exec + ; GCN: S_ENDPGM implicit [[V_ADD_I32_e32_]] + %0:sreg_32_xm0 = S_MOV_B32 12345 + %1:vgpr_32 = IMPLICIT_DEF + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + %2:vgpr_32, %3:sreg_64 = V_ADD_I32_e64 %0, %1, implicit $exec + S_ENDPGM implicit %2 + +... +--- + +# This requires searching through many DBG_VALUE instructions after the insert point, which +# should not count against the search limit. + +name: vcc_liveness_dbg_value_search_after +tracksRegLiveness: true + +body: | + bb.0: + ; GCN-LABEL: name: vcc_liveness_dbg_value_search_after + ; GCN: [[S_MOV_B32_:%[0-9]+]]:sreg_32_xm0 = S_MOV_B32 12345 + ; GCN: [[DEF:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF + ; GCN: [[V_ADD_I32_e32_:%[0-9]+]]:vgpr_32 = V_ADD_I32_e32 [[S_MOV_B32_]], [[DEF]], implicit-def $vcc, implicit $exec + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: DBG_VALUE $noreg, 0 + ; GCN: S_ENDPGM implicit [[V_ADD_I32_e32_]] + %0:sreg_32_xm0 = S_MOV_B32 12345 + %1:vgpr_32 = IMPLICIT_DEF + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + %2:vgpr_32, %3:sreg_64 = V_ADD_I32_e64 %0, %1, implicit $exec + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + DBG_VALUE $noreg, 0 + $vcc = S_MOV_B64 0 + S_ENDPGM implicit %2 + +...