[llvm] [MachineOutliner] Preserve regmasks in calls to outlined functions (PR #120940)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Tue May 13 15:09:41 PDT 2025


================
@@ -1130,6 +1131,12 @@ bool MachineOutliner::outline(
           MachineInstr *MI = &*Iter;
           SmallSet<Register, 2> InstrUseRegs;
           for (MachineOperand &MOP : MI->operands()) {
+            // Collect all regmasks. Merge them in the end.
+            if (MOP.isRegMask()) {
----------------
ellishg wrote:

The size of `RegMasks` depends on the number of call instructions in the outlined candidate, and I believe this usually one. However, I think you might be forgetting that non-call instruction can clobber a register. My understanding of `RegMask` is that it tells you which registers could be changed after executing that instruction.

https://github.com/llvm/llvm-project/blob/76dba2ea02048b587d10ccdf777b0875369f362c/llvm/include/llvm/CodeGen/MachineOperand.h#L921-L927

But an outlined function might have other instructions as well as call instructions. I think you need to mark `MOP.isDef()` registers as clobbered in the mask too (I believe this is what @MatzeB was alluding to).

In that case, we will likely need to copy the mask using `allocateRegMask()` anyway, so I think @kyulee-com suggestion might be worth considering.

https://github.com/llvm/llvm-project/pull/120940


More information about the llvm-commits mailing list