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,109 @@ +; 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 !dbg !7 { +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, !dbg !23 + store i32 10, i32* %i1, align 4, !dbg !24, !tbaa !25 + %i2 = getelementptr inbounds %struct.moo, %struct.moo* %moo_p, i32 0, i32 2, !dbg !30 + %0 = load i32, i32* %i2, align 4, !dbg !30, !tbaa !25 + ret i32 %0, !dbg !31 +} + +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*, !dbg !38 + call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #3, !dbg !38 + call void @llvm.dbg.declare(metadata i32* %blah, metadata !36, metadata !20), !dbg !39 + store i32 10, i32* %blah, align 4, !dbg !39, !tbaa !40 + %1 = bitcast %struct.moo* %mymoo to i8*, !dbg !41 + call void @llvm.lifetime.start.p0i8(i64 12, i8* %1) #3, !dbg !41 + call void @llvm.dbg.declare(metadata %struct.moo* %mymoo, metadata !37, metadata !20), !dbg !42 + %2 = bitcast %struct.moo* %mymoo to i8*, !dbg !42 + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* bitcast (%struct.moo* @foo.mymoo to i8*), i64 12, i32 4, i1 false), !dbg !42 + %3 = load i32, i32* %blah, align 4, !dbg !43, !tbaa !40 + %call = call i32 @bar(%struct.moo* %mymoo, i32 %3), !dbg !44 + %4 = bitcast %struct.moo* %mymoo to i8*, !dbg !45 + call void @llvm.lifetime.end.p0i8(i64 12, i8* %4) #3, !dbg !45 + %5 = bitcast i32* %blah to i8*, !dbg !45 + call void @llvm.lifetime.end.p0i8(i64 4, i8* %5) #3, !dbg !45 + ret i32 %call, !dbg !46 +} + +declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #2 +declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #2 +declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #2 +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 + +attributes #0 = { nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } +attributes #2 = { argmemonly nounwind } +attributes #3 = { nounwind } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.0 (trunk 300347) (llvm/trunk 300367)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "a.c", directory: "/tmp") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"PIC Level", i32 2} +!6 = !{!"clang version 5.0.0 (trunk 300347) (llvm/trunk 300367)"} +!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) +!23 = !DILocation(line: 6, column: 10, scope: !7) +!24 = !DILocation(line: 6, column: 12, 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"} +!30 = !DILocation(line: 7, column: 17, scope: !7) +!31 = !DILocation(line: 7, column: 3, scope: !7) +!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) +!38 = !DILocation(line: 11, column: 3, scope: !32) +!39 = !DILocation(line: 11, column: 7, scope: !32) +!40 = !{!27, !27, i64 0} +!41 = !DILocation(line: 12, column: 3, scope: !32) +!42 = !DILocation(line: 12, column: 14, scope: !32) +!43 = !DILocation(line: 13, column: 22, scope: !32) +!44 = !DILocation(line: 13, column: 10, scope: !32) +!45 = !DILocation(line: 14, column: 1, scope: !32) +!46 = !DILocation(line: 13, column: 3, scope: !32)