[llvm] r335696 - [InstCombine] Avoid creating mis-sized dbg.values in commonCastTransforms()

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 26 17:47:53 PDT 2018


Author: vedantk
Date: Tue Jun 26 17:47:53 2018
New Revision: 335696

URL: http://llvm.org/viewvc/llvm-project?rev=335696&view=rev
Log:
[InstCombine] Avoid creating mis-sized dbg.values in commonCastTransforms()

This prevents InstCombine from creating mis-sized dbg.values when
replacing a sequence of casts with a simpler cast. For example, in:

  (fptrunc (floor (fpext X))) -> (floorf X)

We no longer emit dbg.value(X) (with a 32-bit float operand) to describe
(fpext X) (which is a 64-bit float).

This was diagnosed by the debugify check added in r335682.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
    llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=335696&r1=335695&r2=335696&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Tue Jun 26 17:47:53 2018
@@ -266,10 +266,13 @@ Instruction *InstCombiner::commonCastTra
     if (Instruction::CastOps NewOpc = isEliminableCastPair(CSrc, &CI)) {
       // The first cast (CSrc) is eliminable so we need to fix up or replace
       // the second cast (CI). CSrc will then have a good chance of being dead.
-      auto *Res = CastInst::Create(NewOpc, CSrc->getOperand(0), CI.getType());
+      auto *Ty = CI.getType();
+      auto *Res = CastInst::Create(NewOpc, CSrc->getOperand(0), Ty);
       // Replace debug users of the eliminable cast by emitting debug values
       // which refer to the new cast.
-      insertReplacementDbgValues(*CSrc, *Res, *std::next(CI.getIterator()));
+      if (Ty->isIntegerTy() || Ty->isPointerTy())
+        // TODO: Support floats and vectors (see DW_OP_convert, fragment).
+        insertReplacementDbgValues(*CSrc, *Res, *std::next(CI.getIterator()));
       return Res;
     }
   }

Modified: llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll?rev=335696&r1=335695&r2=335696&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/double-float-shrink-2.ll Tue Jun 26 17:47:53 2018
@@ -5,6 +5,7 @@
 ; RUN: opt < %s -instcombine -S -mtriple "i386-pc-mingw32" | FileCheck -check-prefix=ALL -check-prefix=DO-SIMPLIFY %s
 ; RUN: opt < %s -instcombine -S -mtriple "x86_64-pc-mingw32" | FileCheck -check-prefix=ALL -check-prefix=DO-SIMPLIFY %s
 ; RUN: opt < %s -instcombine -S -mtriple "sparc-sun-solaris" | FileCheck -check-prefix=ALL -check-prefix=DO-SIMPLIFY %s
+; RUN: opt < %s -enable-debugify -instcombine -S -mtriple "x86_64-pc-win32" 2>&1 | FileCheck -check-prefix=DBG-VALID %s
 
 declare double @floor(double)
 declare double @ceil(double)
@@ -685,3 +686,5 @@ define float @test_no_shrink_intrin_fabs
   %F = fptrunc double %E to float
   ret float %F
 }
+
+; DBG-VALID: CheckModuleDebugify: PASS




More information about the llvm-commits mailing list