[llvm] 573f741 - [NFC][ScalarizeMaskedMemIntrin] scalarizeMaskedCompressStore(): port to SplitBlockAndInsertIfThen()

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 28 14:12:19 PST 2021


Author: Roman Lebedev
Date: 2021-01-29T01:11:35+03:00
New Revision: 573f74117b1a4a8f17bceccd8abd908eb019c385

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

LOG: [NFC][ScalarizeMaskedMemIntrin] scalarizeMaskedCompressStore(): port to SplitBlockAndInsertIfThen()

Makes Dominator Tree preservation in a followup patch somewhat easier.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
index 85ac37d9cd11..d38c5d5fe952 100644
--- a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
+++ b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
@@ -801,10 +801,13 @@ static void scalarizeMaskedCompressStore(CallInst *CI, bool &ModifiedDT) {
     //  %EltAddr = getelementptr i32* %1, i32 0
     //  %store i32 %OneElt, i32* %EltAddr
     //
-    BasicBlock *CondBlock =
-        IfBlock->splitBasicBlock(InsertPt->getIterator(), "cond.store");
-    Builder.SetInsertPoint(InsertPt);
+    Instruction *ThenTerm =
+        SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false);
+
+    BasicBlock *CondBlock = ThenTerm->getParent();
+    CondBlock->setName("cond.store");
 
+    Builder.SetInsertPoint(CondBlock->getTerminator());
     Value *OneElt = Builder.CreateExtractElement(Src, Idx);
     Builder.CreateAlignedStore(OneElt, Ptr, Align(1));
 
@@ -814,15 +817,13 @@ static void scalarizeMaskedCompressStore(CallInst *CI, bool &ModifiedDT) {
       NewPtr = Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, 1);
 
     // Create "else" block, fill it in the next iteration
-    BasicBlock *NewIfBlock =
-        CondBlock->splitBasicBlock(InsertPt->getIterator(), "else");
-    Builder.SetInsertPoint(InsertPt);
-    Instruction *OldBr = IfBlock->getTerminator();
-    BranchInst::Create(CondBlock, NewIfBlock, Predicate, OldBr);
-    OldBr->eraseFromParent();
+    BasicBlock *NewIfBlock = ThenTerm->getSuccessor(0);
+    NewIfBlock->setName("else");
     BasicBlock *PrevIfBlock = IfBlock;
     IfBlock = NewIfBlock;
 
+    Builder.SetInsertPoint(NewIfBlock, NewIfBlock->begin());
+
     // Add a PHI for the pointer if this isn't the last iteration.
     if ((Idx + 1) != VectorWidth) {
       PHINode *PtrPhi = Builder.CreatePHI(Ptr->getType(), 2, "ptr.phi.else");


        


More information about the llvm-commits mailing list