diff --git a/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp b/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp --- a/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp +++ b/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp @@ -336,23 +336,38 @@ assert(SI.isValid()); // Remove dead registers or mask bits. - for (auto &It : LiveRegs) { - const LiveInterval &LI = LIS.getInterval(It.first); + SmallSet SeenRegs; + for (auto &MO : LastTrackedMI->operands()) { + if (!MO.isReg() || !MO.getReg().isVirtual()) + continue; + if (MO.isUse() && !MO.readsReg()) + continue; + if (!SeenRegs.insert(MO.getReg()).second) + continue; + const LiveInterval &LI = LIS.getInterval(MO.getReg()); if (LI.hasSubRanges()) { + auto It = LiveRegs.end(); for (const auto &S : LI.subranges()) { if (!S.liveAt(SI)) { - auto PrevMask = It.second; - It.second &= ~S.LaneMask; - CurPressure.inc(It.first, PrevMask, It.second, *MRI); + if (It == LiveRegs.end()) { + It = LiveRegs.find(MO.getReg()); + if (It == LiveRegs.end()) + llvm_unreachable("register isn't live"); + } + auto PrevMask = It->second; + It->second &= ~S.LaneMask; + CurPressure.inc(MO.getReg(), PrevMask, It->second, *MRI); } } + if (It != LiveRegs.end() && It->second.none()) + LiveRegs.erase(It); } else if (!LI.liveAt(SI)) { - auto PrevMask = It.second; - It.second = LaneBitmask::getNone(); - CurPressure.inc(It.first, PrevMask, It.second, *MRI); + auto It = LiveRegs.find(MO.getReg()); + if (It == LiveRegs.end()) + llvm_unreachable("register isn't live"); + CurPressure.inc(MO.getReg(), It->second, LaneBitmask::getNone(), *MRI); + LiveRegs.erase(It); } - if (It.second.none()) - LiveRegs.erase(It.first); } MaxPressure = max(MaxPressure, CurPressure); diff --git a/llvm/test/CodeGen/AMDGPU/scheduler-rp-calc-one-successor-two-predecessors-bug.ll b/llvm/test/CodeGen/AMDGPU/scheduler-rp-calc-one-successor-two-predecessors-bug.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/scheduler-rp-calc-one-successor-two-predecessors-bug.ll @@ -0,0 +1,31 @@ +; RUN: llc -march=amdgcn -mcpu=gfx900 < %s + +declare void @llvm.amdgcn.kill(i1) +declare <4 x float> @llvm.amdgcn.image.sample.2d.v4f32.f32(i32 immarg, float, float, <8 x i32>, <4 x i32>, i1 immarg, i32 immarg, i32 immarg) +declare <2 x half> @llvm.amdgcn.cvt.pkrtz(float, float) +declare void @llvm.amdgcn.exp.compr.v2f16(i32 immarg, i32 immarg, <2 x half>, <2 x half>, i1 immarg, i1 immarg) + +define amdgpu_ps void @_amdgpu_ps_main(float %arg) { +bb: + %i = fcmp olt float %arg, 0.000000e+00 + br i1 %i, label %bb5, label %bb1 + +bb1: + %i2 = call <4 x float> @llvm.amdgcn.image.sample.2d.v4f32.f32(i32 15, float 0.000000e+00, float %arg, <8 x i32> zeroinitializer, <4 x i32> zeroinitializer, i1 false, i32 0, i32 0) + %i3 = extractelement <4 x float> %i2, i64 1 + %i4 = extractelement <4 x float> %i2, i64 0 + br label %bb6 + +bb5: + call void @llvm.amdgcn.kill(i1 false) + br label %bb6 + +bb6: + %i7 = phi float [ 0.000000e+00, %bb5 ], [ %i3, %bb1 ] + %i8 = phi float [ 0.000000e+00, %bb5 ], [ 1.000000e+00, %bb1 ] + %i9 = phi float [ undef, %bb5 ], [ %i4, %bb1 ] + %i10 = call <2 x half> @llvm.amdgcn.cvt.pkrtz(float 0.000000e+00, float %i7) + %i11 = call <2 x half> @llvm.amdgcn.cvt.pkrtz(float %i8, float %i9) + call void @llvm.amdgcn.exp.compr.v2f16(i32 0, i32 0, <2 x half> %i10, <2 x half> %i11, i1 false, i1 false) + ret void +}