[llvm] 63babf5 - [InstCombine] Fix worklist management in transformToIndexedCompare()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 1 01:35:21 PDT 2023
Author: Nikita Popov
Date: 2023-06-01T10:35:13+02:00
New Revision: 63babf54c22ab2045082b03d6794fac0738cad25
URL: https://github.com/llvm/llvm-project/commit/63babf54c22ab2045082b03d6794fac0738cad25
DIFF: https://github.com/llvm/llvm-project/commit/63babf54c22ab2045082b03d6794fac0738cad25.diff
LOG: [InstCombine] Fix worklist management in transformToIndexedCompare()
Use replaceInstUsesWith() rather than plain RAUW to make sure the
old instructions are added back to the worklist for DCE.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 462e65d8e7d6..d0bff3a6a540 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -534,7 +534,8 @@ static void setInsertionPoint(IRBuilder<> &Builder, Value *V,
/// pointer.
static Value *rewriteGEPAsOffset(Type *ElemTy, Value *Start, Value *Base,
const DataLayout &DL,
- SetVector<Value *> &Explored) {
+ SetVector<Value *> &Explored,
+ InstCombiner &IC) {
// Perform all the substitutions. This is a bit tricky because we can
// have cycles in our use-def chains.
// 1. Create the PHI nodes without any incoming values.
@@ -636,7 +637,7 @@ static Value *rewriteGEPAsOffset(Type *ElemTy, Value *Start, Value *Base,
Val->getName() + ".ptr");
NewVal = Builder.CreateBitOrPointerCast(
NewVal, Val->getType(), Val->getName() + ".conv");
- Val->replaceAllUsesWith(NewVal);
+ IC.replaceInstUsesWith(*cast<Instruction>(Val), NewVal);
}
return NewInsts[Start];
@@ -689,7 +690,8 @@ getAsConstantIndexedAddress(Type *ElemTy, Value *V, const DataLayout &DL) {
/// between GEPLHS and RHS.
static Instruction *transformToIndexedCompare(GEPOperator *GEPLHS, Value *RHS,
ICmpInst::Predicate Cond,
- const DataLayout &DL) {
+ const DataLayout &DL,
+ InstCombiner &IC) {
// FIXME: Support vector of pointers.
if (GEPLHS->getType()->isVectorTy())
return nullptr;
@@ -713,7 +715,7 @@ static Instruction *transformToIndexedCompare(GEPOperator *GEPLHS, Value *RHS,
// can't have overflow on either side. We can therefore re-write
// this as:
// OFFSET1 cmp OFFSET2
- Value *NewRHS = rewriteGEPAsOffset(ElemTy, RHS, PtrBase, DL, Nodes);
+ Value *NewRHS = rewriteGEPAsOffset(ElemTy, RHS, PtrBase, DL, Nodes, IC);
// RewriteGEPAsOffset has replaced RHS and all of its uses with a re-written
// GEP having PtrBase as the pointer base, and has returned in NewRHS the
@@ -832,7 +834,7 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
// Otherwise, the base pointers are
diff erent and the indices are
//
diff erent. Try convert this to an indexed compare by looking through
// PHIs/casts.
- return transformToIndexedCompare(GEPLHS, RHS, Cond, DL);
+ return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this);
}
// If one of the GEPs has all zero indices, recurse.
@@ -896,7 +898,7 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
// Try convert this to an indexed compare by looking through PHIs/casts as a
// last resort.
- return transformToIndexedCompare(GEPLHS, RHS, Cond, DL);
+ return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this);
}
bool InstCombinerImpl::foldAllocaCmp(AllocaInst *Alloca) {
More information about the llvm-commits
mailing list