1 ; RUN: opt -S -loop-reduce %s -o - | FileCheck %s
2 ; RUN: opt --try-experimental-debuginfo-iterators -S -loop-reduce %s -o - | FileCheck %s
3 ; REQUIRES: x86-registered-target
5 ;; Ensure that we retain debuginfo for the induction variable and dependant
6 ;; variables when loop strength reduction is applied to the loop.
7 ;; This IR produced from:
9 ;; clang -S -emit-llvm -Xclang -disable-llvm-passes -g lsr-basic.cpp -o
10 ;; Then executing opt -O2 up to the the loopFullUnroll pass.
11 ;; void basic_recurrence(unsigned k, unsigned size, unsigned *data)
14 ;; #pragma clang loop vectorize(disable)
16 ;; unsigned comp = i * k;
21 ; CHECK: #dbg_value(i64 %lsr.iv, ![[i:[0-9]+]], !DIExpression(),
22 ; CHECK: #dbg_value(!DIArgList(i64 %lsr.iv, i32 %k), ![[comp:[0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_mul, DW_OP_stack_value),
23 ; CHECK: #dbg_value(i64 %lsr.iv, ![[i]], !DIExpression(DW_OP_consts, 1, DW_OP_plus, DW_OP_stack_value),
24 ; CHECK: ![[i]] = !DILocalVariable(name: "i"
25 ; CHECK: ![[comp]] = !DILocalVariable(name: "comp"
27 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
28 target triple = "x86_64-unknown-linux-gnu"
30 define dso_local void @_Z16basic_recurrencejjPj(i32 %k, i32 %size, ptr nocapture %data) local_unnamed_addr !dbg !7 {
32 call void @llvm.dbg.value(metadata i32 %k, metadata !13, metadata !DIExpression()), !dbg !14
33 call void @llvm.dbg.value(metadata i32 %size, metadata !15, metadata !DIExpression()), !dbg !14
34 call void @llvm.dbg.value(metadata ptr %data, metadata !16, metadata !DIExpression()), !dbg !14
35 br label %while.cond, !dbg !14
37 while.cond: ; preds = %while.body, %entry
38 %i.0 = phi i32 [ 0, %entry ], [ %inc, %while.body ]
39 call void @llvm.dbg.value(metadata i32 %i.0, metadata !17, metadata !DIExpression()), !dbg !14
40 %cmp = icmp ult i32 %i.0, %size, !dbg !14
41 br i1 %cmp, label %while.body, label %while.end, !dbg !14
43 while.body: ; preds = %while.cond
44 %mul = mul i32 %i.0, %k, !dbg !18
45 call void @llvm.dbg.value(metadata i32 %mul, metadata !20, metadata !DIExpression()), !dbg !18
46 %idxprom = zext i32 %i.0 to i64, !dbg !18
47 %arrayidx = getelementptr inbounds i32, ptr %data, i64 %idxprom, !dbg !18
48 store i32 %mul, ptr %arrayidx, align 4, !dbg !18
49 %inc = add nuw i32 %i.0, 1, !dbg !18
50 call void @llvm.dbg.value(metadata i32 %inc, metadata !17, metadata !DIExpression()), !dbg !14
51 br label %while.cond, !dbg !14, !llvm.loop !21
53 while.end: ; preds = %while.cond
57 declare void @llvm.dbg.value(metadata, metadata, metadata)
60 !llvm.module.flags = !{!3, !4, !5}
63 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
64 !1 = !DIFile(filename: "basic.cpp", directory: "/test")
66 !3 = !{i32 7, !"Dwarf Version", i32 4}
67 !4 = !{i32 2, !"Debug Info Version", i32 3}
68 !5 = !{i32 1, !"wchar_size", i32 4}
69 !6 = !{!"clang version 12.0.0)"}
70 !7 = distinct !DISubprogram(name: "basic_recurrence", linkageName: "_Z16basic_recurrencejjPj", scope: !8, file: !8, line: 82, type: !9, scopeLine: 83, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
71 !8 = !DIFile(filename: "./basic.cpp", directory: "/test")
72 !9 = !DISubroutineType(types: !10)
73 !10 = !{null, !11, !11, !12}
74 !11 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
75 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
76 !13 = !DILocalVariable(name: "k", arg: 1, scope: !7, file: !8, line: 82, type: !11)
77 !14 = !DILocation(line: 0, scope: !7)
78 !15 = !DILocalVariable(name: "size", arg: 2, scope: !7, file: !8, line: 82, type: !11)
79 !16 = !DILocalVariable(name: "data", arg: 3, scope: !7, file: !8, line: 82, type: !12)
80 !17 = !DILocalVariable(name: "i", scope: !7, file: !8, line: 84, type: !11)
81 !18 = !DILocation(line: 87, column: 27, scope: !19)
82 !19 = distinct !DILexicalBlock(scope: !7, file: !8, line: 86, column: 22)
83 !20 = !DILocalVariable(name: "comp", scope: !19, file: !8, line: 87, type: !11)
84 !21 = distinct !{!21, !22, !23, !24, !25}
85 !22 = !DILocation(line: 86, column: 5, scope: !7)
86 !23 = !DILocation(line: 90, column: 5, scope: !7)
87 !24 = !{!"llvm.loop.mustprogress"}
88 !25 = !{!"llvm.loop.vectorize.width", i32 1}