Skip to content

Commit 4a65109

Browse files
authored
Merge pull request #27997 from gottesmm/pr-96e6234768d2055870be817c97bbf375d0822f45
[constant-folding] Eliminate complexity introducing pre-mature optimization.
2 parents f644983 + 8cb8e75 commit 4a65109

File tree

1 file changed

+1
-44
lines changed

1 file changed

+1
-44
lines changed

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,51 +1939,8 @@ ConstantFolder::processWorkList() {
19391939
// Ok, we have succeeded. Add user to the FoldedUsers list and perform
19401940
// the necessary cleanups, RAUWs, etc.
19411941
FoldedUsers.insert(User);
1942-
++NumInstFolded;
1943-
19441942
InvalidateInstructions = true;
1945-
1946-
// If the constant produced a tuple, be smarter than RAUW: explicitly
1947-
// nuke any tuple_extract instructions using the apply. This is a
1948-
// common case for functions returning multiple values.
1949-
if (auto *TI = dyn_cast<TupleInst>(C)) {
1950-
for (SILValue Result : User->getResults()) {
1951-
for (auto UI = Result->use_begin(), UE = Result->use_end();
1952-
UI != UE;) {
1953-
Operand *O = *UI++;
1954-
1955-
// If the user is a tuple_extract, just substitute the right
1956-
// value in.
1957-
if (auto *TEI = dyn_cast<TupleExtractInst>(O->getUser())) {
1958-
SILValue NewVal = TI->getOperand(TEI->getFieldNo());
1959-
TEI->replaceAllUsesWith(NewVal);
1960-
TEI->dropAllReferences();
1961-
FoldedUsers.insert(TEI);
1962-
if (auto *Inst = NewVal->getDefiningInstruction())
1963-
WorkList.insert(Inst);
1964-
continue;
1965-
}
1966-
1967-
if (auto *DTI = dyn_cast<DestructureTupleInst>(O->getUser())) {
1968-
SILValue NewVal = TI->getOperand(O->getOperandNumber());
1969-
auto OwnershipKind = NewVal.getOwnershipKind();
1970-
if (OwnershipKind.isCompatibleWith(
1971-
ValueOwnershipKind::Guaranteed)) {
1972-
SILValue DTIResult = DTI->getResult(O->getOperandNumber());
1973-
DTIResult->replaceAllUsesWith(NewVal);
1974-
FoldedUsers.insert(DTI);
1975-
if (auto *Inst = NewVal->getDefiningInstruction())
1976-
WorkList.insert(Inst);
1977-
continue;
1978-
}
1979-
}
1980-
}
1981-
}
1982-
1983-
if (llvm::all_of(User->getResults(),
1984-
[](SILValue v) { return v->use_empty(); }))
1985-
FoldedUsers.insert(TI);
1986-
}
1943+
++NumInstFolded;
19871944

19881945
// We were able to fold, so all users should use the new folded
19891946
// value. If we don't have any such users, continue.

0 commit comments

Comments
 (0)