[PATCH] D119261: [DependenceAnalysis][PR52170] Conservative crash on overflowed loop backedge
Artem Radzikhovskyy via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 8 09:52:29 PST 2022
artemrad created this revision.
artemrad added reviewers: uabelho, fhahn, philip.pfaffe, pfaffe, bmahjour, Meinersbur.
artemrad added a project: LLVM.
Herald added subscribers: javed.absar, hiraditya.
artemrad requested review of this revision.
Herald added a subscriber: llvm-commits.
The following commit (https://github.com/llvm/llvm-project/commit/7086025d6567562d31fadbaccf08b4fd72ec2100) enabled delinearization of fixed sized arrays. It is now possible to propagate SIV constraints to coupled subscripts in more cases, resulting in more accurate dependence analysis. When a SIV constraint is propagated we re-classify the other non-SIV subscripts. It is possible that the re-classified subscript is now marked as non-linear, in cases where we cannot prove that the taken back-edge of the loop may not overflow.
Changes:
- Removed overly conservative code (that is causing the crash reported in the bug), in checkSubscript. SCEVs already do the overflow checks that the code was targeting.
- Added a new LIT test to test that DA reports conservative dependencies when it cannot be determined if overflow will happen in the AddRec
https://reviews.llvm.org/D119261
Files:
llvm/lib/Analysis/DependenceAnalysis.cpp
llvm/test/Analysis/DependenceAnalysis/TripCountOverflow.ll
Index: llvm/test/Analysis/DependenceAnalysis/TripCountOverflow.ll
===================================================================
--- /dev/null
+++ llvm/test/Analysis/DependenceAnalysis/TripCountOverflow.ll
@@ -0,0 +1,40 @@
+; RUN: opt %s -disable-output "-passes=print<da>" 2>&1 | FileCheck %s
+
+; [PR52170]
+; Test that in cases where SIV propagation does not produce a linear equation
+; (e.g. the trip count of the post propagation SCEV can overflow) produce a
+; conservative answer - don't crash.
+; CHECK-LABEL: dynamic_trip_count
+; CHECK: da analyze - output [* S]!
+; CHECK: da analyze - output [* *|<]!
+; CHECK: da analyze - output [* *]!
+
+define void @dynamic_trip_count(i32 %n) {
+entry:
+ %array = alloca [2 x [5 x i32]], align 1
+ br label %for.outer
+
+for.outer:
+ %i = phi i32 [ 0, %entry ], [ %add1140.i.i, %cleanup ]
+ %i.trunc = trunc i32 %i to i16
+ %i.trunc.3 = add i16 %i.trunc, 3
+ %i.ptr = getelementptr inbounds [2 x [5 x i32]], [2 x [5 x i32]]* %array, i16 0, i16 %i.trunc, i16 %i.trunc.3
+ br label %for.inner
+
+for.inner:
+ %j = phi i32 [ 0, %for.outer ], [ %j.1, %for.inner ]
+ store i32 undef, i32* %i.ptr, align 1
+ %j.trunc = trunc i32 %j to i16
+ %j.ptr = getelementptr inbounds [2 x [5 x i32]], [2 x [5 x i32]]* %array, i16 0, i16 %j.trunc, i16 %i.trunc.3
+ store i32 0, i32* %j.ptr, align 1
+ %j.1 = add nuw nsw i32 %j, 1
+ br i1 false, label %for.inner, label %cleanup
+
+cleanup:
+ %add1140.i.i = add nuw nsw i32 %i, 1
+ %cmp602.i.i = icmp slt i32 %i, %n
+ br i1 %cmp602.i.i, label %for.outer, label %other
+
+other:
+ ret void
+}
\ No newline at end of file
Index: llvm/lib/Analysis/DependenceAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/DependenceAnalysis.cpp
+++ llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -899,14 +899,7 @@
return isLoopInvariant(Expr, LoopNest);
const SCEV *Start = AddRec->getStart();
const SCEV *Step = AddRec->getStepRecurrence(*SE);
- const SCEV *UB = SE->getBackedgeTakenCount(AddRec->getLoop());
- if (!isa<SCEVCouldNotCompute>(UB)) {
- if (SE->getTypeSizeInBits(Start->getType()) <
- SE->getTypeSizeInBits(UB->getType())) {
- if (!AddRec->getNoWrapFlags())
- return false;
- }
- }
+
if (!isLoopInvariant(Step, LoopNest))
return false;
if (IsSrc)
@@ -3296,12 +3289,12 @@
int Size = SrcSubscripts.size();
LLVM_DEBUG({
- dbgs() << "\nSrcSubscripts: ";
+ dbgs() << "SrcSubscripts:\n";
for (int I = 0; I < Size; I++)
- dbgs() << *SrcSubscripts[I];
- dbgs() << "\nDstSubscripts: ";
+ dbgs() << "\t" << *SrcSubscripts[I] << "\n";
+ dbgs() << "DstSubscripts:\n";
for (int I = 0; I < Size; I++)
- dbgs() << *DstSubscripts[I];
+ dbgs() << "\t" << *DstSubscripts[I] << "\n";
});
// The delinearization transforms a single-subscript MIV dependence test into
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119261.406881.patch
Type: text/x-patch
Size: 2907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220208/1840bc9b/attachment.bin>
More information about the llvm-commits
mailing list