[BranchRelaxation] Strengthen post condition assertions
authorPhilip Reames <preames@rivosinc.com>
Tue, 31 Jan 2023 15:50:40 +0000 (07:50 -0800)
committerPhilip Reames <listmail@philipreames.com>
Tue, 31 Jan 2023 16:05:31 +0000 (08:05 -0800)
The whole point of this pass is to rewrite branches so that branches are in bounds. We should assert that we succeeded rather than just that we kept our internal data structure in sync.

Differential Revision: https://reviews.llvm.org/D142778

llvm/lib/CodeGen/BranchRelaxation.cpp

index 016c81d..45c09a1 100644 (file)
@@ -132,6 +132,19 @@ void BranchRelaxation::verify() {
     assert(BlockInfo[Num].Size == computeBlockSize(MBB));
     PrevNum = Num;
   }
+
+  for (MachineBasicBlock &MBB : *MF) {
+    for (MachineBasicBlock::iterator J = MBB.getFirstTerminator();
+         J != MBB.end(); J = std::next(J)) {
+      MachineInstr &MI = *J;
+      if (!MI.isConditionalBranch() && !MI.isUnconditionalBranch())
+        continue;
+      if (MI.getOpcode() == TargetOpcode::FAULTING_OP)
+        continue;
+      MachineBasicBlock *DestBB = TII->getBranchDestBlock(MI);
+      assert(isBlockInRange(MI, *DestBB));
+    }
+  }
 #endif
 }