Skip to content

Commit 724a63b

Browse files
committed
[LV] Use more accurate getSCEV/MemChecks in GeneratedRTCheck::hasChecks.
Update hasChecks to use getSCEV/MemRuntimeChecks(), which automatically handles checking for known-false checks. This improves a few cases where we previously did not add metadata to disable runtime unrolling, due to runtime checks, even though no runtime checks are needed.
1 parent 1b8bedb commit 724a63b

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ class GeneratedRTChecks {
20012001

20022002
/// Retrieves the SCEVCheckCond and SCEVCheckBlock that were generated as IR
20032003
/// outside VPlan.
2004-
std::pair<Value *, BasicBlock *> getSCEVChecks() {
2004+
std::pair<Value *, BasicBlock *> getSCEVChecks() const {
20052005
using namespace llvm::PatternMatch;
20062006
if (!SCEVCheckCond || match(SCEVCheckCond, m_ZeroInt()))
20072007
return {nullptr, nullptr};
@@ -2011,7 +2011,7 @@ class GeneratedRTChecks {
20112011

20122012
/// Retrieves the MemCheckCond and MemCheckBlock that were generated as IR
20132013
/// outside VPlan.
2014-
std::pair<Value *, BasicBlock *> getMemRuntimeChecks() {
2014+
std::pair<Value *, BasicBlock *> getMemRuntimeChecks() const {
20152015
using namespace llvm::PatternMatch;
20162016
if (MemRuntimeCheckCond && match(MemRuntimeCheckCond, m_ZeroInt()))
20172017
return {nullptr, nullptr};
@@ -2020,9 +2020,7 @@ class GeneratedRTChecks {
20202020

20212021
/// Return true if any runtime checks have been added
20222022
bool hasChecks() const {
2023-
using namespace llvm::PatternMatch;
2024-
return (SCEVCheckCond && !match(SCEVCheckCond, m_ZeroInt())) ||
2025-
MemRuntimeCheckCond;
2023+
return getSCEVChecks().first || getMemRuntimeChecks().first;
20262024
}
20272025
};
20282026
} // namespace

llvm/test/Transforms/LoopVectorize/runtime-check-needed-but-empty.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ exit:
7171
ret void
7272
}
7373

74-
; FIXME: !llvm.loop.unroll.runtime.disable metadata should be added to the
74+
; !llvm.loop.unroll.runtime.disable metadata should be added to the
7575
; scalar loop, as there are no runtime checks needed (or they can be proven
7676
; false).
7777
define void @diff_memcheck_known_false_for_vf_4(ptr %B, ptr %A, ptr %end) {
@@ -151,5 +151,5 @@ exit:
151151
; CHECK: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
152152
; CHECK: [[LOOP3]] = distinct !{[[LOOP3]], [[META1]]}
153153
; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META1]], [[META2]]}
154-
; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]]}
154+
; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META2]], [[META1]]}
155155
;.

0 commit comments

Comments
 (0)