[llvm] b9e328f - [InstCombine] Fix worklist management in rewriteGEPAsOffset() more thoroughly

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 02:00:57 PDT 2023


Author: Nikita Popov
Date: 2023-06-01T11:00:49+02:00
New Revision: b9e328fd9113327f3d5c775f367cc3f4bc2f080f

URL: https://github.com/llvm/llvm-project/commit/b9e328fd9113327f3d5c775f367cc3f4bc2f080f
DIFF: https://github.com/llvm/llvm-project/commit/b9e328fd9113327f3d5c775f367cc3f4bc2f080f.diff

LOG: [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.

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 d0bff3a6a540..7fb3f16b346b 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<Instruction>(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<Instruction>(Val));
   }
 
   return NewInsts[Start];


        


More information about the llvm-commits mailing list