Skip to content

Commit 54dc073

Browse files
kasuga-fjGeneraluseAI
authored andcommitted
[LoopCacheAnalysis] Fix crash after llvm#164798 (llvm#169486)
Fix the assertion failure after llvm#164798. The issue is that the comparison `Sizes.back() == ElementSize` can fail when their types are different. We should cast them to the wider type before the comparison.
1 parent e04c71f commit 54dc073

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

llvm/lib/Analysis/LoopCacheAnalysis.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,16 @@ bool IndexedReference::tryDelinearizeFixedSize(
368368
// the load/store instruction being analyzed. It is not needed for further
369369
// analysis.
370370
// TODO: Maybe this property should be enforced in delinearizeFixedSizeArray.
371+
#ifndef NDEBUG
371372
assert(!Sizes.empty() && Subscripts.size() == Sizes.size() &&
372-
Sizes.back() == ElementSize && "Unexpected delinearization result");
373+
"Inconsistent length of Sizes and Subscripts");
374+
Type *WideTy =
375+
SE.getWiderType(ElementSize->getType(), Sizes.back()->getType());
376+
const SCEV *ElemSizeExt = SE.getNoopOrZeroExtend(ElementSize, WideTy);
377+
const SCEV *LastSizeExt = SE.getNoopOrZeroExtend(Sizes.back(), WideTy);
378+
assert(ElemSizeExt == LastSizeExt && "Unexpected last element of Sizes");
379+
#endif
380+
373381
Sizes.pop_back();
374382
return true;
375383
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: opt < %s -passes='print<loop-cache-cost>' -disable-output
2+
3+
; Ensure no crash happens after PR #164798
4+
5+
target datalayout = "p21:32:16"
6+
7+
define i16 @f() {
8+
entry:
9+
br label %for.cond1.preheader
10+
11+
for.cond1.preheader:
12+
%i.02 = phi i16 [ 0, %entry ], [ %inc8, %for.cond.cleanup3 ]
13+
%idxprom = zext i16 %i.02 to i32
14+
%arrayidx = getelementptr [18 x i16], ptr addrspace(21) null, i32 %idxprom
15+
br label %for.body4
16+
17+
for.cond.cleanup:
18+
ret i16 0
19+
20+
for.cond.cleanup3:
21+
%inc8 = add i16 %i.02, 1
22+
%exitcond3.not = icmp eq i16 %inc8, 0
23+
br i1 %exitcond3.not, label %for.cond.cleanup, label %for.cond1.preheader
24+
25+
for.body4:
26+
%j.01 = phi i16 [ 0, %for.cond1.preheader ], [ %inc.2, %for.body4 ]
27+
%idxprom5 = zext i16 %j.01 to i32
28+
%arrayidx6 = getelementptr i16, ptr addrspace(21) %arrayidx, i32 %idxprom5
29+
store i16 0, ptr addrspace(21) %arrayidx6, align 1
30+
%inc.2 = add i16 %j.01, 1
31+
%exitcond.not.2 = icmp eq i16 %inc.2, 18
32+
br i1 %exitcond.not.2, label %for.cond.cleanup3, label %for.body4
33+
}

0 commit comments

Comments
 (0)