Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
81f1800
Emit better debug and opt-report messages when vectorization is disal…
Sep 14, 2025
6d941ff
Trafo -> Transforms
Sep 15, 2025
c0e6aec
Testing part 1: explicitly disabled code path
Sep 15, 2025
c290bec
Testing part 2: VectorizeOnlyWhenForced code path
Sep 15, 2025
109b3fd
Rename the two new tests so far to begin with diag-
Sep 16, 2025
3c4c8de
Testing part 3: hasDisableAllTransformsHint code path
Sep 16, 2025
fa19ccc
fix test 3
Sep 16, 2025
29d1fa2
use [BUG] instead of [FIXME] in the sanity check fail debug msg
Oct 13, 2025
117c358
Clean up function name and remove excessive attributes from Test 1 an…
Oct 13, 2025
2241343
Try combining Test1 and Test2 into one file
Oct 18, 2025
98a90e9
Address IR review pt1: datalayout
TiborGY Nov 1, 2025
55af5ac
Address IR review pt2: use llvm_unreachable
Nov 1, 2025
120a5bf
Address IR review pt3: only 1 load
Nov 1, 2025
a509ea9
Address IR review pt4: exit block
Nov 1, 2025
bc68571
Refactor the printing of the new messages
Nov 1, 2025
c6a624d
fix
Nov 1, 2025
d4f407b
update message in tests
Nov 1, 2025
5d656e8
give test fn a more descriptive name
Nov 1, 2025
0a933b2
Address IR review pt5: simplify entry block of disable_nonforced
Nov 1, 2025
6dfffe8
Address IR review pt6: simplify some variable and label names
Nov 1, 2025
936d9e3
Apply suggestions from code review
TiborGY Nov 7, 2025
b895a97
update check-nots as the message was removed in favor of llvm_unreach…
Nov 7, 2025
8173da8
fix test
Nov 7, 2025
835f8f0
try simplifying disabled_loop_vectorization test fn to constant store
Nov 7, 2025
7f9fe50
fix return type
Nov 7, 2025
552a8ab
try moving Test3 into the same file as Test 1&2
Nov 7, 2025
dcd926f
somehow a suggestion did not apply
Nov 7, 2025
86515c5
More reviewer suggestions, pt1
Nov 10, 2025
5f7c8b0
use CHECK-LABEL
Nov 10, 2025
96d6136
fix check-label
Nov 10, 2025
6c1932e
shorten loop control flow labels
Nov 15, 2025
8e0c12b
shorten %indvars.iv to %iv, make it 32 bits to remove truncates and s…
Nov 15, 2025
1ec46e8
group all RUN lines at the top, reduce check duplication between Test…
Nov 15, 2025
f530fd5
remove dump-input from FileCheck lines
Nov 17, 2025
60f86af
perform all checks on the second fn with all three RUN lines, also pe…
Nov 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ class LoopVectorizeHints {

/// Interface to emit optimization remarks.
OptimizationRemarkEmitter &ORE;

/// Reports a condition where loop vectorization is disallowed: prints
/// \p DebugMsg for debugging purposes along with the corresponding
/// optimization remark \p RemarkName, with \p RemarkMsg as the user-facing
/// message. The loop \p L is used for the location of the remark.
void reportDisallowedVectorization(const StringRef DebugMsg,
const StringRef RemarkName,
const StringRef RemarkMsg,
const Loop *L) const;
};

/// This holds vectorization requirements that must be verified late in
Expand Down
28 changes: 24 additions & 4 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,37 @@ void LoopVectorizeHints::setAlreadyVectorized() {
IsVectorized.Value = 1;
}

void LoopVectorizeHints::reportDisallowedVectorization(
const StringRef DebugMsg, const StringRef RemarkName,
const StringRef RemarkMsg, const Loop *L) const {
LLVM_DEBUG(dbgs() << "LV: Not vectorizing: " << DebugMsg << ".\n");
ORE.emit(OptimizationRemarkMissed(LV_NAME, RemarkName, L->getStartLoc(),
L->getHeader())
<< "loop not vectorized: " << RemarkMsg);
}

