(original) (raw)

>From 3b5cfc27468359a522b4ce9e99731cc0172a88d5 Mon Sep 17 00:00:00 2001 From: Karl-Johan Karlsson karl-johan.karlsson@ericsson.com Date: Mon, 9 Feb 2015 15:03:52 +0100 Subject: [PATCH] Added lowering of dbg.declare in JumpThreading. The jumpthreading algorithm might duplicate blocks, including dbg.declare instrinsics. Avoid ending up with two dbg.declare intrinsics for a single alloca, by using the same method as in InstructionCombining. Lower the dbg.declare intrinsics into an appropriate set of dbg.value instrinsics. --- lib/Transforms/Scalar/JumpThreading.cpp | 6 ++- test/Transforms/JumpThreading/dbg-declare.ll | 75 ++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 test/Transforms/JumpThreading/dbg-declare.ll diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 8b54abd..dc95e20 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -164,6 +164,10 @@ bool JumpThreading::runOnFunction(Function &F) { TLI = &getAnalysis().getTLI(); LVI = &getAnalysis(); + // Lower dbg.declare intrinsics otherwise they may be duplicated by the + // jumpthreading algorithm. + bool DbgDeclaresChanged = LowerDbgDeclare(F); + // Remove unreachable blocks from function as they may result in infinite // loop. We do threading if we found something profitable. Jump threading a // branch can create other opportunities. If these opportunities form a cycle @@ -234,7 +238,7 @@ bool JumpThreading::runOnFunction(Function &F) { } while (Changed); LoopHeaders.clear(); - return EverChanged; + return DbgDeclaresChanged || EverChanged; } /// getJumpThreadDuplicationCost - Return the cost of duplicating this block to diff --git a/test/Transforms/JumpThreading/dbg-declare.ll b/test/Transforms/JumpThreading/dbg-declare.ll new file mode 100644 index 0000000..709f13d --- /dev/null +++ b/test/Transforms/JumpThreading/dbg-declare.ll @@ -0,0 +1,75 @@ +; RUN: opt -jump-threading -S < %s | FileCheck %s + +; There should be no dbg.declare intrinsics left as they have been lowered. +; The reason is to avoid dbg.declare intrinsics being duplicated and end up +; with two identical dbg.declare intrinsics for a single alloca. + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @main() { + %1 = alloca i32 + %2 = alloca i16 + %3 = load i16* null, !dbg !12 + %4 = icmp eq i16 %3, 0, !dbg !12 + br i1 %4, label %bb1.i, label %bb2.i, !dbg !12 + +bb1.i: ; preds = %1 + br label %func1.exit, !dbg !16 + +bb2.i: ; preds = %1 + br label %func1.exit, !dbg !17 + +func1.exit: ; preds = %bb2.i, %bb1.i + %5 = phi i32 [ 0, %bb1.i ], [ 1, %bb2.i ] + store i32 %5, i32* %1, !dbg !16 + %6 = load i32* %1, !dbg !19 + %7 = icmp eq i32 %6, 0, !dbg !19 + call void @llvm.dbg.declare(metadata i16* %2, metadata !20, metadata !21), !dbg !22 + +br i1 %7, label %bb1, label %bb2, !dbg !19 + +bb1: ; preds = %func1.exit + +; CHECK-NOT: call void @llvm.dbg.declare + +ret void + +bb2: ; preds = %func1.exit + +; CHECK-NOT: call void @llvm.dbg.declare + +ret void +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 + +attributes #0 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!10, !11} + +!0 = !{!"0x11\0012\00clang\000\00\000\00\001", !1, !2, !3, !4, !2, !2} ; [ DW_TAG_compile_unit ] [/tmp/main.c] [DW_LANG_C99] +!1 = !{!"main.c", !"/tmp"} +!2 = !{} +!3 = !{null} +!4 = !{!5} +!5 = !{!"0x2e\00main\00main\00\000x9\000x0\000x1\000x0\000x0\000x0\000x1\000xa", !1, !6, !7, null, void ()* @main, null, null, !2} ; [ DW_TAG_subprogram ] [line 9] [def] [scope 10] [main] +!6 = !{!"0x29", !1} ; [ DW_TAG_file_type ] [/tmp/main.c] +!7 = !{!"0x15\00\000x0\000x0\000x0\000x0\000x0\000x0", null, null, null, !8, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ] +!8 = !{!9} +!9 = !{!"0x24\00short int\000x0\000x10\000x10\000x0\000x0\000x5", null, null} ; [ DW_TAG_base_type ] [short int] [line 0, size 16, align 16, offset 0, enc DW_ATE_signed] +!10 = !{i32 2, !"Dwarf Version", i32 4} +!11 = !{i32 2, !"Debug Info Version", i32 2} +!12 = !MDLocation(line: 6, column: 5, scope: !13, inlinedAt: !14) +!13 = !{!"0xb\000x6\000x5\000x0", !1, !5} ; [ DW_TAG_lexical_block ] [/tmp/main.c] +!14 = distinct !MDLocation(line: 11, column: 10, scope: !15) +!15 = !{!"0xb\000xb\000xa\000x0", !1, !5} ; [ DW_TAG_lexical_block ] [/tmp/main.c] +!16 = !MDLocation(line: 11, column: 10, scope: !15) +!17 = !MDLocation(line: 7, column: 5, scope: !18, inlinedAt: !14) +!18 = !{!"0xb\000x7\000x5\000x0", !1, !5} ; [ DW_TAG_lexical_block ] [/tmp/main.c] +!19 = !MDLocation(line: 12, column: 5, scope: !15) +!20 = !{!"0x101\00value\000x1000004\000x0", !5, null, !9, !14} ; [ DW_TAG_arg_variable ] [value] [line 4] +!21 = !{!"0x102"} ; [ DW_TAG_expression ] +!22 = !MDLocation(line: 4, column: 16, scope: !5, inlinedAt: !14) -- 1.9.1/karl-johan.karlsson@ericsson.com