1; RUN: opt -loop-reduce -S %s | FileCheck %s 2; RUN: opt --try-experimental-debuginfo-iterators -loop-reduce -S %s | FileCheck %s 3 4;; Test that LSR preserves debug-info for induction variables and scev-based 5;; salvaging produces short DIExpressions that use a constant offset from the 6;; induction variable. 7 8target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 9 10define dso_local void @foo(ptr nocapture %p) local_unnamed_addr !dbg !7 { 11; CHECK-LABEL: @foo( 12entry: 13 call void @llvm.dbg.value(metadata ptr %p, metadata !13, metadata !DIExpression()), !dbg !16 14 call void @llvm.dbg.value(metadata i8 0, metadata !14, metadata !DIExpression()), !dbg !17 15 br label %for.body, !dbg !18 16 17for.cond.cleanup: ; preds = %for.body 18 ret void, !dbg !19 19 20for.body: ; preds = %entry, %for.body 21; CHECK-LABEL: for.body: 22 %i.06 = phi i8 [ 0, %entry ], [ %inc, %for.body ] 23 %p.addr.05 = phi ptr [ %p, %entry ], [ %add.ptr, %for.body ] 24 call void @llvm.dbg.value(metadata i8 %i.06, metadata !14, metadata !DIExpression()), !dbg !17 25 call void @llvm.dbg.value(metadata ptr %p.addr.05, metadata !13, metadata !DIExpression()), !dbg !16 26; CHECK-NOT: #dbg_value(ptr undef 27; CHECK: #dbg_value(ptr %lsr.iv, ![[MID_p:[0-9]+]], !DIExpression(DW_OP_constu, 3, DW_OP_minus, DW_OP_stack_value), 28 %add.ptr = getelementptr inbounds i8, ptr %p.addr.05, i64 3, !dbg !20 29 call void @llvm.dbg.value(metadata ptr %add.ptr, metadata !13, metadata !DIExpression()), !dbg !16 30; CHECK-NOT: #dbg_value(ptr undef 31; CHECK: #dbg_value(ptr %lsr.iv, ![[MID_p]], !DIExpression(), 32 store i8 %i.06, ptr %add.ptr, align 1, !dbg !23, !tbaa !24 33 %inc = add nuw nsw i8 %i.06, 1, !dbg !27 34 call void @llvm.dbg.value(metadata i8 %inc, metadata !14, metadata !DIExpression()), !dbg !17 35 %exitcond.not = icmp eq i8 %inc, 32, !dbg !28 36 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body, !dbg !18, !llvm.loop !29 37} 38 39declare void @llvm.dbg.value(metadata, metadata, metadata) 40 41!llvm.dbg.cu = !{!0} 42!llvm.module.flags = !{!3, !4, !5} 43!llvm.ident = !{!6} 44 45!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) 46!1 = !DIFile(filename: "lsrdbg.c", directory: "/") 47!2 = !{} 48!3 = !{i32 7, !"Dwarf Version", i32 4} 49!4 = !{i32 2, !"Debug Info Version", i32 3} 50!5 = !{i32 1, !"wchar_size", i32 4} 51!6 = !{!"clang version 12.0.0"} 52!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) 53!8 = !DISubroutineType(types: !9) 54!9 = !{null, !10} 55!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) 56!11 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char) 57!12 = !{!13, !14} 58!13 = !DILocalVariable(name: "p", arg: 1, scope: !7, file: !1, line: 2, type: !10) 59; CHECK: ![[MID_p]] = !DILocalVariable(name: "p", arg: 1, scope: !7, file: !1, line: 2, type: !10) 60!14 = !DILocalVariable(name: "i", scope: !15, file: !1, line: 4, type: !11) 61!15 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 3) 62!16 = !DILocation(line: 0, scope: !7) 63!17 = !DILocation(line: 0, scope: !15) 64!18 = !DILocation(line: 4, column: 3, scope: !15) 65!19 = !DILocation(line: 8, column: 1, scope: !7) 66!20 = !DILocation(line: 5, column: 7, scope: !21) 67!21 = distinct !DILexicalBlock(scope: !22, file: !1, line: 4, column: 42) 68!22 = distinct !DILexicalBlock(scope: !15, file: !1, line: 4, column: 3) 69!23 = !DILocation(line: 6, column: 8, scope: !21) 70!24 = !{!25, !25, i64 0} 71!25 = !{!"omnipotent char", !26, i64 0} 72!26 = !{!"Simple C/C++ TBAA"} 73!27 = !DILocation(line: 4, column: 38, scope: !22) 74!28 = !DILocation(line: 4, column: 31, scope: !22) 75!29 = distinct !{!29, !18, !30, !31} 76!30 = !DILocation(line: 7, column: 3, scope: !15) 77!31 = !{!"llvm.loop.unroll.disable"} 78