[PATCH] D21395: Fix for Bug 28144

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 11:27:02 PDT 2016


> On Jun 20, 2016, at 9:32 PM, Vivek Pandya via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> vivekvpandya added inline comments.
> 
> ================
> Comment at: lib/CodeGen/RegUsageInfoCollector.cpp:113-126
> @@ -112,1 +112,16 @@
> 
> +  for (MachineBasicBlock &MBB : MF) {
> +    for (MachineInstr &MI : MBB) {
> +      if (!MI.isCall())
> +        continue;
> +      for (MachineOperand &MO : MI.operands()) {
> +        if (!MO.isRegMask())
> +          continue;
> +        const uint32_t *CalleeRegMask = MO.getRegMask();
> +        for (unsigned i = 0; i < RegMaskSize; ++i)
> +          RegMask[i] = RegMask[i] & CalleeRegMask[i];
> +        break;
> +      }
> +    }
> +  }
> +
> ----------------
> MatzeB wrote:
>> mehdi_amini wrote:
>>> Matze: I believe the register allocator does not account for register clobbered by callees.
>> Why do you say so? The registers clobbered by the callees is exactlye what the UsedPhysRegMask in MachineRegisterInfo is about, see also the use of addPhysRegsUsedFromRegMask() in VirtRegMap.cpp/FastRegAlloc.cpp.
> ```
> 
> // Code snippet 1
>  for (MachineBasicBlock &MBB : MF) {
>    for (MachineInstr &MI : MBB) {
>      if (!MI.isCall())
>        continue;
>      for (MachineOperand &MO : MI.operands()) {
>        if (!MO.isRegMask())
>          continue;
>        const uint32_t *CalleeRegMask = MO.getRegMask();
>        //DEBUG(dbgs() << "Callee RegMask : \n");
>        //printRegMask(TRI, CalleeRegMask);
>        for (unsigned i = 0; i < RegMaskSize; ++i)
>          RegMask[i] = RegMask[i] & CalleeRegMask[i];
>        break;
>      }
>    }
>  }
> ```
> 
> 
> ```
> // Code snippet 2
> BitVector UsedPhysRegMask = MRI->getUsedPhysRegsMask();
>  for (unsigned i = 0; i < RegMaskSize; ++i)
>           RegMask[i] = RegMask[i] & UsedPhysRegMask[i];
> 

Yes this fails because UsedPhysRegMask bits are set for used (=clobbered) registers while your regmask has a bit set for preserved registers.

=> RegMask[i] &= ~UsedPhysRegMask[i];

- Matthias


More information about the llvm-commits mailing list