Skip to content

Commit 75781fa

Browse files
swalk-qualcommSteve Walk
andauthored
Hexagon loop idiom pass segfaults when -debug present (llvm#121828)
There was an unprotected use of a function that could return the null pointer. --------- Co-authored-by: Steve Walk <[email protected]>
1 parent bb9785a commit 75781fa

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,8 @@ bool PolynomialMultiplyRecognize::recognize() {
17961796
IterCount = CV->getValue()->getZExtValue() + 1;
17971797

17981798
Value *CIV = getCountIV(LoopB);
1799+
if (CIV == nullptr)
1800+
return false;
17991801
ParsedValues PV;
18001802
Simplifier PreSimp;
18011803
PV.IterCount = IterCount;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
; RUN: opt -debug -S -march=hexagon -O2 < %s | FileCheck %s
2+
; REQUIRES: asserts
3+
; CHECK: define dso_local void @complexMultAccum
4+
target triple = "hexagon"
5+
6+
; Function Attrs: noinline nounwind
7+
define dso_local void @complexMultAccum(i32 noundef %n) #0 {
8+
entry:
9+
%n.addr = alloca i32, align 4
10+
%run_c_code = alloca i8, align 1
11+
%run_asm_code = alloca i8, align 1
12+
%iOutter = alloca i32, align 4
13+
%iOutter1 = alloca i32, align 4
14+
store i32 %n, ptr %n.addr, align 4
15+
store i8 1, ptr %run_c_code, align 1
16+
store i8 0, ptr %run_asm_code, align 1
17+
%0 = load i8, ptr %run_c_code, align 1
18+
%tobool = icmp ne i8 %0, 0
19+
br i1 %tobool, label %if.then, label %if.end
20+
21+
if.then: ; preds = %entry
22+
store i32 0, ptr %iOutter, align 4
23+
br label %for.cond
24+
25+
for.cond: ; preds = %for.inc, %if.then
26+
%1 = load i32, ptr %iOutter, align 4
27+
%cmp = icmp slt i32 %1, 2
28+
br i1 %cmp, label %for.body, label %for.end
29+
30+
for.body: ; preds = %for.cond
31+
br label %for.inc
32+
33+
for.inc: ; preds = %for.body
34+
%2 = load i32, ptr %iOutter, align 4
35+
%inc = add nsw i32 %2, 1
36+
store i32 %inc, ptr %iOutter, align 4
37+
br label %for.cond, !llvm.loop !3
38+
39+
for.end: ; preds = %for.cond
40+
store i32 0, ptr %iOutter1, align 4
41+
br label %for.cond2
42+
43+
for.cond2: ; preds = %for.inc5, %for.end
44+
%3 = load i32, ptr %iOutter1, align 4
45+
%cmp3 = icmp slt i32 %3, 2
46+
br i1 %cmp3, label %for.body4, label %for.end7
47+
48+
for.body4: ; preds = %for.cond2
49+
br label %for.inc5
50+
51+
for.inc5: ; preds = %for.body4
52+
%4 = load i32, ptr %iOutter1, align 4
53+
%inc6 = add nsw i32 %4, 1
54+
store i32 %inc6, ptr %iOutter1, align 4
55+
br label %for.cond2, !llvm.loop !5
56+
57+
for.end7: ; preds = %for.cond2
58+
br label %if.end
59+
60+
if.end: ; preds = %for.end7, %entry
61+
ret void
62+
}
63+
64+
attributes #0 = { noinline nounwind "approx-func-fp-math"="true" "frame-pointer"="all" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="hexagonv79" "target-features"="+v79,-long-calls" "unsafe-fp-math"="true" }
65+
66+
!llvm.module.flags = !{!0, !1}
67+
!llvm.ident = !{!2}
68+
69+
!0 = !{i32 1, !"wchar_size", i32 4}
70+
!1 = !{i32 7, !"frame-pointer", i32 2}
71+
!2 = !{!"LLVM Clang"}
72+
!3 = distinct !{!3, !4}
73+
!4 = !{!"llvm.loop.mustprogress"}
74+
!5 = distinct !{!5, !4}
75+

0 commit comments

Comments
 (0)