[llvm] LiveRangeEdit: Replace setIsDead with an assert (PR #92964)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 14:08:21 PDT 2024


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/92964

I noticed this was possibly buggy with implicit operands with the same dest register, and should maybe be using addRegisterDead. However, this is never called in a situation where the operand wasn't already marked dead. This is eliminateDeadDef, implying the def was already known to be dead.

Add an assert to detect inconsistencies in dead flags. This was apparently added in 9a16d655c71826bef98b7d6e9590e4494ac0e1a9.

>From 04a9f153f40a1b5f361aebe1fd3a238b5014add2 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 21 May 2024 23:03:55 +0200
Subject: [PATCH] LiveRangeEdit: Replace setIsDead with an assert

I noticed this was possibly buggy with implicit operands with the same
dest register, and should maybe be using addRegisterDead. However,
this is never called in a situation where the operand wasn't already marked
dead. This is eliminateDeadDef, implying the def was already known to be dead.

Add an assert to detect inconsistencies in dead flags.
---
 llvm/lib/CodeGen/LiveRangeEdit.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp
index 643370f0573d1..7b7b5459ad7b2 100644
--- a/llvm/lib/CodeGen/LiveRangeEdit.cpp
+++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp
@@ -414,7 +414,7 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) {
       DeadRemats->insert(MI);
       const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
       MI->substituteRegister(Dest, NewLI.reg(), 0, TRI);
-      MI->getOperand(0).setIsDead(true);
+      assert(MI->registerDefIsDead(NewLI.reg(), &TRI));
     } else {
       if (TheDelegate)
         TheDelegate->LRE_WillEraseInstruction(MI);



More information about the llvm-commits mailing list