[llvm] 81c4e58 - [StandardInstrumentations] Handle case where block order changes
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 8 07:41:54 PDT 2022
Author: Arthur Eubanks
Date: 2022-08-08T07:41:39-07:00
New Revision: 81c4e58e2adae7f9711253c07bc0c96dbc6d1b0b
URL: https://github.com/llvm/llvm-project/commit/81c4e58e2adae7f9711253c07bc0c96dbc6d1b0b
DIFF: https://github.com/llvm/llvm-project/commit/81c4e58e2adae7f9711253c07bc0c96dbc6d1b0b.diff
LOG: [StandardInstrumentations] Handle case where block order changes
Previously we'd go off the end of the BI iterator because we expected
that the relative positions of common blocks before and after were
consistent. That's not always true though, for example with
jump-threading.
Reviewed By: jamieschmeiser
Differential Revision: https://reviews.llvm.org/D130596
Added:
llvm/test/Other/ChangePrinters/print-changed-diff-block-ordering-changed.ll
Modified:
llvm/lib/Passes/StandardInstrumentations.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index c44e3eb3ea451..d579529a65a44 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -540,7 +540,10 @@ void OrderedChangedData<T>::report(
}
// This section is in both; advance and print out any before-only
// until we get to it.
- while (*BI != *AI) {
+ // It's possible that this section has moved to be later than before. This
+ // will mess up printing most blocks side by side, but it's a rare case and
+ // it's better than crashing.
+ while (BI != BE && *BI != *AI) {
HandlePotentiallyRemovedData(*BI);
++BI;
}
@@ -550,7 +553,8 @@ void OrderedChangedData<T>::report(
const T &AData = AFD.find(*AI)->getValue();
const T &BData = BFD.find(*AI)->getValue();
HandlePair(&BData, &AData);
- ++BI;
+ if (BI != BE)
+ ++BI;
++AI;
}
diff --git a/llvm/test/Other/ChangePrinters/print-changed-
diff -block-ordering-changed.ll b/llvm/test/Other/ChangePrinters/print-changed-
diff -block-ordering-changed.ll
new file mode 100644
index 0000000000000..ad2cca46f872a
--- /dev/null
+++ b/llvm/test/Other/ChangePrinters/print-changed-
diff -block-ordering-changed.ll
@@ -0,0 +1,20 @@
+; RUN: opt -passes=jump-threading %s -disable-output --print-changed=
diff 2>&1 | FileCheck %s
+
+; CHECK: IR Dump After JumpThreadingPass
+
+define void @f(i1 %0) {
+ br i1 %0, label %5, label %2
+
+2: ; preds = %1
+ br i1 false, label %b, label %3
+
+3: ; preds = %2
+ %4 = call i64 null()
+ br label %b
+
+b: ; preds = %3, %2
+ br label %5
+
+5: ; preds = %b, %1
+ ret void
+}
More information about the llvm-commits
mailing list