Skip to content

Commit 198c884

Browse files
committed
[SandboxVec][BottomUpVec] Add -sbvec-stop-at flag for debugging
When debugging miscompiles we need a way to force-stop the vectorizer early. This helps figure out which invocation is generating incorrect code.
1 parent e2b0d5d commit 198c884

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class BottomUpVec final : public RegionPass {
3939
DenseSet<Instruction *> DeadInstrCandidates;
4040
/// Maps scalars to vectors.
4141
std::unique_ptr<InstrMaps> IMaps;
42+
/// Counter used for force-stopping the vectorizer after this many
43+
/// invocations. Used for debugging miscompiles.
44+
unsigned long BottomUpInvocationCnt = 0;
4245

4346
/// Creates and returns a vector instruction that replaces the instructions in
4447
/// \p Bndl. \p Operands are the already vectorized operands.

llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ static cl::opt<bool>
2525
"emit new instructions (*very* expensive)."));
2626
#endif // NDEBUG
2727

28+
static constexpr const unsigned long StopAtDisabled =
29+
std::numeric_limits<unsigned long>::max();
30+
static cl::opt<unsigned long>
31+
StopAt("sbvec-stop-at", cl::init(StopAtDisabled), cl::Hidden,
32+
cl::desc("Vectorize if the invocation count is < than this. 0 "
33+
"disables vectorization."));
34+
2835
namespace sandboxir {
2936

3037
static SmallVector<Value *, 4> getOperand(ArrayRef<Value *> Bndl,
@@ -456,6 +463,9 @@ Value *BottomUpVec::emitVectors() {
456463

457464
bool BottomUpVec::tryVectorize(ArrayRef<Value *> Bndl) {
458465
Change = false;
466+
if (LLVM_UNLIKELY(BottomUpInvocationCnt++ >= StopAt &&
467+
StopAt != StopAtDisabled))
468+
return false;
459469
DeadInstrCandidates.clear();
460470
Legality->clear();
461471
Actions.clear();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" --sbvec-stop-at=0 %s -S | FileCheck %s --check-prefix=STOPAT0
3+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" --sbvec-stop-at=1 %s -S | FileCheck %s --check-prefix=STOPAT1
4+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" --sbvec-stop-at=2 %s -S | FileCheck %s --check-prefix=STOPAT2
5+
6+
define void @widen(ptr %ptrA, ptr %ptrB) {
7+
; STOPAT0-LABEL: define void @widen(
8+
; STOPAT0-SAME: ptr [[PTRA:%.*]], ptr [[PTRB:%.*]]) {
9+
; STOPAT0-NEXT: [[PTRA0:%.*]] = getelementptr float, ptr [[PTRA]], i32 0
10+
; STOPAT0-NEXT: [[PTRA1:%.*]] = getelementptr float, ptr [[PTRA]], i32 1
11+
; STOPAT0-NEXT: [[LDA0:%.*]] = load float, ptr [[PTRA0]], align 4
12+
; STOPAT0-NEXT: [[LDA1:%.*]] = load float, ptr [[PTRA1]], align 4
13+
; STOPAT0-NEXT: store float [[LDA0]], ptr [[PTRA0]], align 4
14+
; STOPAT0-NEXT: store float [[LDA1]], ptr [[PTRA1]], align 4
15+
; STOPAT0-NEXT: [[PTRB0:%.*]] = getelementptr float, ptr [[PTRB]], i32 0
16+
; STOPAT0-NEXT: [[PTRB1:%.*]] = getelementptr float, ptr [[PTRB]], i32 1
17+
; STOPAT0-NEXT: [[LDB0:%.*]] = load float, ptr [[PTRB0]], align 4
18+
; STOPAT0-NEXT: [[LDB1:%.*]] = load float, ptr [[PTRB1]], align 4
19+
; STOPAT0-NEXT: store float [[LDB0]], ptr [[PTRB0]], align 4
20+
; STOPAT0-NEXT: store float [[LDB1]], ptr [[PTRB1]], align 4
21+
; STOPAT0-NEXT: ret void
22+
;
23+
; STOPAT1-LABEL: define void @widen(
24+
; STOPAT1-SAME: ptr [[PTRA:%.*]], ptr [[PTRB:%.*]]) {
25+
; STOPAT1-NEXT: [[PTRA0:%.*]] = getelementptr float, ptr [[PTRA]], i32 0
26+
; STOPAT1-NEXT: [[VECL:%.*]] = load <2 x float>, ptr [[PTRA0]], align 4
27+
; STOPAT1-NEXT: store <2 x float> [[VECL]], ptr [[PTRA0]], align 4
28+
; STOPAT1-NEXT: [[PTRB0:%.*]] = getelementptr float, ptr [[PTRB]], i32 0
29+
; STOPAT1-NEXT: [[PTRB1:%.*]] = getelementptr float, ptr [[PTRB]], i32 1
30+
; STOPAT1-NEXT: [[LDB0:%.*]] = load float, ptr [[PTRB0]], align 4
31+
; STOPAT1-NEXT: [[LDB1:%.*]] = load float, ptr [[PTRB1]], align 4
32+
; STOPAT1-NEXT: store float [[LDB0]], ptr [[PTRB0]], align 4
33+
; STOPAT1-NEXT: store float [[LDB1]], ptr [[PTRB1]], align 4
34+
; STOPAT1-NEXT: ret void
35+
;
36+
; STOPAT2-LABEL: define void @widen(
37+
; STOPAT2-SAME: ptr [[PTRA:%.*]], ptr [[PTRB:%.*]]) {
38+
; STOPAT2-NEXT: [[PTRA0:%.*]] = getelementptr float, ptr [[PTRA]], i32 0
39+
; STOPAT2-NEXT: [[VECL:%.*]] = load <2 x float>, ptr [[PTRA0]], align 4
40+
; STOPAT2-NEXT: store <2 x float> [[VECL]], ptr [[PTRA0]], align 4
41+
; STOPAT2-NEXT: [[PTRB0:%.*]] = getelementptr float, ptr [[PTRB]], i32 0
42+
; STOPAT2-NEXT: [[VECL1:%.*]] = load <2 x float>, ptr [[PTRB0]], align 4
43+
; STOPAT2-NEXT: store <2 x float> [[VECL1]], ptr [[PTRB0]], align 4
44+
; STOPAT2-NEXT: ret void
45+
;
46+
%ptrA0 = getelementptr float, ptr %ptrA, i32 0
47+
%ptrA1 = getelementptr float, ptr %ptrA, i32 1
48+
%ldA0 = load float, ptr %ptrA0
49+
%ldA1 = load float, ptr %ptrA1
50+
store float %ldA0, ptr %ptrA0
51+
store float %ldA1, ptr %ptrA1
52+
53+
%ptrB0 = getelementptr float, ptr %ptrB, i32 0
54+
%ptrB1 = getelementptr float, ptr %ptrB, i32 1
55+
%ldB0 = load float, ptr %ptrB0
56+
%ldB1 = load float, ptr %ptrB1
57+
store float %ldB0, ptr %ptrB0
58+
store float %ldB1, ptr %ptrB1
59+
60+
ret void
61+
}

0 commit comments

Comments
 (0)