From b0585893ccb78508e900754c4974b0e95aafd4bf Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 17 Apr 2018 22:03:08 +0000 Subject: [Mem2Reg] Create merged debug locations for inserted phis Track the debug locations of the incoming values to newly-created phis, and apply merged debug locations to the phis. A merged location will be on line 0, but will have the correct scope set. This improves crash reporting when an inlined instruction with a merged location triggers a machine exception. A debugger will be able to narrow down the crash to the correct inlined scope, instead of simply pointing to the outer scope of the caller. Taken together with a change allows generating merged line-0 locations for instructions which aren't calls, this results in a 0.5% increase in the uncompressed size of the .debug_line section of a stage2+Release build of clang (-O3 -g). rdar://33858697 Differential Revision: https://reviews.llvm.org/D45397 llvm-svn: 330227 --- .../Transforms/Mem2Reg/dbg-inline-scope-for-phi.ll | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 llvm/test/Transforms/Mem2Reg/dbg-inline-scope-for-phi.ll (limited to 'llvm/test/Transforms/Mem2Reg') diff --git a/llvm/test/Transforms/Mem2Reg/dbg-inline-scope-for-phi.ll b/llvm/test/Transforms/Mem2Reg/dbg-inline-scope-for-phi.ll new file mode 100644 index 00000000000..680f2dd2833 --- /dev/null +++ b/llvm/test/Transforms/Mem2Reg/dbg-inline-scope-for-phi.ll @@ -0,0 +1,110 @@ +; RUN: opt -S < %s -mem2reg -verify | FileCheck %s + +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.13.0" + +; Original source (with some whitespace removed): +; +; extern int *getp(); +; extern int cond(); +; int get1() { return *getp(); } +; int get2(int *p) { return *p; } +; int bug(int *p) { +; if (cond()) return get1(); +; else return get2(p); +; } + +define i32 @get1() !dbg !8 { + %1 = call i32* (...) @getp(), !dbg !12 + %2 = load i32, i32* %1, align 4, !dbg !13 + ret i32 %2, !dbg !14 +} + +declare i32* @getp(...) + +define i32 @get2(i32*) !dbg !15 { + %2 = alloca i32*, align 8 + store i32* %0, i32** %2, align 8 + call void @llvm.dbg.declare(metadata i32** %2, metadata !19, metadata !DIExpression()), !dbg !20 + %3 = load i32*, i32** %2, align 8, !dbg !21 + %4 = load i32, i32* %3, align 4, !dbg !22 + ret i32 %4, !dbg !23 +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) + +; CHECK-LABEL: define i32 @bug +define i32 @bug(i32*) !dbg !24 { + %2 = alloca i32, align 4 + %3 = alloca i32*, align 8 + store i32* %0, i32** %3, align 8 + call void @llvm.dbg.declare(metadata i32** %3, metadata !25, metadata !DIExpression()), !dbg !26 + %4 = call i32 (...) @cond(), !dbg !27 + %5 = icmp ne i32 %4, 0, !dbg !27 + br i1 %5, label %6, label %8, !dbg !29 + +;