1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -passes=loop-unroll -unroll-runtime -unroll-allow-remainder -unroll-count=4 -unroll-remainder -S %s -o - | FileCheck %s 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4target triple = "x86_64-unknown-linux-gnu" 5 6@b = common local_unnamed_addr global i32 0, align 4, !dbg !0 7@a = common local_unnamed_addr global ptr null, align 8, !dbg !6 8 9; Test that loop remainder unrolling doesn't corrupt debuginfo. This example 10; used to cause an assert, but also test that the unrolled backwards branches 11; have the same DILocation. 12 13define i32 @func_c() local_unnamed_addr #0 !dbg !14 { 14; 15; CHECK-LABEL: @func_c( 16; CHECK-NEXT: entry: 17; CHECK-NEXT: [[DOTPR:%.*]] = load i32, ptr @b, align 4, !dbg [[DBG17:![0-9]+]], !tbaa [[TBAA20:![0-9]+]] 18; CHECK-NEXT: [[TOBOOL1:%.*]] = icmp eq i32 [[DOTPR]], 0, !dbg [[DBG24:![0-9]+]] 19; CHECK-NEXT: br i1 [[TOBOOL1]], label [[FOR_END:%.*]], label [[FOR_BODY_LR_PH:%.*]], !dbg [[DBG24]] 20; CHECK: for.body.lr.ph: 21; CHECK-NEXT: [[A_PROMOTED:%.*]] = load ptr, ptr @a, align 8, !dbg [[DBG25:![0-9]+]], !tbaa [[TBAA26:![0-9]+]] 22; CHECK-NEXT: [[TMP0:%.*]] = sub i32 -2, [[DOTPR]], !dbg [[DBG24]] 23; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[TMP0]], -2, !dbg [[DBG24]] 24; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[DOTPR]], [[TMP1]], !dbg [[DBG24]] 25; CHECK-NEXT: [[TMP3:%.*]] = lshr i32 [[TMP0]], 1, !dbg [[DBG24]] 26; CHECK-NEXT: [[TMP4:%.*]] = add nuw i32 [[TMP3]], 1, !dbg [[DBG24]] 27; CHECK-NEXT: [[XTRAITER:%.*]] = and i32 [[TMP4]], 3, !dbg [[DBG24]] 28; CHECK-NEXT: [[LCMP_MOD:%.*]] = icmp ne i32 [[XTRAITER]], 0, !dbg [[DBG24]] 29; CHECK-NEXT: br i1 [[LCMP_MOD]], label [[FOR_BODY_PROL_PREHEADER:%.*]], label [[FOR_BODY_PROL_LOOPEXIT:%.*]], !dbg [[DBG24]] 30; CHECK: for.body.prol.preheader: 31; CHECK-NEXT: br label [[FOR_BODY_PROL:%.*]], !dbg [[DBG24]] 32; CHECK: for.body.prol: 33; CHECK-NEXT: [[ARRAYIDX_PROL:%.*]] = getelementptr inbounds i32, ptr [[A_PROMOTED]], i64 1, !dbg [[DBG28:![0-9]+]] 34; CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[ARRAYIDX_PROL]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]] 35; CHECK-NEXT: [[CONV_PROL:%.*]] = sext i32 [[TMP5]] to i64, !dbg [[DBG28]] 36; CHECK-NEXT: [[TMP6:%.*]] = inttoptr i64 [[CONV_PROL]] to ptr, !dbg [[DBG28]] 37; CHECK-NEXT: [[ADD_PROL:%.*]] = add nsw i32 [[DOTPR]], 2, !dbg [[DBG29:![0-9]+]] 38; CHECK-NEXT: [[PROL_ITER_CMP:%.*]] = icmp ne i32 1, [[XTRAITER]], !dbg [[DBG24]] 39; CHECK-NEXT: br i1 [[PROL_ITER_CMP]], label [[FOR_BODY_PROL_1:%.*]], label [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA:%.*]], !dbg [[DBG24]] 40; CHECK: for.body.prol.1: 41; CHECK-NEXT: [[ARRAYIDX_PROL_1:%.*]] = getelementptr inbounds i32, ptr [[TMP6]], i64 1, !dbg [[DBG28]] 42; CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr [[ARRAYIDX_PROL_1]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]] 43; CHECK-NEXT: [[CONV_PROL_1:%.*]] = sext i32 [[TMP7]] to i64, !dbg [[DBG28]] 44; CHECK-NEXT: [[TMP8:%.*]] = inttoptr i64 [[CONV_PROL_1]] to ptr, !dbg [[DBG28]] 45; CHECK-NEXT: [[ADD_PROL_1:%.*]] = add nsw i32 [[DOTPR]], 4, !dbg [[DBG29]] 46; CHECK-NEXT: [[PROL_ITER_CMP_1:%.*]] = icmp ne i32 2, [[XTRAITER]], !dbg [[DBG24]] 47; CHECK-NEXT: br i1 [[PROL_ITER_CMP_1]], label [[FOR_BODY_PROL_2:%.*]], label [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]], !dbg [[DBG24]] 48; CHECK: for.body.prol.2: 49; CHECK-NEXT: [[ARRAYIDX_PROL_2:%.*]] = getelementptr inbounds i32, ptr [[TMP8]], i64 1, !dbg [[DBG28]] 50; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[ARRAYIDX_PROL_2]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]] 51; CHECK-NEXT: [[CONV_PROL_2:%.*]] = sext i32 [[TMP9]] to i64, !dbg [[DBG28]] 52; CHECK-NEXT: [[TMP10:%.*]] = inttoptr i64 [[CONV_PROL_2]] to ptr, !dbg [[DBG28]] 53; CHECK-NEXT: [[ADD_PROL_2:%.*]] = add nsw i32 [[DOTPR]], 6, !dbg [[DBG29]] 54; CHECK-NEXT: br label [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]] 55; CHECK: for.body.prol.loopexit.unr-lcssa: 56; CHECK-NEXT: [[DOTLCSSA_UNR_PH:%.*]] = phi ptr [ [[TMP6]], [[FOR_BODY_PROL]] ], [ [[TMP8]], [[FOR_BODY_PROL_1]] ], [ [[TMP10]], [[FOR_BODY_PROL_2]] ] 57; CHECK-NEXT: [[DOTUNR_PH:%.*]] = phi ptr [ [[TMP6]], [[FOR_BODY_PROL]] ], [ [[TMP8]], [[FOR_BODY_PROL_1]] ], [ [[TMP10]], [[FOR_BODY_PROL_2]] ] 58; CHECK-NEXT: [[DOTUNR1_PH:%.*]] = phi i32 [ [[ADD_PROL]], [[FOR_BODY_PROL]] ], [ [[ADD_PROL_1]], [[FOR_BODY_PROL_1]] ], [ [[ADD_PROL_2]], [[FOR_BODY_PROL_2]] ] 59; CHECK-NEXT: br label [[FOR_BODY_PROL_LOOPEXIT]], !dbg [[DBG24]] 60; CHECK: for.body.prol.loopexit: 61; CHECK-NEXT: [[DOTLCSSA_UNR:%.*]] = phi ptr [ poison, [[FOR_BODY_LR_PH]] ], [ [[DOTLCSSA_UNR_PH]], [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]] ] 62; CHECK-NEXT: [[DOTUNR:%.*]] = phi ptr [ [[A_PROMOTED]], [[FOR_BODY_LR_PH]] ], [ [[DOTUNR_PH]], [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]] ] 63; CHECK-NEXT: [[DOTUNR1:%.*]] = phi i32 [ [[DOTPR]], [[FOR_BODY_LR_PH]] ], [ [[DOTUNR1_PH]], [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]] ] 64; CHECK-NEXT: [[TMP11:%.*]] = icmp ult i32 [[TMP3]], 3, !dbg [[DBG24]] 65; CHECK-NEXT: br i1 [[TMP11]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]], label [[FOR_BODY_LR_PH_NEW:%.*]], !dbg [[DBG24]] 66; CHECK: for.body.lr.ph.new: 67; CHECK-NEXT: br label [[FOR_BODY:%.*]], !dbg [[DBG24]] 68; CHECK: for.body: 69; CHECK-NEXT: [[TMP12:%.*]] = phi ptr [ [[DOTUNR]], [[FOR_BODY_LR_PH_NEW]] ], [ [[TMP21:%.*]], [[FOR_BODY]] ], !dbg [[DBG28]] 70; CHECK-NEXT: [[TMP13:%.*]] = phi i32 [ [[DOTUNR1]], [[FOR_BODY_LR_PH_NEW]] ], [ [[ADD_3:%.*]], [[FOR_BODY]] ] 71; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP12]], i64 1, !dbg [[DBG28]] 72; CHECK-NEXT: [[TMP14:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]] 73; CHECK-NEXT: [[CONV:%.*]] = sext i32 [[TMP14]] to i64, !dbg [[DBG28]] 74; CHECK-NEXT: [[TMP15:%.*]] = inttoptr i64 [[CONV]] to ptr, !dbg [[DBG28]] 75; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds i32, ptr [[TMP15]], i64 1, !dbg [[DBG28]] 76; CHECK-NEXT: [[TMP16:%.*]] = load i32, ptr [[ARRAYIDX_1]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]] 77; CHECK-NEXT: [[CONV_1:%.*]] = sext i32 [[TMP16]] to i64, !dbg [[DBG28]] 78; CHECK-NEXT: [[TMP17:%.*]] = inttoptr i64 [[CONV_1]] to ptr, !dbg [[DBG28]] 79; CHECK-NEXT: [[ARRAYIDX_2:%.*]] = getelementptr inbounds i32, ptr [[TMP17]], i64 1, !dbg [[DBG28]] 80; CHECK-NEXT: [[TMP18:%.*]] = load i32, ptr [[ARRAYIDX_2]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]] 81; CHECK-NEXT: [[CONV_2:%.*]] = sext i32 [[TMP18]] to i64, !dbg [[DBG28]] 82; CHECK-NEXT: [[TMP19:%.*]] = inttoptr i64 [[CONV_2]] to ptr, !dbg [[DBG28]] 83; CHECK-NEXT: [[ARRAYIDX_3:%.*]] = getelementptr inbounds i32, ptr [[TMP19]], i64 1, !dbg [[DBG28]] 84; CHECK-NEXT: [[TMP20:%.*]] = load i32, ptr [[ARRAYIDX_3]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]] 85; CHECK-NEXT: [[CONV_3:%.*]] = sext i32 [[TMP20]] to i64, !dbg [[DBG28]] 86; CHECK-NEXT: [[TMP21]] = inttoptr i64 [[CONV_3]] to ptr, !dbg [[DBG28]] 87; CHECK-NEXT: [[ADD_3]] = add nsw i32 [[TMP13]], 8, !dbg [[DBG29]] 88; CHECK-NEXT: [[TOBOOL_3:%.*]] = icmp eq i32 [[ADD_3]], 0, !dbg [[DBG24]] 89; CHECK-NEXT: br i1 [[TOBOOL_3]], label [[FOR_COND_FOR_END_CRIT_EDGE_UNR_LCSSA:%.*]], label [[FOR_BODY]], !dbg [[DBG24]], !llvm.loop [[LOOP30:![0-9]+]] 90; CHECK: for.cond.for.end_crit_edge.unr-lcssa: 91; CHECK-NEXT: [[DOTLCSSA_PH:%.*]] = phi ptr [ [[TMP21]], [[FOR_BODY]] ] 92; CHECK-NEXT: br label [[FOR_COND_FOR_END_CRIT_EDGE]], !dbg [[DBG24]] 93; CHECK: for.cond.for.end_crit_edge: 94; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi ptr [ [[DOTLCSSA_UNR]], [[FOR_BODY_PROL_LOOPEXIT]] ], [ [[DOTLCSSA_PH]], [[FOR_COND_FOR_END_CRIT_EDGE_UNR_LCSSA]] ], !dbg [[DBG28]] 95; CHECK-NEXT: [[TMP22:%.*]] = add i32 [[TMP2]], 2, !dbg [[DBG24]] 96; CHECK-NEXT: store ptr [[DOTLCSSA]], ptr @a, align 8, !dbg [[DBG25]], !tbaa [[TBAA26]] 97; CHECK-NEXT: store i32 [[TMP22]], ptr @b, align 4, !dbg [[DBG33:![0-9]+]], !tbaa [[TBAA20]] 98; CHECK-NEXT: br label [[FOR_END]], !dbg [[DBG24]] 99; CHECK: for.end: 100; CHECK-NEXT: ret i32 undef, !dbg [[DBG34:![0-9]+]] 101; 102entry: 103 %.pr = load i32, ptr @b, align 4, !dbg !17, !tbaa !20 104 %tobool1 = icmp eq i32 %.pr, 0, !dbg !24 105 br i1 %tobool1, label %for.end, label %for.body.lr.ph, !dbg !24 106 107for.body.lr.ph: 108 %a.promoted = load ptr, ptr @a, align 8, !dbg !25, !tbaa !26 109 %0 = sub i32 -2, %.pr, !dbg !24 110 %1 = and i32 %0, -2, !dbg !24 111 %2 = add i32 %.pr, %1, !dbg !24 112 br label %for.body, !dbg !24 113 114for.body: 115 %3 = phi ptr [ %a.promoted, %for.body.lr.ph ], [ %6, %for.body ], !dbg !28 116 %4 = phi i32 [ %.pr, %for.body.lr.ph ], [ %add, %for.body ] 117 %arrayidx = getelementptr inbounds i32, ptr %3, i64 1, !dbg !28 118 %5 = load i32, ptr %arrayidx, align 4, !dbg !28, !tbaa !20 119 %conv = sext i32 %5 to i64, !dbg !28 120 %6 = inttoptr i64 %conv to ptr, !dbg !28 121 %add = add nsw i32 %4, 2, !dbg !29 122 %tobool = icmp eq i32 %add, 0, !dbg !24 123 br i1 %tobool, label %for.cond.for.end_crit_edge, label %for.body, !dbg !24, !llvm.loop !30 124 125for.cond.for.end_crit_edge: 126 %7 = add i32 %2, 2, !dbg !24 127 store ptr %6, ptr @a, align 8, !dbg !25, !tbaa !26 128 store i32 %7, ptr @b, align 4, !dbg !32, !tbaa !20 129 br label %for.end, !dbg !24 130 131for.end: 132 ret i32 undef, !dbg !33 133} 134 135define void @func_d() local_unnamed_addr #1 !dbg !34 { 136; 137; CHECK-LABEL: @func_d( 138; CHECK-NEXT: entry: 139; CHECK-NEXT: ret void, !dbg [[DBG38:![0-9]+]] 140; 141entry: 142 ret void, !dbg !37 143} 144 145attributes #0 = { norecurse nounwind uwtable } 146attributes #0 = { norecurse nounwind readnone uwtable } 147 148!llvm.dbg.cu = !{!2} 149!llvm.module.flags = !{!10, !11, !12} 150!llvm.ident = !{!13} 151 152!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 153!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true) 154!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) 155!3 = !DIFile(filename: "loop.c", directory: "/work/projects/src/tests/unroll-debug-info") 156!4 = !{} 157!5 = !{!6, !0} 158!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 159!7 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) 160!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64) 161!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 162!10 = !{i32 2, !"Dwarf Version", i32 4} 163!11 = !{i32 2, !"Debug Info Version", i32 3} 164!12 = !{i32 1, !"wchar_size", i32 4} 165!13 = !{!"clang version 6.0.0"} 166!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) 167!15 = !DISubroutineType(types: !16) 168!16 = !{!9} 169!17 = !DILocation(line: 4, column: 12, scope: !18) 170!18 = distinct !DILexicalBlock(scope: !19, file: !3, line: 4, column: 5) 171!19 = distinct !DILexicalBlock(scope: !14, file: !3, line: 4, column: 5) 172!20 = !{!21, !21, i64 0} 173!21 = !{!"int", !22, i64 0} 174!22 = !{!"omnipotent char", !23, i64 0} 175!23 = !{!"Simple C/C++ TBAA"} 176!24 = !DILocation(line: 4, column: 5, scope: !19) 177!25 = !DILocation(line: 5, column: 13, scope: !18) 178!26 = !{!27, !27, i64 0} 179!27 = !{!"any pointer", !22, i64 0} 180!28 = !DILocation(line: 5, column: 15, scope: !18) 181!29 = !DILocation(line: 4, column: 21, scope: !18) 182!30 = distinct !{!30, !24, !31} 183!31 = !DILocation(line: 5, column: 18, scope: !19) 184!32 = !DILocation(line: 4, column: 17, scope: !18) 185!33 = !DILocation(line: 6, column: 1, scope: !14) 186!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) 187!35 = !DISubroutineType(types: !36) 188!36 = !{null} 189!37 = !DILocation(line: 7, column: 11, scope: !34) 190