|
| 1 | +; RUN: opt -S %s -passes=simplifycfg -o - -experimental-assignment-tracking \ |
| 2 | +; RUN: | FileCheck %s |
| 3 | + |
| 4 | +;; $ cat test.cpp |
| 5 | +;; class a {}; |
| 6 | +;; void operator*(a, float &); |
| 7 | +;; class b { |
| 8 | +;; public: |
| 9 | +;; a c; |
| 10 | +;; }; |
| 11 | +;; int d; |
| 12 | +;; class e { |
| 13 | +;; b g[3]; |
| 14 | +;; float f; |
| 15 | +;; void i(); |
| 16 | +;; }; |
| 17 | +;; void e::i() { |
| 18 | +;; float h; |
| 19 | +;; g[d].c *h; |
| 20 | +;; if (h) |
| 21 | +;; h = f; |
| 22 | +;; else |
| 23 | +;; h = f; |
| 24 | +;; } |
| 25 | +;; Generated by grabbing IR before simplifycfg in: |
| 26 | +;; $ clang++ -O2 -g -c test.cpp -Xclang -fexperimental-assignment-tracking |
| 27 | + |
| 28 | +;; if.then and if.else each only have a dbg.assign and br instruction. |
| 29 | +;; SimplifyCFG will remove these blocks. Check that the dbg.assign intrinsics |
| 30 | +;; are sunk into the succ beforehand. |
| 31 | + |
| 32 | +; CHECK: entry: |
| 33 | +;; -- alloca dbg.assign |
| 34 | +; CHECK: call void @llvm.dbg.assign(metadata i1 undef |
| 35 | +;; -- sunk dbg.assigns |
| 36 | +; CHECK: call void @llvm.dbg.assign(metadata float undef, metadata ![[var:[0-9]+]], metadata !DIExpression(), metadata ![[id:[0-9]+]], metadata ptr %h, metadata !DIExpression()), !dbg |
| 37 | +; CHECK-NEXT: call void @llvm.dbg.assign(metadata float undef, metadata ![[var]], metadata !DIExpression(), metadata ![[id]], metadata ptr %h, metadata !DIExpression()), !dbg |
| 38 | +; CHECK-NEXT: %storemerge.in = getelementptr |
| 39 | +; CHECK-NEXT: %storemerge = load float |
| 40 | +; CHECK-NEXT: store float %storemerge, ptr %h, align 4{{.+}}!DIAssignID ![[id]] |
| 41 | +; CHECK: ret void |
| 42 | + |
| 43 | +%class.e = type { [3 x %class.b], float } |
| 44 | +%class.b = type { %class.a } |
| 45 | +%class.a = type { i8 } |
| 46 | + |
| 47 | +@d = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0 |
| 48 | + |
| 49 | +; Function Attrs: uwtable |
| 50 | +define dso_local void @_ZN1e1iEv(ptr %this) local_unnamed_addr #0 align 2 !dbg !11 { |
| 51 | +entry: |
| 52 | + %h = alloca float, align 4, !DIAssignID !32 |
| 53 | + call void @llvm.dbg.assign(metadata i1 undef, metadata !31, metadata !DIExpression(), metadata !32, metadata ptr %h, metadata !DIExpression()), !dbg !33 |
| 54 | + %0 = bitcast ptr %h to ptr, !dbg !34 |
| 55 | + call void @llvm.lifetime.start.p0i8(i64 4, ptr nonnull %0) #4, !dbg !34 |
| 56 | + call void @_Zml1aRf(ptr nonnull align 4 dereferenceable(4) %h), !dbg !35 |
| 57 | + %1 = load float, ptr %h, align 4, !dbg !36 |
| 58 | + %tobool = fcmp une float %1, 0.000000e+00, !dbg !36 |
| 59 | + br i1 %tobool, label %if.then, label %if.else, !dbg !42 |
| 60 | + |
| 61 | +if.then: ; preds = %entry |
| 62 | + call void @llvm.dbg.assign(metadata float undef, metadata !31, metadata !DIExpression(), metadata !43, metadata ptr %h, metadata !DIExpression()), !dbg !33 |
| 63 | + br label %if.end, !dbg !44 |
| 64 | + |
| 65 | +if.else: ; preds = %entry |
| 66 | + call void @llvm.dbg.assign(metadata float undef, metadata !31, metadata !DIExpression(), metadata !43, metadata ptr %h, metadata !DIExpression()), !dbg !33 |
| 67 | + br label %if.end |
| 68 | + |
| 69 | +if.end: ; preds = %if.else, %if.then |
| 70 | + %storemerge.in = getelementptr inbounds %class.e, ptr %this, i64 0, i32 1, !dbg !45 |
| 71 | + %storemerge = load float, ptr %storemerge.in, align 4, !dbg !45 |
| 72 | + store float %storemerge, ptr %h, align 4, !dbg !45, !DIAssignID !43 |
| 73 | + call void @llvm.lifetime.end.p0i8(i64 4, ptr nonnull %0) #4, !dbg !48 |
| 74 | + ret void, !dbg !48 |
| 75 | +} |
| 76 | + |
| 77 | +declare void @llvm.lifetime.start.p0i8(i64 immarg, ptr nocapture) #1 |
| 78 | +declare !dbg !49 dso_local void @_Zml1aRf(ptr nonnull align 4 dereferenceable(4)) local_unnamed_addr #2 |
| 79 | +declare void @llvm.lifetime.end.p0i8(i64 immarg, ptr nocapture) #1 |
| 80 | +declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #3 |
| 81 | + |
| 82 | +!llvm.dbg.cu = !{!2} |
| 83 | +!llvm.module.flags = !{!7, !8, !9} |
| 84 | +!llvm.ident = !{!10} |
| 85 | + |
| 86 | +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) |
| 87 | +!1 = distinct !DIGlobalVariable(name: "d", scope: !2, file: !3, line: 7, type: !6, isLocal: false, isDefinition: true) |
| 88 | +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) |
| 89 | +!3 = !DIFile(filename: "test.cpp", directory: "/") |
| 90 | +!4 = !{} |
| 91 | +!5 = !{!0} |
| 92 | +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 93 | +!7 = !{i32 7, !"Dwarf Version", i32 4} |
| 94 | +!8 = !{i32 2, !"Debug Info Version", i32 3} |
| 95 | +!9 = !{i32 1, !"wchar_size", i32 4} |
| 96 | +!10 = !{!"clang version 12.0.0"} |
| 97 | +!11 = distinct !DISubprogram(name: "i", linkageName: "_ZN1e1iEv", scope: !12, file: !3, line: 13, type: !25, scopeLine: 13, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, declaration: !24, retainedNodes: !28) |
| 98 | +!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "e", file: !3, line: 8, size: 64, flags: DIFlagTypePassByValue, elements: !13, identifier: "_ZTS1e") |
| 99 | +!13 = !{!14, !22, !24} |
| 100 | +!14 = !DIDerivedType(tag: DW_TAG_member, name: "g", scope: !12, file: !3, line: 9, baseType: !15, size: 24) |
| 101 | +!15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !16, size: 24, elements: !20) |
| 102 | +!16 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "b", file: !3, line: 3, size: 8, flags: DIFlagTypePassByValue, elements: !17, identifier: "_ZTS1b") |
| 103 | +!17 = !{!18} |
| 104 | +!18 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !16, file: !3, line: 5, baseType: !19, size: 8, flags: DIFlagPublic) |
| 105 | +!19 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "a", file: !3, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !4, identifier: "_ZTS1a") |
| 106 | +!20 = !{!21} |
| 107 | +!21 = !DISubrange(count: 3) |
| 108 | +!22 = !DIDerivedType(tag: DW_TAG_member, name: "f", scope: !12, file: !3, line: 10, baseType: !23, size: 32, offset: 32) |
| 109 | +!23 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) |
| 110 | +!24 = !DISubprogram(name: "i", linkageName: "_ZN1e1iEv", scope: !12, file: !3, line: 11, type: !25, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) |
| 111 | +!25 = !DISubroutineType(types: !26) |
| 112 | +!26 = !{null, !27} |
| 113 | +!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) |
| 114 | +!28 = !{!29, !31} |
| 115 | +!29 = !DILocalVariable(name: "this", arg: 1, scope: !11, type: !30, flags: DIFlagArtificial | DIFlagObjectPointer) |
| 116 | +!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64) |
| 117 | +!31 = !DILocalVariable(name: "h", scope: !11, file: !3, line: 14, type: !23) |
| 118 | +!32 = distinct !DIAssignID() |
| 119 | +!33 = !DILocation(line: 0, scope: !11) |
| 120 | +!34 = !DILocation(line: 14, column: 3, scope: !11) |
| 121 | +!35 = !DILocation(line: 15, column: 10, scope: !11) |
| 122 | +!36 = !DILocation(line: 16, column: 7, scope: !37) |
| 123 | +!37 = distinct !DILexicalBlock(scope: !11, file: !3, line: 16, column: 7) |
| 124 | +!42 = !DILocation(line: 16, column: 7, scope: !11) |
| 125 | +!43 = distinct !DIAssignID() |
| 126 | +!44 = !DILocation(line: 17, column: 5, scope: !37) |
| 127 | +!45 = !DILocation(line: 0, scope: !37) |
| 128 | +!48 = !DILocation(line: 20, column: 1, scope: !11) |
| 129 | +!49 = !DISubprogram(name: "operator*", linkageName: "_Zml1aRf", scope: !3, file: !3, line: 2, type: !50, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4) |
| 130 | +!50 = !DISubroutineType(types: !51) |
| 131 | +!51 = !{null, !19, !52} |
| 132 | +!52 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !23, size: 64) |
0 commit comments