[llvm] [CodeGen] Avoid quadratic operand removal in MachineInstr::insert (PR #220165)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 23:47:11 PDT 2026
https://github.com/LittleJianCH updated https://github.com/llvm/llvm-project/pull/220165
>From cf2f33b6cad072d0192852df11c0321de0742cd1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=AE=80?= <chenhowe0529 at gmail.com>
Date: Tue, 1 Sep 2026 13:49:10 +0800
Subject: [PATCH] [CodeGen] Avoid quadratic operand removal in
MachineInstr::insert
---
llvm/lib/CodeGen/MachineInstr.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index e94de37261c53..3b401ae576f43 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -2740,9 +2740,11 @@ void MachineInstr::insert(mop_iterator InsertBefore,
SmallVector<MachineOperand> MovingOps;
MovingOps.reserve(OpsToMove);
- for (unsigned I = 0; I < OpsToMove; ++I) {
- MovingOps.emplace_back(getOperand(OpIdx));
- removeOperand(OpIdx);
+ for (unsigned I = OpIdx; I < NumOperands; ++I) {
+ MovingOps.emplace_back(getOperand(I));
+ }
+ while (getNumOperands() != OpIdx) {
+ removeOperand(getNumOperands() - 1);
}
for (const MachineOperand &MO : Ops)
addOperand(MO);
More information about the llvm-commits
mailing list