Skip to content

Commit 616f3b5

Browse files
scui-ibmShimin Cui
andauthored
[DA] Fix crash when two loops have different type sizes of becount (llvm#165021)
The type sizes of backedge taken counts for two loops can be different and this is to fix the crash in haveSameSD (llvm#165014). --------- Co-authored-by: Shimin Cui <[email protected]>
1 parent 90489ad commit 616f3b5

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed

llvm/lib/Analysis/DependenceAnalysis.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,14 @@ bool DependenceInfo::haveSameSD(const Loop *SrcLoop,
11311131
if (SE->hasLoopInvariantBackedgeTakenCount(DstLoop))
11321132
DstUP = SE->getBackedgeTakenCount(DstLoop);
11331133

1134-
if (SrcUB != nullptr && DstUP != nullptr &&
1135-
SE->isKnownPredicate(ICmpInst::ICMP_EQ, SrcUB, DstUP))
1136-
return true;
1134+
if (SrcUB != nullptr && DstUP != nullptr) {
1135+
Type *WiderType = SE->getWiderType(SrcUB->getType(), DstUP->getType());
1136+
SrcUB = SE->getNoopOrZeroExtend(SrcUB, WiderType);
1137+
DstUP = SE->getNoopOrZeroExtend(DstUP, WiderType);
1138+
1139+
if (SE->isKnownPredicate(ICmpInst::ICMP_EQ, SrcUB, DstUP))
1140+
return true;
1141+
}
11371142

11381143
return false;
11391144
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 | FileCheck %s
2+
3+
define void @f1() {
4+
; CHECK-LABEL: 'f1'
5+
; CHECK-NEXT: Src: store i32 0, ptr null, align 4 --> Dst: store i32 0, ptr null, align 4
6+
; CHECK-NEXT: da analyze - consistent output [S]!
7+
; CHECK-NEXT: Src: store i32 0, ptr null, align 4 --> Dst: %2 = load i32, ptr null, align 4
8+
; CHECK-NEXT: da analyze - consistent flow [|<]!
9+
; CHECK-NEXT: Src: %2 = load i32, ptr null, align 4 --> Dst: %2 = load i32, ptr null, align 4
10+
; CHECK-NEXT: da analyze - consistent input [S]!
11+
;
12+
entry:
13+
br label %for.1.header
14+
15+
for.1.header: ; preds = %for.2.end, %entry
16+
br label %for.1.body
17+
18+
for.1.body: ; preds = %for.1.body, %whiledo
19+
%0 = phi i32 [ 0, %for.1.header ], [ 1, %for.1.body ]
20+
store i32 0, ptr null, align 4
21+
%1 = icmp ult i32 %0, 1
22+
br i1 %1, label %for.1.body, label %for.1.end
23+
24+
for.1.end: ; preds = %for.1.body
25+
br label %for.2.body
26+
27+
for.2.body: ; preds = %for.2.body, %for.1.end
28+
%2 = load i32, ptr null, align 4
29+
br i1 false, label %for.2.body, label %exit
30+
31+
exit: ; preds = %for.2.body
32+
ret void
33+
}
34+
35+
define void @f2() {
36+
; CHECK-LABEL: 'f2'
37+
; CHECK-NEXT: Src: store i32 0, ptr null, align 4 --> Dst: store i32 0, ptr null, align 4
38+
; CHECK-NEXT: da analyze - consistent output [S]!
39+
; CHECK-NEXT: Src: store i32 0, ptr null, align 4 --> Dst: %3 = load i32, ptr null, align 4
40+
; CHECK-NEXT: da analyze - flow [|<] / assuming 1 loop level(s) fused: [S|<]!
41+
; CHECK-NEXT: Src: %3 = load i32, ptr null, align 4 --> Dst: %3 = load i32, ptr null, align 4
42+
; CHECK-NEXT: da analyze - consistent input [S]!
43+
;
44+
entry:
45+
br label %for.1.header
46+
47+
for.1.header: ; preds = %for.2.end, %entry
48+
br label %for.1.body
49+
50+
for.1.body: ; preds = %for.1.body, %whiledo
51+
%0 = phi i32 [ 0, %for.1.header ], [ 1, %for.1.body ]
52+
store i32 0, ptr null, align 4
53+
%1 = icmp ult i32 %0, 1
54+
br i1 %1, label %for.1.body, label %for.1.end
55+
56+
for.1.end: ; preds = %for.1.body
57+
br label %for.2.body
58+
59+
for.2.body: ; preds = %for.2.body, %for.1.end
60+
%2 = phi i64 [ 0, %for.1.end ], [ %4, %for.2.body ]
61+
%3 = load i32, ptr null, align 4
62+
%4 = add nuw nsw i64 %2, 1
63+
%5 = icmp ult i64 %4, 2
64+
br i1 %5, label %for.2.body, label %exit
65+
66+
exit: ; preds = %for.2.body
67+
ret void
68+
}

0 commit comments

Comments
 (0)