@@ -1681,36 +1681,48 @@ SILInstruction *SILCombiner::visitEnumInst(EnumInst *EI) {
1681
1681
return nullptr ;
1682
1682
}
1683
1683
1684
- SILInstruction *SILCombiner::visitMarkDependenceInst (MarkDependenceInst *MDI ) {
1684
+ SILInstruction *SILCombiner::visitMarkDependenceInst (MarkDependenceInst *mdi ) {
1685
1685
// Simplify the base operand of a MarkDependenceInst to eliminate unnecessary
1686
1686
// instructions that aren't adding value.
1687
1687
//
1688
1688
// Conversions to Optional.Some(x) often happen here, this isn't important
1689
1689
// for us, we can just depend on 'x' directly.
1690
- if (auto eiBase = dyn_cast<EnumInst>(MDI ->getBase ())) {
1690
+ if (auto * eiBase = dyn_cast<EnumInst>(mdi ->getBase ())) {
1691
1691
if (eiBase->hasOperand () && eiBase->hasOneUse ()) {
1692
- MDI ->setBase (eiBase->getOperand ());
1692
+ mdi ->setBase (eiBase->getOperand ());
1693
1693
eraseInstFromFunction (*eiBase);
1694
- return MDI ;
1694
+ return mdi ;
1695
1695
}
1696
1696
}
1697
1697
1698
1698
// Conversions from a class to AnyObject also happen a lot, we can just depend
1699
1699
// on the class reference.
1700
- if (auto ier = dyn_cast<InitExistentialRefInst>(MDI ->getBase ())) {
1701
- MDI ->setBase (ier->getOperand ());
1700
+ if (auto * ier = dyn_cast<InitExistentialRefInst>(mdi ->getBase ())) {
1701
+ mdi ->setBase (ier->getOperand ());
1702
1702
if (ier->use_empty ())
1703
1703
eraseInstFromFunction (*ier);
1704
- return MDI ;
1704
+ return mdi ;
1705
1705
}
1706
1706
1707
1707
// Conversions from a class to AnyObject also happen a lot, we can just depend
1708
1708
// on the class reference.
1709
- if (auto oeri = dyn_cast<OpenExistentialRefInst>(MDI ->getBase ())) {
1710
- MDI ->setBase (oeri->getOperand ());
1709
+ if (auto * oeri = dyn_cast<OpenExistentialRefInst>(mdi ->getBase ())) {
1710
+ mdi ->setBase (oeri->getOperand ());
1711
1711
if (oeri->use_empty ())
1712
1712
eraseInstFromFunction (*oeri);
1713
- return MDI;
1713
+ return mdi;
1714
+ }
1715
+
1716
+ // Sometimes due to specialization/builtins, we can get a mark_dependence
1717
+ // whose base is a trivial typed object. In such a case, the mark_dependence
1718
+ // does not have a meaning, so just eliminate it.
1719
+ {
1720
+ SILType baseType = mdi->getBase ()->getType ();
1721
+ if (baseType.isObject () && baseType.isTrivial (*mdi->getFunction ())) {
1722
+ SILValue value = mdi->getValue ();
1723
+ mdi->replaceAllUsesWith (value);
1724
+ return eraseInstFromFunction (*mdi);
1725
+ }
1714
1726
}
1715
1727
1716
1728
return nullptr ;
0 commit comments