[llvm] 76c6a8b - [LAA] Improve the output remark for LoopVectorize (#65832)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 15 21:51:48 PDT 2023
Author: Allen
Date: 2023-09-16T12:51:44+08:00
New Revision: 76c6a8bd36452bb6d17c650f8cd30c5cd5977bfc
URL: https://github.com/llvm/llvm-project/commit/76c6a8bd36452bb6d17c650f8cd30c5cd5977bfc
DIFF: https://github.com/llvm/llvm-project/commit/76c6a8bd36452bb6d17c650f8cd30c5cd5977bfc.diff
LOG: [LAA] Improve the output remark for LoopVectorize (#65832)
Don't report 'Use #pragma loop distribute(enable) to allow loop
distribution' when we already add #pragma clang loop distribute(enable)
Fixes https://github.com/llvm/llvm-project/issues/64637
Added:
llvm/test/Analysis/LoopAccessAnalysis/pr64637.ll
Modified:
llvm/lib/Analysis/LoopAccessAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 4dd150492453f72..8a779ac9fb94f64 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2505,12 +2505,24 @@ void LoopAccessInfo::emitUnsafeDependenceRemark() {
LLVM_DEBUG(dbgs() << "LAA: unsafe dependent memory operations in loop\n");
// Emit remark for first unsafe dependence
+ bool HasForcedDistribution = false;
+ std::optional<const MDOperand *> Value =
+ findStringMetadataForLoop(TheLoop, "llvm.loop.distribute.enable");
+ if (Value) {
+ const MDOperand *Op = *Value;
+ assert(Op && mdconst::hasa<ConstantInt>(*Op) && "invalid metadata");
+ HasForcedDistribution = mdconst::extract<ConstantInt>(*Op)->getZExtValue();
+ }
+
+ const std::string Info =
+ HasForcedDistribution
+ ? "unsafe dependent memory operations in loop."
+ : "unsafe dependent memory operations in loop. Use "
+ "#pragma loop distribute(enable) to allow loop distribution "
+ "to attempt to isolate the offending operations into a separate "
+ "loop";
OptimizationRemarkAnalysis &R =
- recordAnalysis("UnsafeDep", Dep.getDestination(*this))
- << "unsafe dependent memory operations in loop. Use "
- "#pragma loop distribute(enable) to allow loop distribution "
- "to attempt to isolate the offending operations into a separate "
- "loop";
+ recordAnalysis("UnsafeDep", Dep.getDestination(*this)) << Info;
switch (Dep.Type) {
case MemoryDepChecker::Dependence::NoDep:
diff --git a/llvm/test/Analysis/LoopAccessAnalysis/pr64637.ll b/llvm/test/Analysis/LoopAccessAnalysis/pr64637.ll
new file mode 100644
index 000000000000000..4d4d2bf3eee8e0f
--- /dev/null
+++ b/llvm/test/Analysis/LoopAccessAnalysis/pr64637.ll
@@ -0,0 +1,55 @@
+; RUN: opt -S -passes='print<access-info>' -pass-remarks-analysis=loop-vectorize -disable-output < %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
+
+; Test that LoopVectorize don't report 'Use #pragma loop distribute(enable) to allow loop distribution'
+; when we already add #pragma clang loop distribute(enable).
+;
+; Testcase derived from the following C:
+;
+; #define M 100
+; void foo (int *restrict y, int *restrict x, int *restrict indices, int n)
+; {
+; int k = 3;
+; #pragma clang loop distribute(enable)
+; for (int i = 0; i < n; i++) {
+; y[i + k * M] = y[i + k* M] + 1;
+; y[i + k * (M+1)] = indices[i] + 2;
+; }
+; }
+
+define void @foo(ptr noalias nocapture noundef %y, ptr noalias nocapture noundef readnone %x, ptr noalias nocapture noundef readonly %indices, i32 noundef %n) {
+; ANALYSIS: Report: unsafe dependent memory operations in loop.
+; ANALYSIS: Backward loop carried data dependence that prevents store-to-load forwarding.
+entry:
+ %cmp22 = icmp sgt i32 %n, 0
+ br i1 %cmp22, label %for.body.preheader, label %for.cond.cleanup
+
+for.body.preheader: ; preds = %entry
+ %wide.trip.count = zext i32 %n to i64
+ br label %for.body
+
+for.cond.cleanup.loopexit: ; preds = %for.body
+ br label %for.cond.cleanup
+
+for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
+ ret void
+
+for.body: ; preds = %for.body, %for.body.preheader
+ %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
+ %0 = add nuw nsw i64 %indvars.iv, 300
+ %arrayidx = getelementptr inbounds i32, ptr %y, i64 %0
+ %1 = load i32, ptr %arrayidx, align 4
+ %add1 = add nsw i32 %1, 1
+ store i32 %add1, ptr %arrayidx, align 4
+ %arrayidx7 = getelementptr inbounds i32, ptr %indices, i64 %indvars.iv
+ %2 = load i32, ptr %arrayidx7, align 4
+ %add8 = add nsw i32 %2, 2
+ %3 = add nuw nsw i64 %indvars.iv, 303
+ %arrayidx12 = getelementptr inbounds i32, ptr %y, i64 %3
+ store i32 %add8, ptr %arrayidx12, align 4
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+ %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
+ br i1 %exitcond.not, label %for.cond.cleanup.loopexit, label %for.body, !llvm.loop !0
+}
+
+!0 = distinct !{!0, !1}
+!1 = !{!"llvm.loop.distribute.enable", i1 true}
More information about the llvm-commits
mailing list