Skip to content

Commit

Permalink
[InstCombine] Skip addrspacecast when lowering dbg.declare
Browse files Browse the repository at this point in the history
Change-Id: I99e4fc3dedad09c038b026bd62e316ccdfab82dc
  • Loading branch information
epilk committed Jan 8, 2025
1 parent d4cd6af commit 656552e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,11 @@ bool llvm::LowerDbgDeclare(Function &F) {
} else if (BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
if (BI->getType()->isPointerTy())
WorkList.push_back(BI);
} else if (auto *ASC = dyn_cast<AddrSpaceCastInst>(U)) {
// Only look through addrspacecasts if the declare uses new
// expressions (to avoid a difference with upstream).
if (DDI->getExpression()->holdsNewElements())
WorkList.push_back(ASC);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt -passes='instcombine' -S --experimental-debuginfo-iterators=true < %s | FileCheck %s
; RUN: opt -passes='instcombine' -S --experimental-debuginfo-iterators=false < %s | FileCheck %s
; RUN: opt -passes='instcombine' -S < %s | FileCheck %s

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -20,14 +19,31 @@ define i32 @foo() !dbg !5 {
;
entry:
%var = alloca i32, align 4
tail call void @llvm.dbg.declare(metadata ptr %var, metadata !11, metadata !DIExpression(DIOpArg(0, ptr), DIOpDeref(i32))), !dbg !12
#dbg_declare(ptr %var, !11, !DIExpression(DIOpArg(0, ptr), DIOpDeref(i32)), !12)
store i32 42, ptr %var, align 4
call void @escape(ptr %var)
%0 = load i32, ptr %var, align 4
ret i32 %0
}

declare void @llvm.dbg.declare(metadata, metadata, metadata)
define void @bar() !dbg !15 {
; CHECK-LABEL: define void @bar(
; CHECK-SAME: ) !dbg [[DBG13:![0-9]+]] {
; CHECK-NEXT: [[VAR:%.*]] = alloca i32, align 4, addrspace(5)
; CHECK-NEXT: [[VAR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[VAR]] to ptr
; CHECK-NEXT: #dbg_value(i32 42, [[META15:![0-9]+]], !DIExpression(DIOpArg(0, i32)), [[META16:![0-9]+]])
; CHECK-NEXT: store i32 42, ptr [[VAR_ASCAST]], align 4
; CHECK-NEXT: #dbg_value(ptr addrspace(5) [[VAR]], [[META15]], !DIExpression(DIOpArg(0, ptr addrspace(5)), DIOpDeref(i32)), [[META16]])
; CHECK-NEXT: call void @escape(ptr nonnull [[VAR_ASCAST]])
; CHECK-NEXT: ret void
;
%var = alloca i32, align 4, addrspace(5)
%var.ascast = addrspacecast ptr addrspace(5) %var to ptr
#dbg_declare(ptr addrspace(5) %var, !17, !DIExpression(DIOpArg(0, ptr addrspace(5)), DIOpDeref(i32)), !18)
store i32 42, ptr %var.ascast, align 4
call void @escape(ptr %var.ascast)
ret void
}

declare void @escape(ptr)

Expand All @@ -48,6 +64,13 @@ declare void @escape(ptr)
!10 = !{!11}
!11 = !DILocalVariable(name: "var", scope: !5, file: !6, line: 5, type: !9)
!12 = !DILocation(line: 1, column: 1, scope: !5)
!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
!14 = !DILocalVariable(name: "ptr", scope: !5, file: !6, line: 5, type: !13)
!15 = distinct !DISubprogram(name: "bar", scope: !6, file: !6, line: 4, type: !7, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !16)
!16 = !{!17}
!17 = !DILocalVariable(name: "var", scope: !15, file: !6, line: 5, type: !9)
!18 = !DILocation(line: 1, column: 1, scope: !15)

;.
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "clang 19.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
; CHECK: [[META1]] = !DIFile(filename: "t.c", directory: {{.*}})
Expand All @@ -59,4 +82,8 @@ declare void @escape(ptr)
; CHECK: [[META10]] = !{[[META11]]}
; CHECK: [[META11]] = !DILocalVariable(name: "var", scope: [[DBG5]], file: [[META6]], line: 5, type: [[META9]])
; CHECK: [[META12]] = !DILocation(line: 0, scope: [[DBG5]])
; CHECK: [[DBG13]] = distinct !DISubprogram(name: "bar", scope: [[META6]], file: [[META6]], line: 4, type: [[META7]], scopeLine: 4, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META14:![0-9]+]])
; CHECK: [[META14]] = !{[[META15]]}
; CHECK: [[META15]] = !DILocalVariable(name: "var", scope: [[DBG13]], file: [[META6]], line: 5, type: [[META9]])
; CHECK: [[META16]] = !DILocation(line: 0, scope: [[DBG13]])
;.

0 comments on commit 656552e

Please sign in to comment.