[llvm] r340371 - [CodeGenPrepare] Set debug locations when splitting selects

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 17:10:37 PDT 2018


Author: vedantk
Date: Tue Aug 21 17:10:37 2018
New Revision: 340371

URL: http://llvm.org/viewvc/llvm-project?rev=340371&view=rev
Log:
[CodeGenPrepare] Set debug locations when splitting selects

When splitting a select into a diamond, set debug locations on
newly-created branch instructions and phi nodes.

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=340371&r1=340370&r2=340371&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Tue Aug 21 17:10:37 2018
@@ -5680,6 +5680,7 @@ bool CodeGenPrepare::optimizeSelectInst(
         TrueBlock = BasicBlock::Create(SI->getContext(), "select.true.sink",
                                        EndBlock->getParent(), EndBlock);
         TrueBranch = BranchInst::Create(EndBlock, TrueBlock);
+        TrueBranch->setDebugLoc(SI->getDebugLoc());
       }
       auto *TrueInst = cast<Instruction>(SI->getTrueValue());
       TrueInst->moveBefore(TrueBranch);
@@ -5689,6 +5690,7 @@ bool CodeGenPrepare::optimizeSelectInst(
         FalseBlock = BasicBlock::Create(SI->getContext(), "select.false.sink",
                                         EndBlock->getParent(), EndBlock);
         FalseBranch = BranchInst::Create(EndBlock, FalseBlock);
+        FalseBranch->setDebugLoc(SI->getDebugLoc());
       }
       auto *FalseInst = cast<Instruction>(SI->getFalseValue());
       FalseInst->moveBefore(FalseBranch);
@@ -5703,7 +5705,8 @@ bool CodeGenPrepare::optimizeSelectInst(
 
     FalseBlock = BasicBlock::Create(SI->getContext(), "select.false",
                                     EndBlock->getParent(), EndBlock);
-    BranchInst::Create(EndBlock, FalseBlock);
+    auto *FalseBranch = BranchInst::Create(EndBlock, FalseBlock);
+    FalseBranch->setDebugLoc(SI->getDebugLoc());
   }
 
   // Insert the real conditional branch based on the original condition.
@@ -5738,6 +5741,7 @@ bool CodeGenPrepare::optimizeSelectInst(
     PN->takeName(SI);
     PN->addIncoming(getTrueOrFalseValue(SI, true, INS), TrueBlock);
     PN->addIncoming(getTrueOrFalseValue(SI, false, INS), FalseBlock);
+    PN->setDebugLoc(SI->getDebugLoc());
 
     SI->replaceAllUsesWith(PN);
     SI->eraseFromParent();

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=340371&r1=340370&r2=340371&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CodeGenPrepare/X86/select.ll (original)
+++ llvm/trunk/test/Transforms/CodeGenPrepare/X86/select.ll Tue Aug 21 17:10:37 2018
@@ -40,13 +40,13 @@ define float @fdiv_true_sink(float %a, f
 ; DEBUG-NEXT:  entry:
 ; 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-NEXT:    br i1 [[CMP]], label [[SELECT_TRUE_SINK:%.*]], label [[SELECT_END:%.*]], !dbg
 ; DEBUG:       select.true.sink:
 ; DEBUG-NEXT:    [[DIV:%.*]] = fdiv float [[A]], [[B:%.*]]
 ; DEBUG-NEXT:    call void @llvm.dbg.value(metadata float [[DIV]]
-; DEBUG-NEXT:    br label [[SELECT_END]]
+; DEBUG-NEXT:    br label [[SELECT_END]], !dbg
 ; DEBUG:       select.end:
-; DEBUG-NEXT:    [[SEL:%.*]] = phi float [ [[DIV]], [[SELECT_TRUE_SINK]] ], [ 2.000000e+00, [[ENTRY:%.*]] ]
+; DEBUG-NEXT:    [[SEL:%.*]] = phi float [ [[DIV]], [[SELECT_TRUE_SINK]] ], [ 2.000000e+00, [[ENTRY:%.*]] ], !dbg
 ; DEBUG-NEXT:    call void @llvm.dbg.value(metadata float [[SEL]]
 ; DEBUG-NEXT:    ret float [[SEL]]
 ;
@@ -69,6 +69,20 @@ define float @fdiv_false_sink(float %a,
 ; CHECK-NEXT:    [[SEL:%.*]] = phi float [ 4.000000e+00, [[ENTRY:%.*]] ], [ [[DIV]], [[SELECT_FALSE_SINK]] ]
 ; CHECK-NEXT:    ret float [[SEL]]
 ;
+; DEBUG-LABEL: @fdiv_false_sink(
+; DEBUG-NEXT:  entry:
+; DEBUG-NEXT:    [[CMP:%.*]] = fcmp ogt float [[A:%.*]], 3.000000e+00
+; DEBUG-NEXT:    call void @llvm.dbg.value(metadata i1 [[CMP]]
+; DEBUG-NEXT:    br i1 [[CMP]], label [[SELECT_END:%.*]], label [[SELECT_FALSE_SINK:%.*]], !dbg
+; DEBUG:       select.false.sink:
+; DEBUG-NEXT:    [[DIV:%.*]] = fdiv float [[A]], [[B:%.*]]
+; DEBUG-NEXT:    call void @llvm.dbg.value(metadata float [[DIV]]
+; DEBUG-NEXT:    br label [[SELECT_END]], !dbg
+; DEBUG:       select.end:
+; DEBUG-NEXT:    [[SEL:%.*]] = phi float [ 4.000000e+00, [[ENTRY:%.*]] ], [ [[DIV]], [[SELECT_FALSE_SINK]] ], !dbg
+; DEBUG-NEXT:    call void @llvm.dbg.value(metadata float [[SEL]]
+; DEBUG-NEXT:    ret float [[SEL]], !dbg
+;
 entry:
   %div = fdiv float %a, %b
   %cmp = fcmp ogt float %a, 3.0




More information about the llvm-commits mailing list