[PATCH] D60641: [DebugInfo at O2] Prevent Instcombine from dropping debug info when removing zexts (fixes PR41475)

Wolfgang Pieb via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 12 15:41:51 PDT 2019


wolfgangp created this revision.
wolfgangp added reviewers: vsk, aprantl, jmorse, probinson.

See PR41475 <https://bugs.llvm.org/show_bug.cgi?id=41475> for a short description of the problem.

salvageDebugInfo() in Transforms/Utils/Local.cpp decides how an instruction's actions are affecting a value that is used in a dbg.value() call and attempts to return a DIExpr that would make it possible to reconstruct the original value from the instruction's source operand in case the instruction is removed by someone (e.g. by instcombine). Noop casts don't change the value and we can safely say that the cast's source operand can be used by the debug user, thus we simply return the DIExpr found there.

This patch extends this to zext instructions, which are not a noop cast, but arguably don't change the value. Thus the source value of a zext can replace the result value in debug users and survive a removal of the zext instruction.


https://reviews.llvm.org/D60641

Files:
  lib/Transforms/Utils/Local.cpp
  test/Transforms/InstCombine/cast-mul-select.ll


Index: test/Transforms/InstCombine/cast-mul-select.ll
===================================================================
--- test/Transforms/InstCombine/cast-mul-select.ll
+++ 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
+}
Index: lib/Transforms/Utils/Local.cpp
===================================================================
--- lib/Transforms/Utils/Local.cpp
+++ 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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60641.194968.patch
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190412/f602b09b/attachment-0001.bin>


More information about the llvm-commits mailing list