[llvm] [SPIRV] In G_SELECT selection path: replace `removeFromParent` with `eraseFromParent` and return early (PR #184807)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 5 07:16:07 PST 2026
https://github.com/jmmartinez created https://github.com/llvm/llvm-project/pull/184807
When selecting an `ASSIGN_TYPE` of a `G_SELECT`, both instructions were removed but not erased.
The code followed on a code path where the replaced G_SELECT would be added to a remove set if it was dead. But the select is not in the function anymore since it is already removed!
Selecting a `selectSelect` always returns `true`. So the assertions/prints below would have never been triggered.
This patch simplifies this code path to avoid falling through the asserts and paths where `selectSelect` could have failed (which trivially doesn't happen).
Guarded `selectSelect` return with an assert in case it changes.
>From 9cfa6ae53dae1ab84dbb4df5d9f3d2aabcc2ee00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?=
<jmartinezcaamao at gmail.com>
Date: Thu, 5 Mar 2026 15:28:13 +0100
Subject: [PATCH] [SPIRV] Replace `removeFromParent` with `eraseFromParent` and
return early in G_SELECT selection
When selecting an ASSIGN_TYPE of a G_SELECT, both instructions were
removed but not erased.
The code followed on a code path where the replaced G_SELECT would be
added to a remove set if it was dead. But the select is not in the
function anymore since it is already removed!
Selecting a `selectSelect` always returns `true`. So the
assertions/prints below would have never been triggered.
This patch simplifies this code path to avoid falling through the
asserts and paths where `selectSelect` could have failed (which
trivially doens't happen).
Guarded `selectSelect` return with an assert in case it changes.
---
.../Target/SPIRV/SPIRVInstructionSelector.cpp | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index fd5e869279fe6..e2b0b5abcd5ff 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -794,18 +794,20 @@ bool SPIRVInstructionSelector::select(MachineInstr &I) {
if (isTypeFoldingSupported(Def->getOpcode()) &&
Def->getOpcode() != TargetOpcode::G_CONSTANT &&
Def->getOpcode() != TargetOpcode::G_FCONSTANT) {
- bool Res = false;
if (Def->getOpcode() == TargetOpcode::G_SELECT) {
Register SelectDstReg = Def->getOperand(0).getReg();
- Res = selectSelect(SelectDstReg, GR.getSPIRVTypeForVReg(SelectDstReg),
- *Def);
+ bool SuccessToSelectSelect [[maybe_unused]] = selectSelect(
+ SelectDstReg, GR.getSPIRVTypeForVReg(SelectDstReg), *Def);
+ assert(SuccessToSelectSelect);
GR.invalidateMachineInstr(Def);
- Def->removeFromParent();
+ Def->eraseFromParent();
MRI->replaceRegWith(DstReg, SelectDstReg);
GR.invalidateMachineInstr(&I);
- I.removeFromParent();
- } else
- Res = selectImpl(I, *CoverageInfo);
+ I.eraseFromParent();
+ return true;
+ }
+
+ bool Res = selectImpl(I, *CoverageInfo);
LLVM_DEBUG({
if (!Res && Def->getOpcode() != TargetOpcode::G_CONSTANT) {
dbgs() << "Unexpected pattern in ASSIGN_TYPE.\nInstruction: ";
More information about the llvm-commits
mailing list