[llvm] [InstCombine] Directly add negated instructions to the worklist (PR #226118)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 24 04:06:16 PDT 2026
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/226118
This code was doing something really confusing: Resetting the
insertion point and debug location and then inserting the
instructions -- which should be a no-op. It turns out that the
purpose of this code is to invoke the InstCombine IRBuilder
insertion callback, which will add these instructions to the
worklist.
Instead of going through these contortions, directly add the
new instructions to the worklist.
>From b088e7bb294d942cfe13a92345f37779ec0e1181 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 24 Sep 2026 12:52:26 +0200
Subject: [PATCH] [InstCombine] Directly add negated instructions to the
worklist
This code was doing something really confusing: Resetting the
insertion point and debug location and then inserting the
instructions -- which should be a no-op. It turns out that the
purpose of this code is to invoke the InstCombine IRBuilder
insertion callback, which will add these instructions to the
worklist.
Instead of going through these contortions, directly add the
new instructions to the worklist.
---
llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
index 32d07113b3939a..ed31a7cdab3c47 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
@@ -571,13 +571,6 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
<< "\n NEW: " << *Res->second << "\n");
++NegatorNumTreesNegated;
- // We must temporarily unset the 'current' insertion point and DebugLoc of the
- // InstCombine's IRBuilder so that it won't interfere with the ones we have
- // already specified when producing negated instructions.
- InstCombiner::BuilderTy::InsertPointGuard Guard(IC.Builder);
- IC.Builder.ClearInsertionPoint();
- IC.Builder.SetCurrentDebugLocation(DebugLoc());
-
// And finally, we must add newly-created instructions into the InstCombine's
// worklist (in a proper order!) so it can attempt to combine them.
LLVM_DEBUG(dbgs() << "Negator: Propagating " << Res->first.size()
@@ -585,9 +578,8 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
NegatorMaxInstructionsCreated.updateMax(Res->first.size());
NegatorNumInstructionsNegatedSuccess += Res->first.size();
- // They are in def-use order, so nothing fancy, just insert them in order.
for (Instruction *I : Res->first)
- IC.Builder.Insert(I, I->getName());
+ IC.addToWorklist(I);
// And return the new root.
return Res->second;
More information about the llvm-commits
mailing list