Skip to content

Commit 364cee8

Browse files
committed
[sil-combine] Enable elimination of simple tuple results from overflow functions when ownership is enabled.
This doesn't actually touch non-trivial values, so from an ownership perspective it is inert. It is tested by the pattern in the next commit.
1 parent 1e7990c commit 364cee8

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,19 +1875,16 @@ SILInstruction *SILCombiner::visitSelectEnumInst(SelectEnumInst *SEI) {
18751875
}
18761876

18771877
SILInstruction *SILCombiner::visitTupleExtractInst(TupleExtractInst *TEI) {
1878-
if (TEI->getFunction()->hasOwnership())
1879-
return nullptr;
1880-
18811878
// tuple_extract(apply([add|sub|...]overflow(x, 0)), 1) -> 0
18821879
// if it can be proven that no overflow can happen.
1883-
if (TEI->getFieldIndex() != 1)
1884-
return nullptr;
1880+
if (TEI->getFieldIndex() == 1) {
1881+
Builder.setCurrentDebugScope(TEI->getDebugScope());
1882+
if (auto *BI = dyn_cast<BuiltinInst>(TEI->getOperand()))
1883+
if (!canOverflow(BI))
1884+
return Builder.createIntegerLiteral(TEI->getLoc(), TEI->getType(),
1885+
APInt(1, 0));
1886+
}
18851887

1886-
Builder.setCurrentDebugScope(TEI->getDebugScope());
1887-
if (auto *BI = dyn_cast<BuiltinInst>(TEI->getOperand()))
1888-
if (!canOverflow(BI))
1889-
return Builder.createIntegerLiteral(TEI->getLoc(), TEI->getType(),
1890-
APInt(1, 0));
18911888
return nullptr;
18921889
}
18931890

0 commit comments

Comments
 (0)