[PATCH] D82709: [MachineLICM] [PowerPC] hoisting rematerializable cheap instructions based on register pressure.

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 28 02:14:57 PDT 2020


shchenz created this revision.
shchenz added reviewers: hfinkel, jsji, nemanjai, efriedma, arsenm, qcolombet, dmgreen, PowerPC.
Herald added subscribers: llvm-commits, wuzish, asbirlea, kosarev, kbarton, hiraditya, wdng.
Herald added a project: LLVM.
shchenz added parent revisions: D82708: [MachineLICM] NFC - make safety of moving explicitly for IsLoopInvariantInst, D82441: [MachineLICM] NFC - add a target hook shouldHoistCheapInstructions for machine licm to hoist cheap instruction.
shchenz edited the summary of this revision.
Herald added a subscriber: steven.zhang.

There is an issue for MachineLICM for rematerializable instructions hoisting.

  %64:g8rc = LIS8 585
  %65:g8rc = ORI8 killed %64:g8rc, 61440
  %66:g8rc_and_g8rc_nox0 = STDUX %21:g8rc, %18:g8rc_and_g8rc_nox0(tied-def 0), killed %65:g8rc :: (store 8 into %ir.49, !tbaa !2)

`%64:g8rc = LIS8 585` is a rematerializable instruction and it will be hoisted outside of loop without considering register pressure in MachineLICM.

After `%64:g8rc = LIS8 585` is hoisted out, `%65:g8rc = ORI8 killed %64:g8rc, 61440` is also hoisted out because it will lower the register pressure:

  // - When hoisting the last use of a value in the loop, that value no longer
  //   needs to be live in the loop. This lowers register pressure in the loop

So no matter how many pattern groups like above, MachineLICM will hoist all of them. When we have more than 32 group like above on PowerPC, hoisting all of them outside of loop will cause RA spilling.

This patch tries to fix the above issue:
1: override target hook `shouldHoistCheapInstructions` to make  machine licm hoist cheap rematerializable based on register pressure.
2: when machine licm gets a cheap rematerializable instruction, it will also check the user inside the loop. if the user is also a loop invariant, do not hoist it blindly, instead it hoists the instruction after evaluating the register pressure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82709

Files:
  llvm/lib/CodeGen/MachineLICM.cpp
  llvm/lib/Target/PowerPC/PPCInstrInfo.h
  llvm/test/CodeGen/PowerPC/rematerializable-instruction-machine-licm.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82709.273909.patch
Type: text/x-patch
Size: 29837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200628/598733bb/attachment-0001.bin>


More information about the llvm-commits mailing list