[llvm] 03bb277 - [BranchRelaxation] Strengthen post condition assertions

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 31 08:05:49 PST 2023


Author: Philip Reames
Date: 2023-01-31T08:05:31-08:00
New Revision: 03bb277f308e0e49d2d7f00719e908b8e10325b8

URL: https://github.com/llvm/llvm-project/commit/03bb277f308e0e49d2d7f00719e908b8e10325b8
DIFF: https://github.com/llvm/llvm-project/commit/03bb277f308e0e49d2d7f00719e908b8e10325b8.diff

LOG: [BranchRelaxation] Strengthen post condition assertions

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

Added: 
    

Modified: 
    llvm/lib/CodeGen/BranchRelaxation.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/BranchRelaxation.cpp b/llvm/lib/CodeGen/BranchRelaxation.cpp
index 016c81dc5aa4..45c09a12ce11 100644
--- a/llvm/lib/CodeGen/BranchRelaxation.cpp
+++ b/llvm/lib/CodeGen/BranchRelaxation.cpp
@@ -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
 }
 


        


More information about the llvm-commits mailing list