@@ -1768,15 +1768,14 @@ class GeneratedRTChecks {
17681768 BasicBlock *SCEVCheckBlock = nullptr ;
17691769
17701770 // / 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.
17721772 Value *SCEVCheckCond = nullptr ;
17731773
17741774 // / Basic block which contains the generated memory runtime checks, if any.
17751775 BasicBlock *MemCheckBlock = nullptr ;
17761776
17771777 // / 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.
17801779 Value *MemRuntimeCheckCond = nullptr ;
17811780
17821781 // / True if any checks have been added.
@@ -1996,13 +1995,14 @@ class GeneratedRTChecks {
19961995 ~GeneratedRTChecks () {
19971996 SCEVExpanderCleaner SCEVCleaner (SCEVExp);
19981997 SCEVExpanderCleaner MemCheckCleaner (MemCheckExp);
1999- if (!SCEVCheckCond)
1998+ bool SCEVChecksUsed = !SCEVCheckBlock || !pred_empty (SCEVCheckBlock);
1999+ bool MemChecksUsed = !MemCheckBlock || !pred_empty (MemCheckBlock);
2000+ if (SCEVChecksUsed)
20002001 SCEVCleaner.markResultUsed ();
20012002
2002- if (!MemRuntimeCheckCond)
2003+ if (MemChecksUsed) {
20032004 MemCheckCleaner.markResultUsed ();
2004-
2005- if (MemRuntimeCheckCond) {
2005+ } else {
20062006 auto &SE = *MemCheckExp.getSE ();
20072007 // Memory runtime check generation creates compares that use expanded
20082008 // values. Remove them before running the SCEVExpanderCleaners.
@@ -2016,9 +2016,9 @@ class GeneratedRTChecks {
20162016 MemCheckCleaner.cleanup ();
20172017 SCEVCleaner.cleanup ();
20182018
2019- if (SCEVCheckCond )
2019+ if (!SCEVChecksUsed )
20202020 SCEVCheckBlock->eraseFromParent ();
2021- if (MemRuntimeCheckCond )
2021+ if (!MemChecksUsed )
20222022 MemCheckBlock->eraseFromParent ();
20232023 }
20242024
@@ -2044,8 +2044,6 @@ class GeneratedRTChecks {
20442044 if (AddBranchWeights)
20452045 setBranchWeights (BI, SCEVCheckBypassWeights, /* IsExpected=*/ false );
20462046 ReplaceInstWithInst (SCEVCheckBlock->getTerminator (), &BI);
2047- // Mark the check as used, to prevent it from being removed during cleanup.
2048- SCEVCheckCond = nullptr ;
20492047 AddedAnyChecks = true ;
20502048 return SCEVCheckBlock;
20512049 }
@@ -2074,8 +2072,6 @@ class GeneratedRTChecks {
20742072 MemCheckBlock->getTerminator ()->setDebugLoc (
20752073 Pred->getTerminator ()->getDebugLoc ());
20762074
2077- // Mark the check as used, to prevent it from being removed during cleanup.
2078- MemRuntimeCheckCond = nullptr ;
20792075 AddedAnyChecks = true ;
20802076 return MemCheckBlock;
20812077 }
0 commit comments