[PATCH] D43542: [CodeGen][FastRegAlloc] Disable registers spilling for a naked function (PR28641)

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 25 12:06:51 PST 2018


MatzeB added a comment.

I've been looking into this, and we do indeed produce something like this for naked function with a parameter (this from  http://llvm.org/PR28641 compiled with -O0):

  bb.0 (%ir-block.1):
    liveins: $edi
    %0:gr32 = COPY $edi
    %1:gr32 = COPY killed %0
    INLINEASM &ret [sideeffect] [attdialect], $0:[clobber], implicit-def early-clobber $rdi, $1:[clobber], implicit-def early-clobber $eflags, !2



- It would probably be a good idea to change isel to not emit copies for unused arguments but technically it is not wrong.
- The %1 assignment is dead but not marked as such. I'm not 100% sure whether it is allowed to omit dead flags.
- We can teach fast regalloc to recognize obviously dead cases where a vreg doesn't have a single use. That's enough to get this naked function stuff going:

  diff --git a/lib/CodeGen/RegAllocFast.cpp b/lib/CodeGen/RegAllocFast.cpp
  index 7a8d4225ad0..b2603c270a1 100644
  --- a/lib/CodeGen/RegAllocFast.cpp
  +++ b/lib/CodeGen/RegAllocFast.cpp
  @@ -1044,7 +1044,7 @@ void RegAllocFast::allocateBasicBlock(MachineBasicBlock &MBB) {
         }
         LiveRegMap::iterator LRI = defineVirtReg(MI, I, Reg, CopySrcReg);
         MCPhysReg PhysReg = LRI->PhysReg;
  -      if (setPhysReg(MI, I, PhysReg)) {
  +      if (setPhysReg(MI, I, PhysReg) || MRI->use_nodbg_empty(Reg)) {
           VirtDead.push_back(Reg);
           CopyDstReg = 0; // cancel coalescing;
         } else

(of course to actually push this fastregalloc improvement we have to adapt a number of testcases)


https://reviews.llvm.org/D43542





More information about the llvm-commits mailing list