@@ -787,43 +787,47 @@ bool MemCpyOptPass::processStore(StoreInst *SI, BasicBlock::iterator &BBI) {
787787 // Ensure that the value being stored is something that can be memset'able a
788788 // byte at a time like "0" or "-1" or any width, as well as things like
789789 // 0xA0A0A0A0 and 0.0.
790- auto *V = SI->getOperand (0 );
791- if (Value *ByteVal = isBytewiseValue (V, DL)) {
792- if (Instruction *I =
793- tryMergingIntoMemset (SI, SI->getPointerOperand (), ByteVal)) {
794- BBI = I->getIterator (); // Don't invalidate iterator.
795- return true ;
796- }
790+ Value *V = SI->getOperand (0 );
791+ Value *ByteVal = isBytewiseValue (V, DL);
792+ if (!ByteVal)
793+ return false ;
797794
798- // If we have an aggregate, we try to promote it to memset regardless
799- // of opportunity for merging as it can expose optimization opportunities
800- // in subsequent passes.
801- auto *T = V->getType ();
802- if (T->isAggregateType ()) {
803- uint64_t Size = DL.getTypeStoreSize (T);
804- IRBuilder<> Builder (SI);
805- auto *M = Builder.CreateMemSet (SI->getPointerOperand (), ByteVal, Size,
806- SI->getAlign ());
807- M->copyMetadata (*SI, LLVMContext::MD_DIAssignID);
795+ if (Instruction *I =
796+ tryMergingIntoMemset (SI, SI->getPointerOperand (), ByteVal)) {
797+ BBI = I->getIterator (); // Don't invalidate iterator.
798+ return true ;
799+ }
800+
801+ // If we have an aggregate, we try to promote it to memset regardless
802+ // of opportunity for merging as it can expose optimization opportunities
803+ // in subsequent passes.
804+ auto *T = V->getType ();
805+ if (!T->isAggregateType ())
806+ return false ;
808807
809- LLVM_DEBUG (dbgs () << " Promoting " << *SI << " to " << *M << " \n " );
808+ TypeSize Size = DL.getTypeStoreSize (T);
809+ if (Size.isScalable ())
810+ return false ;
810811
811- // The newly inserted memset is immediately overwritten by the original
812- // store, so we do not need to rename uses.
813- auto *StoreDef = cast<MemoryDef>(MSSA->getMemoryAccess (SI));
814- auto *NewAccess = MSSAU->createMemoryAccessBefore (M, nullptr , StoreDef);
815- MSSAU->insertDef (cast<MemoryDef>(NewAccess), /* RenameUses=*/ false );
812+ IRBuilder<> Builder (SI);
813+ auto *M = Builder.CreateMemSet (SI->getPointerOperand (), ByteVal, Size,
814+ SI->getAlign ());
815+ M->copyMetadata (*SI, LLVMContext::MD_DIAssignID);
816816
817- eraseInstruction (SI);
818- NumMemSetInfer++;
817+ LLVM_DEBUG (dbgs () << " Promoting " << *SI << " to " << *M << " \n " );
819818
820- // Make sure we do not invalidate the iterator.
821- BBI = M-> getIterator ();
822- return true ;
823- }
824- }
819+ // The newly inserted memset is immediately overwritten by the original
820+ // store, so we do not need to rename uses.
821+ auto *StoreDef = cast<MemoryDef>(MSSA-> getMemoryAccess (SI)) ;
822+ auto *NewAccess = MSSAU-> createMemoryAccessBefore (M, nullptr , StoreDef);
823+ MSSAU-> insertDef (cast<MemoryDef>(NewAccess), /* RenameUses= */ false );
825824
826- return false ;
825+ eraseInstruction (SI);
826+ NumMemSetInfer++;
827+
828+ // Make sure we do not invalidate the iterator.
829+ BBI = M->getIterator ();
830+ return true ;
827831}
828832
829833bool MemCpyOptPass::processMemSet (MemSetInst *MSI, BasicBlock::iterator &BBI) {
0 commit comments