From 656552edc693e2bb4abc9258399c39d190fce2b3 Mon Sep 17 00:00:00 2001 From: Emma Pilkington Date: Mon, 15 Jul 2024 16:10:10 -0400 Subject: [PATCH] [InstCombine] Skip addrspacecast when lowering dbg.declare Change-Id: I99e4fc3dedad09c038b026bd62e316ccdfab82dc --- llvm/lib/Transforms/Utils/Local.cpp | 5 +++ .../heterogeneous-poison-lower-dbg-declare.ll | 35 ++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index b92e016fe05ed3..4dee0227b1f379 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2136,6 +2136,11 @@ bool llvm::LowerDbgDeclare(Function &F) { } else if (BitCastInst *BI = dyn_cast(U)) { if (BI->getType()->isPointerTy()) WorkList.push_back(BI); + } else if (auto *ASC = dyn_cast(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); } } } diff --git a/llvm/test/Transforms/InstCombine/heterogeneous-poison-lower-dbg-declare.ll b/llvm/test/Transforms/InstCombine/heterogeneous-poison-lower-dbg-declare.ll index 9aaca0c4603b67..8b87e7b4abb1a2 100644 --- a/llvm/test/Transforms/InstCombine/heterogeneous-poison-lower-dbg-declare.ll +++ b/llvm/test/Transforms/InstCombine/heterogeneous-poison-lower-dbg-declare.ll @@ -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" @@ -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) @@ -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: {{.*}}) @@ -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]]) ;.