xref: /llvm-project/llvm/test/Transforms/LoopStrengthReduce/pr51656.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -loop-reduce -S %s | FileCheck %s
2; RUN: opt --try-experimental-debuginfo-iterators -loop-reduce -S %s | FileCheck %s
3
4;; This test ensures that no attempt is made to translate long SCEVs into
5;; DIExpressions. Attempting the translation can use excessive resources and
6;; result in crashes.
7
8target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9target triple = "x86_64-unknown-linux-gnu"
10
11@c = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0
12@b = dso_local local_unnamed_addr global i32 0, align 4, !dbg !9
13@a = dso_local local_unnamed_addr global i32 0, align 4, !dbg !5
14
15define dso_local i32 @d() local_unnamed_addr #0 !dbg !16 {
16entry:
17  %b.promoted = load i32, ptr @b, align 4, !tbaa !29
18  %mul = mul nsw i32 %b.promoted, %b.promoted, !dbg !33
19  %mul.1 = mul nsw i32 %mul, %mul, !dbg !33
20  %mul.2 = mul nsw i32 %mul.1, %mul.1, !dbg !33
21  %mul.3 = mul nsw i32 %mul.2, %mul.2, !dbg !33
22  %mul.4 = mul nsw i32 %mul.3, %mul.3, !dbg !33
23  %mul.5 = mul nsw i32 %mul.4, %mul.4, !dbg !33
24  %mul.6 = mul nsw i32 %mul.5, %mul.5, !dbg !33
25  %mul.7 = mul nsw i32 %mul.6, %mul.6, !dbg !33
26  %mul.8 = mul nsw i32 %mul.7, %mul.7, !dbg !33
27  %mul.9 = mul nsw i32 %mul.8, %mul.8, !dbg !33
28  store i32 49, ptr @c, align 4, !dbg !36, !tbaa !29
29  store i32 %mul.9, ptr @b, align 4, !dbg !37, !tbaa !29
30  %.pr = load i32, ptr @a, align 4, !dbg !38, !tbaa !29
31  %tobool.not8 = icmp eq i32 %.pr, 0, !dbg !39
32  br i1 %tobool.not8, label %for.end3, label %for.body2.preheader, !dbg !39
33
34for.body2.preheader:                              ; preds = %entry
35  br label %for.body2, !dbg !39
36
37for.body2:                                        ; preds = %for.body2.preheader, %for.body2
38  %0 = phi i32 [ %sub, %for.body2 ], [ %.pr, %for.body2.preheader ]
39  %sub = sub nsw i32 %0, %mul.9, !dbg !40
40  ; CHECK: #dbg_value(!DIArgList(i32 poison, i32 %mul.9), ![[VAR_e:[0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_LLVM_convert, 64, DW_ATE_signed, DW_OP_stack_value),
41  call void @llvm.dbg.value(metadata i32 %sub, metadata !20, metadata !DIExpression(DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_LLVM_convert, 64, DW_ATE_signed, DW_OP_stack_value)), !dbg !41
42  %tobool.not = icmp eq i32 %sub, 0, !dbg !39
43  br i1 %tobool.not, label %for.cond1.for.end3_crit_edge, label %for.body2, !dbg !39, !llvm.loop !42
44
45for.cond1.for.end3_crit_edge:                     ; preds = %for.body2
46  store i32 0, ptr @a, align 4, !dbg !40, !tbaa !29
47  br label %for.end3, !dbg !39
48
49for.end3:                                         ; preds = %for.cond1.for.end3_crit_edge, %entry
50  ret i32 poison, !dbg !45
51}
52
53declare void @llvm.dbg.value(metadata, metadata, metadata) #1
54
55!llvm.dbg.cu = !{!2}
56!llvm.module.flags = !{!11, !12, !13, !14}
57!llvm.ident = !{!15}
58
59!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
60!1 = distinct !DIGlobalVariable(name: "c", scope: !2, file: !7, line: 2, type: !8, isLocal: false, isDefinition: true)
61!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
62!3 = !DIFile(filename: "test.c", directory: "/test")
63!4 = !{!5, !9, !0}
64!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
65!6 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !7, line: 2, type: !8, isLocal: false, isDefinition: true)
66!7 = !DIFile(filename: "./test.c", directory: "/test")
67!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
68!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
69!10 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !7, line: 2, type: !8, isLocal: false, isDefinition: true)
70!11 = !{i32 7, !"Dwarf Version", i32 4}
71!12 = !{i32 2, !"Debug Info Version", i32 3}
72!13 = !{i32 1, !"wchar_size", i32 4}
73!14 = !{i32 7, !"uwtable", i32 1}
74!15 = !{!"clang version 14.0.0"}
75!16 = distinct !DISubprogram(name: "d", scope: !7, file: !7, line: 3, type: !17, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19)
76!17 = !DISubroutineType(types: !18)
77!18 = !{!8}
78!19 = !{!20}
79; CHECK: ![[VAR_e]] = !DILocalVariable(name: "e", scope: !21, file: !7, line: 8, type: !24)
80!20 = !DILocalVariable(name: "e", scope: !21, file: !7, line: 8, type: !24)
81!21 = distinct !DILexicalBlock(scope: !22, file: !7, line: 7, column: 14)
82!22 = distinct !DILexicalBlock(scope: !23, file: !7, line: 7, column: 3)
83!23 = distinct !DILexicalBlock(scope: !16, file: !7, line: 7, column: 3)
84!24 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint64_t", file: !25, line: 27, baseType: !26)
85!25 = !DIFile(filename: "/usr/include/x86_64-linux-gnu/bits/stdint-uintn.h", directory: "")
86!26 = !DIDerivedType(tag: DW_TAG_typedef, name: "__uint64_t", file: !27, line: 44, baseType: !28)
87!27 = !DIFile(filename: "/usr/include/x86_64-linux-gnu/bits/types.h", directory: "")
88!28 = !DIBasicType(name: "long unsigned int", size: 64, encoding: DW_ATE_unsigned)
89!29 = !{!30, !30, i64 0}
90!30 = !{!"int", !31, i64 0}
91!31 = !{!"omnipotent char", !32, i64 0}
92!32 = !{!"Simple C/C++ TBAA"}
93!33 = !DILocation(line: 6, column: 7, scope: !34)
94!34 = distinct !DILexicalBlock(scope: !35, file: !7, line: 5, column: 3)
95!35 = distinct !DILexicalBlock(scope: !16, file: !7, line: 5, column: 3)
96!36 = !DILocation(line: 0, scope: !16)
97!37 = !DILocation(line: 0, scope: !34)
98!38 = !DILocation(line: 7, column: 10, scope: !22)
99!39 = !DILocation(line: 7, column: 3, scope: !23)
100!40 = !DILocation(line: 8, column: 20, scope: !21)
101!41 = !DILocation(line: 0, scope: !21)
102!42 = distinct !{!42, !39, !43, !44}
103!43 = !DILocation(line: 9, column: 3, scope: !23)
104!44 = !{!"llvm.loop.mustprogress"}
105!45 = !DILocation(line: 10, column: 1, scope: !16)
106