182 lines · plain
1; RUN: opt %s -S -passes=licm -o - | FileCheck %s2 3;; $ cat test.c4;; int b, c, d;5;; void e();6;; void f(int *g) { *g = b; }7;; void i() {8;; int h, a;9;; for (;;) {10;; e();11;; a = 1;12;; if (h) {13;; if (d)14;; continue;15;; h = c;16;; }17;; f(&a);18;; }19;; }20;; Generated by getting the IR before LICM in:21;; $ clang -c -O2 -g test.c -fno-unroll-loops -fno-vectorize -fno-inline -Xclang -fexperimental-assignment-tracking -o -22 23;; entry24;; |25;; v26;; *---->for.cond.outer27;; | |28;; | v29;; | +->for.cond-----+30;; | | | |31;; | | v |32;; | +--if.then |33;; | | |34;; | v v35;; | if.end if.end3.loopexit36;; | | |37;; | v |38;; +-----if.end3 <----+39;;40;; The store in for.cond is sunk into the inner-loop exits if.end and if.end3.loopexit.41;;42;; Check that a store sunk into multiple exits retains its (their) dbg.assign,43;; and that the new stores share the same DIAssignID.44 45; CHECK-LABEL: for.cond:46; CHECK: #dbg_assign(i32 1, ![[var:[0-9]+]], !DIExpression(), ![[id:[0-9]+]], ptr %a, !DIExpression(),47 48; CHECK-LABEL: if.end:49; CHECK-NEXT: store i32 1, ptr %a, align 1,{{.*}}!DIAssignID ![[id]]50 51; CHECK-LABEL: if.end3.loopexit:52; CHECK-NEXT: store i32 1, ptr %a, align 1,{{.*}}!DIAssignID ![[id]]53 54; CHECK-DAG: ![[var]] = !DILocalVariable(name: "a",55 56@b = dso_local local_unnamed_addr global i32 0, align 4, !dbg !057@d = dso_local local_unnamed_addr global i32 0, align 4, !dbg !958@c = dso_local local_unnamed_addr global i32 0, align 4, !dbg !659 60define dso_local void @f(ptr nocapture %g) local_unnamed_addr #0 !dbg !15 {61entry:62 call void @llvm.dbg.assign(metadata i1 undef, metadata !20, metadata !DIExpression(), metadata !21, metadata ptr undef, metadata !DIExpression()), !dbg !2263 call void @llvm.dbg.assign(metadata ptr %g, metadata !20, metadata !DIExpression(), metadata !23, metadata ptr undef, metadata !DIExpression()), !dbg !2264 %0 = load i32, ptr @b, align 4, !dbg !2465 store i32 %0, ptr %g, align 4, !dbg !2966 ret void, !dbg !3067}68 69define dso_local void @i() local_unnamed_addr #2 !dbg !31 {70entry:71 call void @llvm.dbg.assign(metadata i1 undef, metadata !35, metadata !DIExpression(), metadata !37, metadata ptr undef, metadata !DIExpression()), !dbg !3872 %a = alloca i32, align 4, !DIAssignID !3973 call void @llvm.dbg.assign(metadata i1 undef, metadata !36, metadata !DIExpression(), metadata !39, metadata ptr %a, metadata !DIExpression()), !dbg !3874 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %a) #5, !dbg !4075 br label %for.cond.outer, !dbg !4176 77for.cond.outer: ; preds = %if.end3, %entry78 %h.0.ph = phi i32 [ %h.1, %if.end3 ], [ undef, %entry ]79 br label %for.cond, !dbg !4280 81for.cond: ; preds = %for.cond.outer, %if.then82 call void @llvm.dbg.value(metadata i32 %h.0.ph, metadata !35, metadata !DIExpression()), !dbg !3883 tail call void (...) @e() #5, !dbg !4484 store i32 1, ptr %a, align 4, !dbg !47, !DIAssignID !4885 call void @llvm.dbg.assign(metadata i32 1, metadata !36, metadata !DIExpression(), metadata !48, metadata ptr %a, metadata !DIExpression()), !dbg !3886 %tobool.not = icmp eq i32 %h.0.ph, 0, !dbg !4987 br i1 %tobool.not, label %if.end3.loopexit, label %if.then, !dbg !5188 89if.then: ; preds = %for.cond90 %0 = load i32, ptr @d, align 4, !dbg !5291 %tobool1.not = icmp eq i32 %0, 0, !dbg !5292 br i1 %tobool1.not, label %if.end, label %for.cond, !dbg !55, !llvm.loop !5693 94if.end: ; preds = %if.then95 %1 = load i32, ptr @c, align 4, !dbg !5996 call void @llvm.dbg.assign(metadata i32 %1, metadata !35, metadata !DIExpression(), metadata !60, metadata ptr undef, metadata !DIExpression()), !dbg !3897 br label %if.end3, !dbg !6198 99if.end3.loopexit: ; preds = %for.cond100 br label %if.end3, !dbg !62101 102if.end3: ; preds = %if.end3.loopexit, %if.end103 %h.1 = phi i32 [ %1, %if.end ], [ 0, %if.end3.loopexit ]104 call void @llvm.dbg.value(metadata i32 %h.1, metadata !35, metadata !DIExpression()), !dbg !38105 call void @f(ptr nonnull %a), !dbg !62106 br label %for.cond.outer, !dbg !63, !llvm.loop !56107}108 109declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #1110declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3111declare !dbg !64 dso_local void @e(...) local_unnamed_addr #4112declare void @llvm.dbg.value(metadata, metadata, metadata) #1113 114!llvm.dbg.cu = !{!2}115!llvm.module.flags = !{!11, !12, !13, !1000}116!llvm.ident = !{!14}117 118!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())119!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)120!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)121!3 = !DIFile(filename: "test.c", directory: "/")122!4 = !{}123!5 = !{!0, !6, !9}124!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())125!7 = distinct !DIGlobalVariable(name: "c", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)126!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)127!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())128!10 = distinct !DIGlobalVariable(name: "d", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)129!11 = !{i32 7, !"Dwarf Version", i32 4}130!12 = !{i32 2, !"Debug Info Version", i32 3}131!13 = !{i32 1, !"wchar_size", i32 4}132!14 = !{!"clang version 12.0.0"}133!15 = distinct !DISubprogram(name: "f", scope: !3, file: !3, line: 3, type: !16, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19)134!16 = !DISubroutineType(types: !17)135!17 = !{null, !18}136!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)137!19 = !{!20}138!20 = !DILocalVariable(name: "g", arg: 1, scope: !15, file: !3, line: 3, type: !18)139!21 = distinct !DIAssignID()140!22 = !DILocation(line: 0, scope: !15)141!23 = distinct !DIAssignID()142!24 = !DILocation(line: 3, column: 23, scope: !15)143!29 = !DILocation(line: 3, column: 21, scope: !15)144!30 = !DILocation(line: 3, column: 26, scope: !15)145!31 = distinct !DISubprogram(name: "i", scope: !3, file: !3, line: 4, type: !32, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !34)146!32 = !DISubroutineType(types: !33)147!33 = !{null}148!34 = !{!35, !36}149!35 = !DILocalVariable(name: "h", scope: !31, file: !3, line: 5, type: !8)150!36 = !DILocalVariable(name: "a", scope: !31, file: !3, line: 5, type: !8)151!37 = distinct !DIAssignID()152!38 = !DILocation(line: 0, scope: !31)153!39 = distinct !DIAssignID()154!40 = !DILocation(line: 5, column: 3, scope: !31)155!41 = !DILocation(line: 6, column: 3, scope: !31)156!42 = !DILocation(line: 6, column: 3, scope: !43)157!43 = distinct !DILexicalBlock(scope: !31, file: !3, line: 6, column: 3)158!44 = !DILocation(line: 7, column: 5, scope: !45)159!45 = distinct !DILexicalBlock(scope: !46, file: !3, line: 6, column: 12)160!46 = distinct !DILexicalBlock(scope: !43, file: !3, line: 6, column: 3)161!47 = !DILocation(line: 8, column: 7, scope: !45)162!48 = distinct !DIAssignID()163!49 = !DILocation(line: 9, column: 9, scope: !50)164!50 = distinct !DILexicalBlock(scope: !45, file: !3, line: 9, column: 9)165!51 = !DILocation(line: 9, column: 9, scope: !45)166!52 = !DILocation(line: 10, column: 11, scope: !53)167!53 = distinct !DILexicalBlock(scope: !54, file: !3, line: 10, column: 11)168!54 = distinct !DILexicalBlock(scope: !50, file: !3, line: 9, column: 12)169!55 = !DILocation(line: 10, column: 11, scope: !54)170!56 = distinct !{!56, !42, !57, !58}171!57 = !DILocation(line: 15, column: 3, scope: !43)172!58 = !{!"llvm.loop.unroll.disable"}173!59 = !DILocation(line: 12, column: 11, scope: !54)174!60 = distinct !DIAssignID()175!61 = !DILocation(line: 13, column: 5, scope: !54)176!62 = !DILocation(line: 14, column: 5, scope: !45)177!63 = !DILocation(line: 6, column: 3, scope: !46)178!64 = !DISubprogram(name: "e", scope: !3, file: !3, line: 2, type: !65, spFlags: DISPFlagOptimized, retainedNodes: !4)179!65 = !DISubroutineType(types: !66)180!66 = !{null, null}181!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}182