[PATCH] D158856: [LAA] Improve the output remark for LoopVectorize
Allen zhong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 29 23:49:23 PDT 2023
Allen updated this revision to Diff 554588.
Allen added a comment.
address comment, replace the case under **llvm/test/Analysis/LoopAccessAnalysis** and run with **LoopAccessAnalysis ** only
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158856/new/
https://reviews.llvm.org/D158856
Files:
llvm/lib/Analysis/LoopAccessAnalysis.cpp
llvm/test/Analysis/LoopAccessAnalysis/pr64637.ll
Index: llvm/test/Analysis/LoopAccessAnalysis/pr64637.ll
===================================================================
--- /dev/null
+++ 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}
Index: llvm/lib/Analysis/LoopAccessAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2505,12 +2505,24 @@
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158856.554588.patch
Type: text/x-patch
Size: 4147 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230830/835c9e19/attachment.bin>
More information about the llvm-commits
mailing list