[PATCH] D71093: [InstCombine] Insert instructions before adding them to worklist
Jakub Kuderski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 18 12:05:14 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d29c41ad59e: [InstCombine] Insert instructions before adding them to worklist (authored by kuhar).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71093/new/
https://reviews.llvm.org/D71093
Files:
llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/zext-or-icmp.ll
Index: llvm/test/Transforms/InstCombine/zext-or-icmp.ll
===================================================================
--- llvm/test/Transforms/InstCombine/zext-or-icmp.ll
+++ llvm/test/Transforms/InstCombine/zext-or-icmp.ll
@@ -15,7 +15,7 @@
; CHECK-NEXT: %toBool2 = icmp eq i8 %b, 0
; CHECK-NEXT: %toBool22 = zext i1 %toBool2 to i8
; CHECK-NEXT: %1 = xor i8 %mask, 1
-; CHECK-NEXT: %zext = or i8 %1, %toBool22
+; CHECK-NEXT: %zext3 = or i8 %1, %toBool22
; CHECK-NEXT: ret i8 %zext
}
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3361,10 +3361,6 @@
// Move the name to the new instruction first.
Result->takeName(I);
- // Push the new instruction and any users onto the worklist.
- Worklist.AddUsersToWorkList(*Result);
- Worklist.Add(Result);
-
// Insert the new instruction into the basic block...
BasicBlock *InstParent = I->getParent();
BasicBlock::iterator InsertPos = I->getIterator();
@@ -3376,6 +3372,10 @@
InstParent->getInstList().insert(InsertPos, Result);
+ // Push the new instruction and any users onto the worklist.
+ Worklist.AddUsersToWorkList(*Result);
+ Worklist.Add(Result);
+
eraseInstFromFunction(*I);
} else {
LLVM_DEBUG(dbgs() << "IC: Mod = " << OrigI << '\n'
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1189,7 +1189,9 @@
// zext (or icmp, icmp) -> or (zext icmp), (zext icmp)
Value *LCast = Builder.CreateZExt(LHS, CI.getType(), LHS->getName());
Value *RCast = Builder.CreateZExt(RHS, CI.getType(), RHS->getName());
- BinaryOperator *Or = BinaryOperator::Create(Instruction::Or, LCast, RCast);
+ Value *Or = Builder.CreateOr(LCast, RCast, CI.getName());
+ if (auto *OrInst = dyn_cast<Instruction>(Or))
+ Builder.SetInsertPoint(OrInst);
// Perform the elimination.
if (auto *LZExt = dyn_cast<ZExtInst>(LCast))
@@ -1197,7 +1199,7 @@
if (auto *RZExt = dyn_cast<ZExtInst>(RCast))
transformZExtICmp(RHS, *RZExt);
- return Or;
+ return replaceInstUsesWith(CI, Or);
}
}
Index: llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
===================================================================
--- llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
+++ llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
@@ -24,8 +24,8 @@
/// InstCombineWorklist - This is the worklist management logic for
/// InstCombine.
class InstCombineWorklist {
- SmallVector<Instruction*, 256> Worklist;
- DenseMap<Instruction*, unsigned> WorklistMap;
+ SmallVector<Instruction *, 256> Worklist;
+ DenseMap<Instruction *, unsigned> WorklistMap;
public:
InstCombineWorklist() = default;
@@ -38,6 +38,9 @@
/// Add - Add the specified instruction to the worklist if it isn't already
/// in it.
void Add(Instruction *I) {
+ assert(I);
+ assert(I->getParent() && "Instruction not inserted yet?");
+
if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) {
LLVM_DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
Worklist.push_back(I);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71093.234594.patch
Type: text/x-patch
Size: 3581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191218/23dd383c/attachment.bin>
More information about the llvm-commits
mailing list