[llvm] 4b83208 - [InstCombine] Remove dead extractelements (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 06:40:57 PDT 2023


Author: Nikita Popov
Date: 2023-05-23T15:40:48+02:00
New Revision: 4b8320868c9e32d1448c81ca76dba2a6b9f374cd

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

LOG: [InstCombine] Remove dead extractelements (NFCI)

Directly remove these dead extractelement instructions, rather than
leaving them for the next InstCombine iteration to clean up.

Should be mostly NFC, apart from worklist order differences.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 00fc8b1c03b5..5bcbf8fec840 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -743,13 +743,15 @@ static void replaceExtractElements(InsertElementInst *InsElt,
 
   // Replace extracts from the original narrow vector with extracts from the new
   // wide vector.
-  for (User *U : ExtVecOp->users()) {
+  SmallVector<User *> Users(ExtVecOp->users());
+  for (User *U : Users) {
     ExtractElementInst *OldExt = dyn_cast<ExtractElementInst>(U);
     if (!OldExt || OldExt->getParent() != WideVec->getParent())
       continue;
     auto *NewExt = ExtractElementInst::Create(WideVec, OldExt->getOperand(1));
     NewExt->insertAfter(OldExt);
     IC.replaceInstUsesWith(*OldExt, NewExt);
+    IC.eraseInstFromFunction(*OldExt);
   }
 }
 


        


More information about the llvm-commits mailing list