Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions llvm/lib/CodeGen/GlobalISel/GIMatchTableExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ bool GIMatchTableExecutor::isObviouslySafeToFold(MachineInstr &MI,
if (MI.isConvergent() && MI.getParent() != IntoMI.getParent())
return false;

return !MI.mayLoadOrStore() && !MI.mayRaiseFPException() &&
!MI.hasUnmodeledSideEffects() && MI.implicit_operands().empty();
auto IsSafe = [](const MachineInstr &MI) {
return !MI.mayRaiseFPException() && !MI.hasUnmodeledSideEffects() &&
MI.implicit_operands().empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand the implicit operands check. I think this is starting to reproduce MachineInstr::isSafeToMove

};
auto IsSafeNoMem = [IsSafe](const MachineInstr &MI) {
return !MI.mayLoadOrStore() && IsSafe(MI);
};

// If source instruction uses memory, fold if no intermediate
// instructions use it.
if (MI.mayLoadOrStore() && IsSafe(MI) &&
MI.getParent() == IntoMI.getParent()) {
auto IntoIt = IntoMI.getIterator();
auto NextIt = std::next(MI.getIterator());
while (!NextIt.isEnd() && NextIt != IntoIt && IsSafeNoMem(*NextIt))
++NextIt;
if (NextIt == IntoIt)
return true;
}

return IsSafeNoMem(MI);
}