bool LoopVectorizeHints::allowVectorization(
Function *F, Loop *L, bool VectorizeOnlyWhenForced) const {
if (getForce() == LoopVectorizeHints::FK_Disabled) {
LLVM_DEBUG(dbgs() << "LV: Not vectorizing: #pragma vectorize disable.\n");
emitRemarkWithHints();
if (Force.Value == LoopVectorizeHints::FK_Disabled) {
reportDisallowedVectorization("#pragma vectorize disable",
"MissedExplicitlyDisabled",
"vectorization is explicitly disabled", L);
} else if (hasDisableAllTransformsHint(L)) {
reportDisallowedVectorization("loop hasDisableAllTransformsHint",
"MissedTransformsDisabled",
"loop transformations are disabled", L);
} else {
llvm_unreachable("loop vect disabled for an unknown reason");
}
return false;
}

if (VectorizeOnlyWhenForced && getForce() != LoopVectorizeHints::FK_Enabled) {
LLVM_DEBUG(dbgs() << "LV: Not vectorizing: No #pragma vectorize enable.\n");
emitRemarkWithHints();
reportDisallowedVectorization(
"VectorizeOnlyWhenForced is set, and no #pragma vectorize enable",
"MissedForceOnly", "only vectorizing loops that explicitly request it",
L);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
; REQUIRES: asserts

; TEST 1
; Checks that we emit only the correct debug messages and
; optimization remark when the loop vectorizer is disabled by loop metadata.
; RUN: opt -S -passes=loop-vectorize -pass-remarks=loop-vectorize \
; RUN: -pass-remarks-missed=loop-vectorize \
; RUN: -pass-remarks-analysis=loop-vectorize -debug \
; RUN: < %s 2>&1 | FileCheck --check-prefixes=METADATA,ALL %s
; TEST 2
; Checks that we emit only the correct debug messages and
; optimization remark when the loop is not vectorized due to the
; vectorize-forced-only pass option being set.
; Strip metadata for FORCEDONLY run, keep it for METADATA run
; RUN: sed 's/,[[:space:]]*!llvm\.loop[[:space:]]*!0//' %s | \
; RUN: opt -S -passes='loop-vectorize<vectorize-forced-only>' \
; RUN: -pass-remarks=loop-vectorize \
; RUN: -pass-remarks-missed=loop-vectorize \
; RUN: -pass-remarks-analysis=loop-vectorize -debug \
; RUN: 2>&1 | FileCheck --check-prefixes=FORCEDONLY,ALL %s
; TEST 3
; Checks that we emit only the correct debug messages and
; optimization remark when the loop vectorizer is disabled by loop metadata
; that requests no loop transformations.
; RUN: opt -S -passes=loop-vectorize -pass-remarks=loop-vectorize \
; RUN: -pass-remarks-missed=loop-vectorize \
; RUN: -pass-remarks-analysis=loop-vectorize -debug \
; RUN: -force-vector-interleave=1 -force-vector-width=2 \
; RUN: < %s 2>&1 | FileCheck --check-prefix=ALL %s

; ALL-LABEL: 'disabled_loop_vectorization' from <stdin>
; ALL-NOT: LV: We can vectorize this loop
; ALL-NOT: LV: Not vectorizing: loop hasDisableAllTransformsHint
; ALL-NOT: LV: Not vectorizing: Disabled/already vectorized
; ALL-NOT: LV: Not vectorizing: Cannot prove legality
;
; METADATA-NOT: LV: Not vectorizing: VectorizeOnlyWhenForced is set
; METADATA: LV: Loop hints: force=disabled
; METADATA: LV: Not vectorizing: #pragma vectorize disable.
; METADATA: remark:
; METADATA-SAME: loop not vectorized: vectorization is explicitly disabled
;
; FORCEDONLY-NOT: LV: Not vectorizing: #pragma vectorize disable
; FORCEDONLY: LV: Loop hints: force=?
; FORCEDONLY: LV: Not vectorizing: VectorizeOnlyWhenForced is set, and no #pragma vectorize enable
; FORCEDONLY: remark:
; FORCEDONLY-SAME: loop not vectorized: only vectorizing loops that explicitly request it
;
; ALL: LV: Loop hints prevent vectorization
define void @disabled_loop_vectorization(ptr %src) {
entry:
br label %loop

loop:
%iv = phi i64 [ 0, %entry ], [ %inc, %loop ]
%arrayidx = getelementptr inbounds nuw double, ptr %src, i64 %iv
store double 0.0, ptr %arrayidx, align 8
%inc = add nuw nsw i64 %iv, 1
%exitcond.not = icmp eq i64 %inc, 15
br i1 %exitcond.not, label %exit, label %loop, !llvm.loop !0

exit:
ret void
}
!0 = distinct !{!0, !1}
!1 = !{!"llvm.loop.vectorize.enable", i1 false}

; ALL-LABEL: 'disable_nonforced' from <stdin>
; ALL-NOT: LV: We can vectorize this loop
; ALL-NOT: LV: Not vectorizing: #pragma vectorize disable.
; ALL-NOT: LV: Not vectorizing: VectorizeOnlyWhenForced is set
; ALL-NOT: LV: Not vectorizing: Disabled/already vectorized
; ALL-NOT: LV: Not vectorizing: Cannot prove legality
; ALL: LV: Loop hints: force=disabled
; ALL: LV: Not vectorizing: loop hasDisableAllTransformsHint.
; ALL: remark:
; ALL-SAME: loop not vectorized: loop transformations are disabled
; ALL: LV: Loop hints prevent vectorization
define void @disable_nonforced(ptr nocapture %a, i32 %n) {
entry:
br label %loop

loop:
%iv = phi i32 [ %iv.next, %loop ], [ 0, %entry ]
%arrayidx = getelementptr inbounds i32, ptr %a, i32 %iv
store i32 %iv, ptr %arrayidx, align 4
%iv.next = add i32 %iv, 1
%exitcond = icmp eq i32 %iv.next, %n
br i1 %exitcond, label %end, label %loop, !llvm.loop !2

end:
ret void
}
!2 = !{!2, !{!"llvm.loop.disable_nonforced"}}