[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
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 3110322..65d5928 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -1666,11 +1666,10 @@
};
if (auto *CI = dyn_cast<CastInst>(&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<ZExtInst>(&I))
+ return SrcDIExpr;
+ return nullptr;
} else if (auto *GEP = dyn_cast<GetElementPtrInst>(&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 b140dfa..c501fd8 100644
--- a/test/Transforms/InstCombine/cast-mul-select.ll
+++ b/test/Transforms/InstCombine/cast-mul-select.ll
@@ -170,3 +170,12 @@
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
+}