[PATCH] D48331: [DebugInfo][InstCombine] Preserve DI after merging instructions
Anastasis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 20 02:27:35 PDT 2018
gramanas updated this revision to Diff 152040.
gramanas added a comment.
Clean up code and test
Repository:
rL LLVM
https://reviews.llvm.org/D48331
Files:
lib/Transforms/InstCombine/InstCombineCasts.cpp
test/Transforms/InstCombine/debuginfo-trunc-and-zext.ll
Index: test/Transforms/InstCombine/debuginfo-trunc-and-zext.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstCombine/debuginfo-trunc-and-zext.ll
@@ -0,0 +1,12 @@
+; RUN: opt -debugify -instcombine -S < %s | FileCheck %s
+
+define <2 x i64> @test3(<2 x i64> %A) {
+ %trunc = trunc <2 x i64> %A to <2 x i32>
+ %and = and <2 x i32> %trunc, <i32 23, i32 42>
+ %zext = zext <2 x i32> %and to <2 x i64>
+ ret <2 x i64> %zext
+}
+
+; CHECK: call void @llvm.dbg.value{{.*}}
+; CHECK: call void @llvm.dbg.value{{.*}}
+; CHECK: call void @llvm.dbg.value{{.*}}
Index: lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1088,6 +1088,21 @@
uint32_t SrcBitsKept = SrcTy->getScalarSizeInBits()-BitsToClear;
uint32_t DestBitSize = DestTy->getScalarSizeInBits();
+ // Since the old instruction is merged, we preserve it's DI as
+ // a fragment in the resulting instruction
+ SmallVector<DbgInfoIntrinsic *, 1> SrcDbgInsts;
+ findDbgUsers(SrcDbgInsts, Src);
+ if (SrcDbgInsts.size()) {
+ DIBuilder DIB(*CI.getModule());
+ for (auto *DII : SrcDbgInsts) {
+ auto Fragment = DIExpression::createFragmentExpression(
+ DII->getExpression(), SrcBitsKept, DestBitSize);
+ DIB.insertDbgValueIntrinsic(
+ Res, DII->getVariable(), Fragment.getValue(),
+ DII->getDebugLoc().get(), &*std::next(CI.getIterator()));
+ }
+ }
+
// If the high bits are already filled with zeros, just replace this
// cast with the result.
if (MaskedValueIsZero(Res,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48331.152040.patch
Type: text/x-patch
Size: 1759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180620/1ec7b13a/attachment.bin>
More information about the llvm-commits
mailing list