summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorRobert Lougher <rob.lougher@gmail.com>2016-12-14 17:49:19 +0000
committerRobert Lougher <rob.lougher@gmail.com>2016-12-14 17:49:19 +0000
commit2428a4050f066a51ff9dbd713aab0356ca435e7d (patch)
treea29dd267acda143a237f4f6bf41a5b25935af4bd /llvm/lib/Transforms
parent34a0f3dc2fcfec0ef5234407f0ea4cd473a6c166 (diff)
downloadbcm5719-llvm-2428a4050f066a51ff9dbd713aab0356ca435e7d.tar.gz
bcm5719-llvm-2428a4050f066a51ff9dbd713aab0356ca435e7d.zip
[InstCombine] Merge debug locations when folding through a phi node
If all the operands to a phi node are of the same operation, instcombine will try to pull them through the phi node, combining them into a single operation. When it does this, the debug location of the operation should be the merged debug locations of the phi node arguments. Patch 2 of 8 for D26256. Folding of a binary operation. Differential Revision: https://reviews.llvm.org/D26256 llvm-svn: 289679
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineInternal.h4
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp18
2 files changed, 21 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index e6b9bca1289..d13b94cb6c9 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -553,6 +553,10 @@ private:
Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
Instruction *FoldPHIArgZextsIntoPHI(PHINode &PN);
+ /// Helper function for FoldPHIArgXIntoPHI() to get debug location for the
+ /// folded operation.
+ DebugLoc PHIArgMergedDebugLoc(PHINode &PN);
+
Instruction *foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
ICmpInst::Predicate Cond, Instruction &I);
Instruction *foldAllocaCmp(ICmpInst &ICI, const AllocaInst *Alloca,
diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 675a5d17ad9..91bfe6c5c82 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -18,11 +18,27 @@
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Transforms/Utils/Local.h"
+#include "llvm/IR/DebugInfo.h"
using namespace llvm;
using namespace llvm::PatternMatch;
#define DEBUG_TYPE "instcombine"
+/// The PHI arguments will be folded into a single operation with a PHI node
+/// as input. The debug location of the single operation will be the merged
+/// locations of the original PHI node arguments.
+DebugLoc InstCombiner::PHIArgMergedDebugLoc(PHINode &PN) {
+ auto *FirstInst = cast<Instruction>(PN.getIncomingValue(0));
+ DILocation *Loc = FirstInst->getDebugLoc();
+
+ for (unsigned i = 1; i != PN.getNumIncomingValues(); ++i) {
+ auto *I = cast<Instruction>(PN.getIncomingValue(i));
+ Loc = DILocation::getMergedLocation(Loc, I->getDebugLoc());
+ }
+
+ return Loc;
+}
+
/// If we have something like phi [add (a,b), add(a,c)] and if a/b/c and the
/// adds all have a single use, turn this into a phi and a single binop.
Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
@@ -114,7 +130,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
for (unsigned i = 1, e = PN.getNumIncomingValues(); i != e; ++i)
NewBinOp->andIRFlags(PN.getIncomingValue(i));
- NewBinOp->setDebugLoc(FirstInst->getDebugLoc());
+ NewBinOp->setDebugLoc(PHIArgMergedDebugLoc(PN));
return NewBinOp;
}
OpenPOWER on IntegriCloud