1; RUN: opt -loop-unroll -unroll-runtime -unroll-allow-remainder -unroll-count=4 -unroll-remainder -S %s -o - | FileCheck %s 2target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 3target triple = "x86_64-unknown-linux-gnu" 4 5@b = common local_unnamed_addr global i32 0, align 4, !dbg !0 6@a = common local_unnamed_addr global i32* null, align 8, !dbg !6 7 8; Test that loop remainder unrolling doesn't corrupt debuginfo. This example 9; used to cause an assert, but also test that the unrolled backwards branches 10; have the same DILocation. 11 12; CHECK-LABEL: func_c 13; CHECK-LABEL: for.body.lr.ph: 14; CHECK: br i1 %[[CMP0:.*]], label %[[PRE:.*]], label %for.body.prol.loopexit, !dbg !24 15; CHECK-LABEL: for.body: 16; CHECK: br i1 %[[CMP1:.*]], label %[[CRIT_EDGE:.*]], label %for.body, !dbg !24, !llvm.loop !30 17; CHECK-LABEL: for.cond.for.end_crit_edge: 18; CHECK: br label %for.end, !dbg !24 19; CHECK-LABEL: for.body.prol.1: 20; CHECK: br i1 %[[CMP2:.*]], label %for.body.prol.2, label %[[EXIT:.*]], !dbg !24 21; CHECK-LABEL: for.body.prol.2: 22define i32 @func_c() local_unnamed_addr #0 !dbg !14 { 23entry: 24 %.pr = load i32, i32* @b, align 4, !dbg !17, !tbaa !20 25 %tobool1 = icmp eq i32 %.pr, 0, !dbg !24 26 br i1 %tobool1, label %for.end, label %for.body.lr.ph, !dbg !24 27 28for.body.lr.ph: 29 %a.promoted = load i32*, i32** @a, align 8, !dbg !25, !tbaa !26 30 %0 = sub i32 -2, %.pr, !dbg !24 31 %1 = and i32 %0, -2, !dbg !24 32 %2 = add i32 %.pr, %1, !dbg !24 33 br label %for.body, !dbg !24 34 35for.body: 36 %3 = phi i32* [ %a.promoted, %for.body.lr.ph ], [ %6, %for.body ], !dbg !28 37 %4 = phi i32 [ %.pr, %for.body.lr.ph ], [ %add, %for.body ] 38 %arrayidx = getelementptr inbounds i32, i32* %3, i64 1, !dbg !28 39 %5 = load i32, i32* %arrayidx, align 4, !dbg !28, !tbaa !20 40 %conv = sext i32 %5 to i64, !dbg !28 41 %6 = inttoptr i64 %conv to i32*, !dbg !28 42 %add = add nsw i32 %4, 2, !dbg !29 43 %tobool = icmp eq i32 %add, 0, !dbg !24 44 br i1 %tobool, label %for.cond.for.end_crit_edge, label %for.body, !dbg !24, !llvm.loop !30 45 46for.cond.for.end_crit_edge: 47 %7 = add i32 %2, 2, !dbg !24 48 store i32* %6, i32** @a, align 8, !dbg !25, !tbaa !26 49 store i32 %7, i32* @b, align 4, !dbg !32, !tbaa !20 50 br label %for.end, !dbg !24 51 52for.end: 53 ret i32 undef, !dbg !33 54} 55 56; CHECK-LABEL: func_d 57define void @func_d() local_unnamed_addr #1 !dbg !34 { 58entry: 59 ret void, !dbg !37 60} 61 62attributes #0 = { norecurse nounwind uwtable } 63attributes #0 = { norecurse nounwind readnone uwtable } 64 65!llvm.dbg.cu = !{!2} 66!llvm.module.flags = !{!10, !11, !12} 67!llvm.ident = !{!13} 68 69!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 70!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true) 71!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) 72!3 = !DIFile(filename: "loop.c", directory: "/work/projects/src/tests/unroll-debug-info") 73!4 = !{} 74!5 = !{!6, !0} 75!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 76!7 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) 77!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64) 78!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 79!10 = !{i32 2, !"Dwarf Version", i32 4} 80!11 = !{i32 2, !"Debug Info Version", i32 3} 81!12 = !{i32 1, !"wchar_size", i32 4} 82!13 = !{!"clang version 6.0.0"} 83!14 = distinct !DISubprogram(name: "c", scope: !3, file: !3, line: 3, type: !15, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !2, retainedNodes: !4) 84!15 = !DISubroutineType(types: !16) 85!16 = !{!9} 86!17 = !DILocation(line: 4, column: 12, scope: !18) 87!18 = distinct !DILexicalBlock(scope: !19, file: !3, line: 4, column: 5) 88!19 = distinct !DILexicalBlock(scope: !14, file: !3, line: 4, column: 5) 89!20 = !{!21, !21, i64 0} 90!21 = !{!"int", !22, i64 0} 91!22 = !{!"omnipotent char", !23, i64 0} 92!23 = !{!"Simple C/C++ TBAA"} 93!24 = !DILocation(line: 4, column: 5, scope: !19) 94!25 = !DILocation(line: 5, column: 13, scope: !18) 95!26 = !{!27, !27, i64 0} 96!27 = !{!"any pointer", !22, i64 0} 97!28 = !DILocation(line: 5, column: 15, scope: !18) 98!29 = !DILocation(line: 4, column: 21, scope: !18) 99!30 = distinct !{!30, !24, !31} 100!31 = !DILocation(line: 5, column: 18, scope: !19) 101!32 = !DILocation(line: 4, column: 17, scope: !18) 102!33 = !DILocation(line: 6, column: 1, scope: !14) 103!34 = distinct !DISubprogram(name: "d", scope: !3, file: !3, line: 7, type: !35, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !2, retainedNodes: !4) 104!35 = !DISubroutineType(types: !36) 105!36 = !{null} 106!37 = !DILocation(line: 7, column: 11, scope: !34) 107