[PATCH] D48331: [DebugInfo][InstCombine] Preserve DI after combining zext instructions

Anastasis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 28 06:03:38 PDT 2018


gramanas updated this revision to Diff 153303.
gramanas added a comment.

Incorporate the -debugify test into the existing test files.


Repository:
  rL LLVM

https://reviews.llvm.org/D48331

Files:
  lib/Transforms/InstCombine/InstCombineCasts.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
@@ -1,19 +1,32 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -instcombine -S | FileCheck %s
+; RUN: opt -debugify -instcombine -S < %s | FileCheck %s -check-prefix DBGINFO
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32"
 
 define i32 @mul(i32 %x, i32 %y) {
 ; CHECK-LABEL: @mul(
 ; CHECK-NEXT:    [[C:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:    [[D:%.*]] = and i32 [[C]], 255
 ; CHECK-NEXT:    ret i32 [[D]]
-;
+
+; Test that when zext is evaluated in different type
+; we preserve the debug information in the resulting
+; instruction.
+; DBGINFO-LABEL: @mul(
+; DBGINFO-NEXT:    [[C:%.*]] = mul i32 {{.*}}
+; DBGINFO-NEXT:    call void @llvm.dbg.value(metadata i32 [[C]], metadata ![[DILocVarC:[0-9]+]]
+; DBGINFO-NEXT:    [[D:%.*]] = and i32 {{.*}}
+; DBGINFO-NEXT:    call void @llvm.dbg.value(metadata i32 [[D]], metadata ![[DILocVarD:[0-9]+]]
+
   %A = trunc i32 %x to i8
   %B = trunc i32 %y to i8
   %C = mul i8 %A, %B
   %D = zext i8 %C to i32
   ret i32 %D
+
+; DBGINFO: ![[DILocVarC]] = !DILocalVariable(
+; DBGINFO: ![[DILocVarD]] = !DILocalVariable(
 }
 
 define i32 @select1(i1 %cond, i32 %x, i32 %y, i32 %z) {
Index: lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1079,6 +1079,17 @@
     Value *Res = EvaluateInDifferentType(Src, DestTy, false);
     assert(Res->getType() == DestTy);
 
+    // When DestTy is integer, try to preserve any debug values
+    // referring to the zext being replaced.
+    // TODO: this should work for vectors as well, possibly
+    // via the use of dwarf fragments
+    if (DestTy->isIntegerTy()) {
+      insertReplacementDbgValues(
+          *Src, *Res, CI, [](DbgInfoIntrinsic &OldDII) -> DIExpression * {
+            return OldDII.getExpression();
+          });
+    }
+
     uint32_t SrcBitsKept = SrcTy->getScalarSizeInBits()-BitsToClear;
     uint32_t DestBitSize = DestTy->getScalarSizeInBits();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48331.153303.patch
Type: text/x-patch
Size: 2433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180628/1ae7fdc3/attachment.bin>


More information about the llvm-commits mailing list