[llvm] [MCP] Avoid Folding Spill Chains Over Across Source Clobbers (PR #207169)
Jack Styles via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 07:16:42 PDT 2026
================
@@ -1376,6 +1379,27 @@ void MachineCopyPropagation::eliminateSpillageCopies(MachineBasicBlock &MBB) {
}
};
+ auto HasUnexpectedCopySourceDef = [&](const MachineInstr *Copy,
+ const MachineInstr *ExpectedDef) {
+ auto CopySouceDefPair = CopySourceDefCopies.find(Copy);
+ if (CopySouceDefPair == CopySourceDefCopies.end())
+ return false;
+
+ for (const MachineInstr *DefCopy : CopySouceDefPair->second)
+ if (DefCopy != ExpectedDef)
+ return true;
+ return false;
+ };
+ // Do not fold across an unexpected COPY def of a chains copy's source.
+ // The paired reload may be needed to restore the original source value.
+ // More info: https://github.com/llvm/llvm-project/issues/206839
+ for (size_t I = 1; I < SC.size(); ++I) {
+ if (HasUnexpectedCopySourceDef(SC[I], SC[I - 1]))
+ return;
+ if (I + 1 > SC.size() && HasUnexpectedCopySourceDef(RC[I], RC[I + 1]))
----------------
Stylie777 wrote:
This is intentional, for spills the defining copy would be the previous inner spill, and reload it would be the next outer reload. I did try collapsing this into one loop but I think thats wrong now on reflection as it misses the first reload. It will now check all the reloads, and all spills. Because of how they are checked, the formation of the for loops are different, so they have been separated.
https://github.com/llvm/llvm-project/pull/207169
More information about the llvm-commits
mailing list