From 04f57483979827c5a61b09394022339bff610099 Mon Sep 17 00:00:00 2001 From: Wolfgang Pieb Date: Mon, 15 Apr 2019 17:36:29 +0000 Subject: [PATCH] [DEBUGINFO] Prevent Instcombine from dropping debuginfo when removing zexts Zexts can be treated like no-op casts when it comes to assessing whether their removal affects debug info. Reviewer: aprantl Differential Revision: https://reviews.llvm.org/D60641 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358431 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/Local.cpp | 9 ++++----- test/Transforms/InstCombine/cast-mul-select.ll | 9 +++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 3110322b314..65d5928e99c 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -1666,11 +1666,10 @@ DIExpression *llvm::salvageDebugInfoImpl(Instruction &I, }; if (auto *CI = dyn_cast(&I)) { - if (!CI->isNoopCast(DL)) - return nullptr; - - // No-op casts are irrelevant for debug info. - return SrcDIExpr; + // No-op casts and zexts are irrelevant for debug info. + if (CI->isNoopCast(DL) || isa(&I)) + return SrcDIExpr; + return nullptr; } else if (auto *GEP = dyn_cast(&I)) { unsigned BitWidth = M.getDataLayout().getIndexSizeInBits(GEP->getPointerAddressSpace()); diff --git a/test/Transforms/InstCombine/cast-mul-select.ll b/test/Transforms/InstCombine/cast-mul-select.ll index b140dfa2229..c501fd8d04c 100644 --- a/test/Transforms/InstCombine/cast-mul-select.ll +++ b/test/Transforms/InstCombine/cast-mul-select.ll @@ -170,3 +170,12 @@ exit: unreachable } +; Check that we don't drop debug info when a zext is removed. +define i1 @foo(i1 zeroext %b) { +; DBGINFO-LABEL: @foo( +; DBGINFO-NEXT: call void @llvm.dbg.value(metadata i1 %b +; DBGINFO-NEXT: ret i1 %b + + %frombool = zext i1 %b to i8 + ret i1 %b +} -- 2.11.0