[PATCH] D125035: [riscv] Add strict asserts for VSETVLI insertion algorithm to help catch bugs

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 12:50:43 PDT 2022


reames created this revision.
reames added reviewers: frasercrmck, khchen, fakepaper56, jacquesguan, craig.topper.
Herald added subscribers: sunshaoce, VincentWu, luke957, StephenFan, vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, kito-cheng, niosHD, sabuasal, bollu, simoncook, johnrusso, rbar, asb, hiraditya, arichardson, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

This assertion should hold for any reasonable data flow algorithm, but is known not to in several cases today.  I'd like to go ahead and land this off-by-default, so that we can collaborate on fixes and have a common definition of success.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125035

Files:
  llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp


Index: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -37,6 +37,10 @@
     "riscv-disable-insert-vsetvl-phi-opt", cl::init(false), cl::Hidden,
     cl::desc("Disable looking through phis when inserting vsetvlis."));
 
+static cl::opt<bool> UseStrictAsserts(
+    "riscv-insert-vsetvl-strict-asserts", cl::init(false), cl::Hidden,
+    cl::desc("Enable strict assertion checking for the dataflow algorithm"));
+
 namespace {
 
 class VSETVLIInfo {
@@ -1168,7 +1172,7 @@
 
     // If we reach the end of the block and our current info doesn't match the
     // expected info, insert a vsetvli to correct.
-    if (MI.isTerminator()) {
+    if (!UseStrictAsserts && MI.isTerminator()) {
       const VSETVLIInfo &ExitInfo = BlockInfo[MBB.getNumber()].Exit;
       if (CurInfo.isValid() && ExitInfo.isValid() && !ExitInfo.isUnknown() &&
           CurInfo != ExitInfo) {
@@ -1177,6 +1181,16 @@
       }
     }
   }
+
+  if (UseStrictAsserts) {
+    const VSETVLIInfo &ExitInfo = BlockInfo[MBB.getNumber()].Exit;
+    if (CurInfo != ExitInfo) {
+      LLVM_DEBUG(dbgs() << "in block " << MBB.getName() << "\n");
+      LLVM_DEBUG(dbgs() << "  expected end state: " << ExitInfo << "\n");
+      LLVM_DEBUG(dbgs() << "  actual   end state: " << CurInfo << "\n");
+    }
+    assert(CurInfo == ExitInfo);
+  }
 }
 
 bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125035.427419.patch
Type: text/x-patch
Size: 1544 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220505/6f67a683/attachment.bin>


More information about the llvm-commits mailing list