From b9e328fd9113327f3d5c775f367cc3f4bc2f080f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 1 Jun 2023 10:58:58 +0200 Subject: [PATCH] [InstCombine] Fix worklist management in rewriteGEPAsOffset() more thoroughly We need to add the replaced instruction itself to the worklist as well. We want to remove the old instructions, but can't easily do so directly, as the icmp is also one of the users and we need to retain it until the fold has finished. --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index d0bff3a..7fb3f16 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -638,6 +638,9 @@ static Value *rewriteGEPAsOffset(Type *ElemTy, Value *Start, Value *Base, NewVal = Builder.CreateBitOrPointerCast( NewVal, Val->getType(), Val->getName() + ".conv"); IC.replaceInstUsesWith(*cast(Val), NewVal); + // Add old instruction to worklist for DCE. We don't directly remove it + // here because the original compare is one of the users. + IC.addToWorklist(cast(Val)); } return NewInsts[Start]; -- 2.7.4