@@ -1768,15 +1768,14 @@ class GeneratedRTChecks {
1768
1768
BasicBlock *SCEVCheckBlock = nullptr ;
1769
1769
1770
1770
// / The value representing the result of the generated SCEV checks. If it is
1771
- // / nullptr, either no SCEV checks have been generated or they have been used .
1771
+ // / nullptr no SCEV checks have been generated.
1772
1772
Value *SCEVCheckCond = nullptr ;
1773
1773
1774
1774
// / Basic block which contains the generated memory runtime checks, if any.
1775
1775
BasicBlock *MemCheckBlock = nullptr ;
1776
1776
1777
1777
// / The value representing the result of the generated memory runtime checks.
1778
- // / If it is nullptr, either no memory runtime checks have been generated or
1779
- // / they have been used.
1778
+ // / If it is nullptr no memory runtime checks have been generated.
1780
1779
Value *MemRuntimeCheckCond = nullptr ;
1781
1780
1782
1781
// / True if any checks have been added.
@@ -1996,13 +1995,14 @@ class GeneratedRTChecks {
1996
1995
~GeneratedRTChecks () {
1997
1996
SCEVExpanderCleaner SCEVCleaner (SCEVExp);
1998
1997
SCEVExpanderCleaner MemCheckCleaner (MemCheckExp);
1999
- if (!SCEVCheckCond)
1998
+ bool SCEVChecksUsed = !SCEVCheckBlock || !pred_empty (SCEVCheckBlock);
1999
+ bool MemChecksUsed = !MemCheckBlock || !pred_empty (MemCheckBlock);
2000
+ if (SCEVChecksUsed)
2000
2001
SCEVCleaner.markResultUsed ();
2001
2002
2002
- if (!MemRuntimeCheckCond)
2003
+ if (MemChecksUsed) {
2003
2004
MemCheckCleaner.markResultUsed ();
2004
-
2005
- if (MemRuntimeCheckCond) {
2005
+ } else {
2006
2006
auto &SE = *MemCheckExp.getSE ();
2007
2007
// Memory runtime check generation creates compares that use expanded
2008
2008
// values. Remove them before running the SCEVExpanderCleaners.
@@ -2016,9 +2016,9 @@ class GeneratedRTChecks {
2016
2016
MemCheckCleaner.cleanup ();
2017
2017
SCEVCleaner.cleanup ();
2018
2018
2019
- if (SCEVCheckCond )
2019
+ if (!SCEVChecksUsed )
2020
2020
SCEVCheckBlock->eraseFromParent ();
2021
- if (MemRuntimeCheckCond )
2021
+ if (!MemChecksUsed )
2022
2022
MemCheckBlock->eraseFromParent ();
2023
2023
}
2024
2024
@@ -2044,8 +2044,6 @@ class GeneratedRTChecks {
2044
2044
if (AddBranchWeights)
2045
2045
setBranchWeights (BI, SCEVCheckBypassWeights, /* IsExpected=*/ false );
2046
2046
ReplaceInstWithInst (SCEVCheckBlock->getTerminator (), &BI);
2047
- // Mark the check as used, to prevent it from being removed during cleanup.
2048
- SCEVCheckCond = nullptr ;
2049
2047
AddedAnyChecks = true ;
2050
2048
return SCEVCheckBlock;
2051
2049
}
@@ -2074,8 +2072,6 @@ class GeneratedRTChecks {
2074
2072
MemCheckBlock->getTerminator ()->setDebugLoc (
2075
2073
Pred->getTerminator ()->getDebugLoc ());
2076
2074
2077
- // Mark the check as used, to prevent it from being removed during cleanup.
2078
- MemRuntimeCheckCond = nullptr ;
2079
2075
AddedAnyChecks = true ;
2080
2076
return MemCheckBlock;
2081
2077
}
0 commit comments