Skip to content

Commit 4fe4221

Browse files
committedApr 15, 2019
[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 llvm-svn: 358431
1 parent 3929c43 commit 4fe4221

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed
 

‎llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,11 +1666,10 @@ DIExpression *llvm::salvageDebugInfoImpl(Instruction &I,
16661666
};
16671667

16681668
if (auto *CI = dyn_cast<CastInst>(&I)) {
1669-
if (!CI->isNoopCast(DL))
1670-
return nullptr;
1671-
1672-
// No-op casts are irrelevant for debug info.
1673-
return SrcDIExpr;
1669+
// No-op casts and zexts are irrelevant for debug info.
1670+
if (CI->isNoopCast(DL) || isa<ZExtInst>(&I))
1671+
return SrcDIExpr;
1672+
return nullptr;
16741673
} else if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
16751674
unsigned BitWidth =
16761675
M.getDataLayout().getIndexSizeInBits(GEP->getPointerAddressSpace());

‎llvm/test/Transforms/InstCombine/cast-mul-select.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,12 @@ exit:
170170
unreachable
171171
}
172172

173+
; Check that we don't drop debug info when a zext is removed.
174+
define i1 @foo(i1 zeroext %b) {
175+
; DBGINFO-LABEL: @foo(
176+
; DBGINFO-NEXT: call void @llvm.dbg.value(metadata i1 %b
177+
; DBGINFO-NEXT: ret i1 %b
178+
179+
%frombool = zext i1 %b to i8
180+
ret i1 %b
181+
}

0 commit comments

Comments
 (0)
Please sign in to comment.