@@ -321,6 +321,24 @@ class TypePromotionTransaction;
321
321
}
322
322
323
323
private:
324
+ template <typename F>
325
+ void resetIteratorIfInvalidatedWhileCalling (BasicBlock *BB, F f) {
326
+ // Substituting can cause recursive simplifications, which can invalidate
327
+ // our iterator. Use a WeakTrackingVH to hold onto it in case this
328
+ // happens.
329
+ Value *CurValue = &*CurInstIterator;
330
+ WeakTrackingVH IterHandle (CurValue);
331
+
332
+ f ();
333
+
334
+ // If the iterator instruction was recursively deleted, start over at the
335
+ // start of the block.
336
+ if (IterHandle != CurValue) {
337
+ CurInstIterator = BB->begin ();
338
+ SunkAddrs.clear ();
339
+ }
340
+ }
341
+
324
342
bool eliminateFallThrough (Function &F);
325
343
bool eliminateMostlyEmptyBlocks (Function &F);
326
344
BasicBlock *findDestBlockOfMergeableEmptyBlock (BasicBlock *BB);
@@ -1690,21 +1708,18 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool &ModifiedDT) {
1690
1708
// Lower all uses of llvm.objectsize.*
1691
1709
ConstantInt *RetVal =
1692
1710
lowerObjectSizeCall (II, *DL, TLInfo, /* MustSucceed=*/ true );
1693
- // Substituting this can cause recursive simplifications, which can
1694
- // invalidate our iterator. Use a WeakTrackingVH to hold onto it in case
1695
- // this
1696
- // happens.
1697
- Value *CurValue = &*CurInstIterator;
1698
- WeakTrackingVH IterHandle (CurValue);
1699
1711
1700
- replaceAndRecursivelySimplify (CI, RetVal, TLInfo, nullptr );
1701
-
1702
- // If the iterator instruction was recursively deleted, start over at the
1703
- // start of the block.
1704
- if (IterHandle != CurValue) {
1705
- CurInstIterator = BB->begin ();
1706
- SunkAddrs.clear ();
1707
- }
1712
+ resetIteratorIfInvalidatedWhileCalling (BB, [&]() {
1713
+ replaceAndRecursivelySimplify (CI, RetVal, TLInfo, nullptr );
1714
+ });
1715
+ return true ;
1716
+ }
1717
+ case Intrinsic::is_constant: {
1718
+ // If is_constant hasn't folded away yet, lower it to false now.
1719
+ Constant *RetVal = ConstantInt::getFalse (II->getContext ());
1720
+ resetIteratorIfInvalidatedWhileCalling (BB, [&]() {
1721
+ replaceAndRecursivelySimplify (CI, RetVal, TLInfo, nullptr );
1722
+ });
1708
1723
return true ;
1709
1724
}
1710
1725
case Intrinsic::aarch64_stlxr:
0 commit comments