[llvm] f486119 - [riscv] Add strict asserts for VSETVLI insertion algorithm to help catch bugs
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri May 6 10:28:35 PDT 2022
Author: Philip Reames
Date: 2022-05-06T10:28:22-07:00
New Revision: f486119ce94573793c1569f1542c09fae74a0d1d
URL: https://github.com/llvm/llvm-project/commit/f486119ce94573793c1569f1542c09fae74a0d1d
DIFF: https://github.com/llvm/llvm-project/commit/f486119ce94573793c1569f1542c09fae74a0d1d.diff
LOG: [riscv] Add strict asserts for VSETVLI insertion algorithm to help catch bugs
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.
Differential: https://reviews.llvm.org/D125035
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index f58e0873b839a..ddb4b5c9ef976 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -37,6 +37,10 @@ static cl::opt<bool> DisableInsertVSETVLPHIOpt(
"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 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
// 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,18 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
}
}
}
+
+ if (UseStrictAsserts && CurInfo.isValid()) {
+ const auto &Info = BlockInfo[MBB.getNumber()];
+ if (CurInfo != Info.Exit) {
+ LLVM_DEBUG(dbgs() << "in block " << printMBBReference(MBB) << "\n");
+ LLVM_DEBUG(dbgs() << " begin state: " << Info.Pred << "\n");
+ LLVM_DEBUG(dbgs() << " expected end state: " << Info.Exit << "\n");
+ LLVM_DEBUG(dbgs() << " actual end state: " << CurInfo << "\n");
+ }
+ assert(CurInfo == Info.Exit &&
+ "InsertVSETVLI dataflow invariant violated");
+ }
}
bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
More information about the llvm-commits
mailing list