Index: lib/Transforms/InstCombine/InstructionCombining.cpp =================================================================== --- lib/Transforms/InstCombine/InstructionCombining.cpp +++ lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3052,7 +3052,10 @@ } } - InstrsForInstCombineWorklist.push_back(Inst); + // Skip processing debug intrinsics in InstCombine. Processing these call instructions + // consumes non-trivial amount of time and provides no value for the optimization. + if (!isa(Inst)) + InstrsForInstCombineWorklist.push_back(Inst); } // Recursively visit successors. If this is a branch or switch on a Index: test/Transforms/InstCombine/debuginfo-skip.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/debuginfo-skip.ll @@ -0,0 +1,85 @@ +; RUN: opt < %s -instcombine -debug -S -o %t 2>&1 | FileCheck %s +; RUN: cat %t | FileCheck %s --check-prefix=CHECK-IR + +; Debug output from InstCombine should not have any @llvm.dbg.* instructions visited +; CHECK-NOT: call void @llvm.dbg. + +; The resulting IR should still have them +; CHECK-IR: call void @llvm.dbg. + +%struct.moo = type { i32, i32, i32 } + +@foo.mymoo = private unnamed_addr constant %struct.moo { i32 1, i32 2, i32 3 }, align 4 + +define i32 @bar(%struct.moo* %moo_p, i32 %i) #0 { +entry: + call void @llvm.dbg.value(metadata %struct.moo* %moo_p, i64 0, metadata !18, metadata !20), !dbg !21 + call void @llvm.dbg.value(metadata i32 %i, i64 0, metadata !19, metadata !20), !dbg !22 + %i1 = getelementptr inbounds %struct.moo, %struct.moo* %moo_p, i32 0, i32 2 + store i32 10, i32* %i1, align 4 + %i2 = getelementptr inbounds %struct.moo, %struct.moo* %moo_p, i32 0, i32 2 + %0 = load i32, i32* %i2, align 4 + ret i32 %0 +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +define i32 @foo() #0 !dbg !32 { +entry: + %blah = alloca i32, align 4 + %mymoo = alloca %struct.moo, align 4 + %0 = bitcast i32* %blah to i8* + call void @llvm.dbg.declare(metadata i32* %blah, metadata !36, metadata !20), !dbg !39 + store i32 10, i32* %blah, align 4 + %1 = bitcast %struct.moo* %mymoo to i8* + call void @llvm.dbg.declare(metadata %struct.moo* %mymoo, metadata !37, metadata !20), !dbg !42 + %2 = bitcast %struct.moo* %mymoo to i8* + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* bitcast (%struct.moo* @foo.mymoo to i8*), i64 12, i32 4, i1 false) + %3 = load i32, i32* %blah, align 4 + %call = call i32 @bar(%struct.moo* %mymoo, i32 %3), !dbg !44 + %4 = bitcast %struct.moo* %mymoo to i8* + %5 = bitcast i32* %blah to i8* + ret i32 %call +} + +declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #2 +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang 5.0.0)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug) +!1 = !DIFile(filename: "a.c", directory: "/tmp") +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"PIC Level", i32 2} +!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !17) +!8 = !DISubroutineType(types: !9) +!9 = !{!10, !11, !10} +!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64) +!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "moo", file: !1, line: 1, size: 96, elements: !13) +!13 = !{!14, !15, !16} +!14 = !DIDerivedType(tag: DW_TAG_member, name: "j", scope: !12, file: !1, line: 2, baseType: !10, size: 32) +!15 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !12, file: !1, line: 2, baseType: !10, size: 32, offset: 32) +!16 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !12, file: !1, line: 2, baseType: !10, size: 32, offset: 64) +!17 = !{!18, !19} +!18 = !DILocalVariable(name: "moo_p", arg: 1, scope: !7, file: !1, line: 5, type: !11) +!19 = !DILocalVariable(name: "i", arg: 2, scope: !7, file: !1, line: 5, type: !10) +!20 = !DIExpression() +!21 = !DILocation(line: 5, column: 21, scope: !7) +!22 = !DILocation(line: 5, column: 32, scope: !7) +!25 = !{!26, !27, i64 8} +!26 = !{!"moo", !27, i64 0, !27, i64 4, !27, i64 8} +!27 = !{!"int", !28, i64 0} +!28 = !{!"omnipotent char", !29, i64 0} +!29 = !{!"Simple C/C++ TBAA"} +!32 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 10, type: !33, isLocal: false, isDefinition: true, scopeLine: 10, isOptimized: true, unit: !0, variables: !35) +!33 = !DISubroutineType(types: !34) +!34 = !{!10} +!35 = !{!36, !37} +!36 = !DILocalVariable(name: "blah", scope: !32, file: !1, line: 11, type: !10) +!37 = !DILocalVariable(name: "mymoo", scope: !32, file: !1, line: 12, type: !12) +!39 = !DILocation(line: 11, column: 7, scope: !32) +!42 = !DILocation(line: 12, column: 14, scope: !32) +!44 = !DILocation(line: 13, column: 10, scope: !32)