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

Kyungwoo Lee via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 24 01:15:23 PST 2024


================
@@ -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()) {
----------------
kyulee-com wrote:

I see you attempt to optimize the case with 1 just for copying the pointer. But I'd simply merging reg mask in place here, without using the extra set. 
Basically, you could declare `RegMaskSize` outside the loop, as it's a constant for the function.
```
uint32_t *RegMask = nullptr;
...
            if (MOP.isRegMask()) {
              const uint32_t *CurrRegMask = MOP.getRegMask();
              if (!RegMask) {
                RegMask = MF->allocateRegMask();
                memcpy(RegMask, CurrRegMask, sizeof(RegMask[0]) * RegMaskSize);
              } else {
                for (unsigned I = 0; I < RegMaskSize; ++I)
                  RegMask[I] &= CurrRegMask[I];
              }
              continue;
            }
...
            if (RegMask)
              CallInst->addOperand(MachineOperand::CreateRegMask(RegMask));

  ```

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


More information about the llvm-commits mailing list