[llvm] r340370 - [CodeGenPrepare] Clean up dbg.value use-before-def as late as possible

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 16:43:09 PDT 2018


Author: vedantk
Date: Tue Aug 21 16:43:08 2018
New Revision: 340370

URL: http://llvm.org/viewvc/llvm-project?rev=340370&view=rev
Log:
[CodeGenPrepare] Clean up dbg.value use-before-def as late as possible

CodeGenPrepare has a strategy for moving dbg.values so that a value's
definition always dominates its debug users. This cleanup was happening
too early (before certain CGP transforms were run), resulting in some
dbg.value use-before-def errors.

Perform this cleanup as late as possible to avoid use-before-def.

Modified:
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
    llvm/trunk/test/Transforms/CodeGenPrepare/X86/select.ll

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=340370&r1=340369&r2=340370&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Tue Aug 21 16:43:08 2018
@@ -426,11 +426,6 @@ bool CodeGenPrepare::runOnFunction(Funct
   // unconditional branch.
   EverMadeChange |= eliminateMostlyEmptyBlocks(F);
 
-  // llvm.dbg.value is far away from the value then iSel may not be able
-  // handle it properly. iSel will drop llvm.dbg.value if it can not
-  // find a node corresponding to the value.
-  EverMadeChange |= placeDbgValues(F);
-
   if (!DisableBranchOpts)
     EverMadeChange |= splitBranchCondition(F);
 
@@ -518,6 +513,10 @@ bool CodeGenPrepare::runOnFunction(Funct
       EverMadeChange |= simplifyOffsetableRelocate(*I);
   }
 
+  // Do this last to clean up use-before-def scenarios introduced by other
+  // preparatory transforms.
+  EverMadeChange |= placeDbgValues(F);
+
   return EverMadeChange;
 }
 

Modified: llvm/trunk/test/Transforms/CodeGenPrepare/X86/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CodeGenPrepare/X86/select.ll?rev=340370&r1=340369&r2=340370&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CodeGenPrepare/X86/select.ll (original)
+++ llvm/trunk/test/Transforms/CodeGenPrepare/X86/select.ll Tue Aug 21 16:43:08 2018
@@ -38,12 +38,12 @@ define float @fdiv_true_sink(float %a, f
 ;
 ; DEBUG-LABEL: @fdiv_true_sink(
 ; DEBUG-NEXT:  entry:
-; DEBUG-NEXT:    call void @llvm.dbg.value(metadata float [[DIV:%[^,]+]]
 ; DEBUG-NEXT:    [[CMP:%.*]] = fcmp ogt float [[A:%.*]], 1.000000e+00
 ; DEBUG-NEXT:    call void @llvm.dbg.value(metadata i1 [[CMP]]
 ; DEBUG-NEXT:    br i1 [[CMP]], label [[SELECT_TRUE_SINK:%.*]], label [[SELECT_END:%[^,]+]]
 ; DEBUG:       select.true.sink:
-; DEBUG-NEXT:    [[DIV]] = fdiv float [[A]], [[B:%.*]]
+; DEBUG-NEXT:    [[DIV:%.*]] = fdiv float [[A]], [[B:%.*]]
+; DEBUG-NEXT:    call void @llvm.dbg.value(metadata float [[DIV]]
 ; DEBUG-NEXT:    br label [[SELECT_END]]
 ; DEBUG:       select.end:
 ; DEBUG-NEXT:    [[SEL:%.*]] = phi float [ [[DIV]], [[SELECT_TRUE_SINK]] ], [ 2.000000e+00, [[ENTRY:%.*]] ]




More information about the llvm-commits mailing list