[PATCH] D80077: [LiveVariables] Don't set undef reg PHI used as live for FromMBB

Zhang Kang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 17 01:33:29 PDT 2020


ZhangKang created this revision.
ZhangKang added reviewers: bjope, qcolombet, hfinkel, jonpa, jsji, steven.zhang, nemanjai, echristo, PowerPC.
ZhangKang added a project: LLVM.
Herald added subscribers: wuzish, hiraditya, kristof.beyls.
ZhangKang edited the summary of this revision.

In the patch, https://reviews.llvm.org/D73152 , it adds a new function `LiveVariables::addNewBlock`.
This new function will add the reg which PHI used to the MBB which reg is from.
But the new function may cause LiveVariable Verification failed when the Src reg in PHI is undef.

For example:

  bb.0:
    ... // no-definiton for %2
  bb.1:
    ...
  bb.2:
    %3:g8rc = PHI %1, %bb.0, undef %2:g8rc, %bb.0

It's obvious that, the %2 shouldn't live in bb.0, but the patch D73152 <https://reviews.llvm.org/D73152> will set it live for bb.0.

If you have enabled all the pass verification in llvm/lib/CodeGen/TargetPassConfig.cpp,
then, you can use below command to reproduce the bug.

  llvm-lit -a llvm/test/CodeGen/AArch64/shrink-wrap.ll

There is no test case for this patch, because the verification for LiveVariable pass has other errors,
we can't enable the verification for the LiveVariable pass and PHIElimination pass.

>From the `LiveVariables::analyzePHINodes`, we can know we can use `getOperand(i).readsReg()` to avoid above bug.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80077

Files:
  llvm/lib/CodeGen/LiveVariables.cpp


Index: llvm/lib/CodeGen/LiveVariables.cpp
===================================================================
--- llvm/lib/CodeGen/LiveVariables.cpp
+++ llvm/lib/CodeGen/LiveVariables.cpp
@@ -828,7 +828,8 @@
          BBE = SuccBB->end();
        BBI != BBE && BBI->isPHI(); ++BBI) {
     for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2)
-      if (BBI->getOperand(i + 1).getMBB() == BB)
+      if (BBI->getOperand(i + 1).getMBB() == BB &&
+          BBI->getOperand(i).readsReg())
         getVarInfo(BBI->getOperand(i).getReg())
           .AliveBlocks.set(NumNew);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80077.264477.patch
Type: text/x-patch
Size: 588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200517/8e561b1b/attachment.bin>


More information about the llvm-commits mailing list