@@ -295,6 +295,31 @@ static void deleteDeadInstruction(Instruction *I) {
295
295
I->eraseFromParent ();
296
296
}
297
297
298
+ namespace {
299
+ class ExpandedValuesCleaner {
300
+ SCEVExpander &Expander;
301
+ TargetLibraryInfo *TLI;
302
+ SmallVector<Value *, 4 > ExpandedValues;
303
+ bool Commit = false ;
304
+
305
+ public:
306
+ ExpandedValuesCleaner (SCEVExpander &Expander, TargetLibraryInfo *TLI)
307
+ : Expander(Expander), TLI(TLI) {}
308
+
309
+ void add (Value *V) { ExpandedValues.push_back (V); }
310
+
311
+ void commit () { Commit = true ; }
312
+
313
+ ~ExpandedValuesCleaner () {
314
+ if (!Commit) {
315
+ Expander.clear ();
316
+ for (auto *V : ExpandedValues)
317
+ RecursivelyDeleteTriviallyDeadInstructions (V, TLI);
318
+ }
319
+ }
320
+ };
321
+ } // namespace
322
+
298
323
// ===----------------------------------------------------------------------===//
299
324
//
300
325
// Implementation of LoopIdiomRecognize
@@ -908,6 +933,7 @@ bool LoopIdiomRecognize::processLoopStridedStore(
908
933
BasicBlock *Preheader = CurLoop->getLoopPreheader ();
909
934
IRBuilder<> Builder (Preheader->getTerminator ());
910
935
SCEVExpander Expander (*SE, *DL, " loop-idiom" );
936
+ ExpandedValuesCleaner EVC (Expander, TLI);
911
937
912
938
Type *DestInt8PtrTy = Builder.getInt8PtrTy (DestAS);
913
939
Type *IntIdxTy = DL->getIndexType (DestPtr->getType ());
@@ -930,6 +956,7 @@ bool LoopIdiomRecognize::processLoopStridedStore(
930
956
// base pointer and checking the region.
931
957
Value *BasePtr =
932
958
Expander.expandCodeFor (Start, DestInt8PtrTy, Preheader->getTerminator ());
959
+ EVC.add (BasePtr);
933
960
934
961
// From here on out, conservatively report to the pass manager that we've
935
962
// changed the IR, even if we later clean up these added instructions. There
@@ -941,12 +968,8 @@ bool LoopIdiomRecognize::processLoopStridedStore(
941
968
Changed = true ;
942
969
943
970
if (mayLoopAccessLocation (BasePtr, ModRefInfo::ModRef, CurLoop, BECount,
944
- StoreSize, *AA, Stores)) {
945
- Expander.clear ();
946
- // If we generated new code for the base pointer, clean up.
947
- RecursivelyDeleteTriviallyDeadInstructions (BasePtr, TLI);
971
+ StoreSize, *AA, Stores))
948
972
return Changed;
949
- }
950
973
951
974
if (avoidLIRForMultiBlockLoop (/* IsMemset=*/ true , IsLoopMemset))
952
975
return Changed;
@@ -1018,34 +1041,10 @@ bool LoopIdiomRecognize::processLoopStridedStore(
1018
1041
if (MSSAU && VerifyMemorySSA)
1019
1042
MSSAU->getMemorySSA ()->verifyMemorySSA ();
1020
1043
++NumMemSet;
1044
+ EVC.commit ();
1021
1045
return true ;
1022
1046
}
1023
1047
1024
- namespace {
1025
- class ExpandedValuesCleaner {
1026
- SCEVExpander &Expander;
1027
- TargetLibraryInfo *TLI;
1028
- SmallVector<Value *, 4 > ExpandedValues;
1029
- bool Commit = false ;
1030
-
1031
- public:
1032
- ExpandedValuesCleaner (SCEVExpander &Expander, TargetLibraryInfo *TLI)
1033
- : Expander(Expander), TLI(TLI) {}
1034
-
1035
- void add (Value *V) { ExpandedValues.push_back (V); }
1036
-
1037
- void commit () { Commit = true ; }
1038
-
1039
- ~ExpandedValuesCleaner () {
1040
- if (!Commit) {
1041
- Expander.clear ();
1042
- for (auto *V : ExpandedValues)
1043
- RecursivelyDeleteTriviallyDeadInstructions (V, TLI);
1044
- }
1045
- }
1046
- };
1047
- } // namespace
1048
-
1049
1048
// / If the stored value is a strided load in the same loop with the same stride
1050
1049
// / this may be transformable into a memcpy. This kicks in for stuff like
1051
1050
// / for (i) A[i] = B[i];
0 commit comments