summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2018-01-29 05:59:55 +0000
committerDavide Italiano <davide@freebsd.org>2018-01-29 05:59:55 +0000
commit8b797a0fd25d8000b239c76016833ad4ab81339b (patch)
tree2d7508d5ed745092747e409e07d2596c67c46dcc /llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
parent23743f48fa51e6ffb7cef49d9bb20fdb50d4a8a1 (diff)
downloadbcm5719-llvm-8b797a0fd25d8000b239c76016833ad4ab81339b.tar.gz
bcm5719-llvm-8b797a0fd25d8000b239c76016833ad4ab81339b.zip
[CVP] Don't Replace incoming values from unreachable blocks with undef.
This pretty much reverts r322006, except that we keep the test, because we work around the issue exposed in a different way (a recursion limit in value tracking). There's still probably some sequence that exposes this problem, and the proper way to fix that for somebody who has time is outlined in the code review. llvm-svn: 323630
Diffstat (limited to 'llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp28
1 files changed, 4 insertions, 24 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 07803f6e0c7..535d43cdf9e 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -14,7 +14,6 @@
#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/GlobalsModRef.h"
@@ -123,8 +122,8 @@ static bool processSelect(SelectInst *S, LazyValueInfo *LVI) {
return true;
}
-static bool processPHI(PHINode *P, LazyValueInfo *LVI, const SimplifyQuery &SQ,
- DenseSet<BasicBlock *> &ReachableBlocks) {
+static bool processPHI(PHINode *P, LazyValueInfo *LVI,
+ const SimplifyQuery &SQ) {
bool Changed = false;
BasicBlock *BB = P->getParent();
@@ -132,18 +131,7 @@ static bool processPHI(PHINode *P, LazyValueInfo *LVI, const SimplifyQuery &SQ,
Value *Incoming = P->getIncomingValue(i);
if (isa<Constant>(Incoming)) continue;
- // If the incoming value is coming from an unreachable block, replace
- // it with undef and go on. This is good for two reasons:
- // 1) We skip an LVI query for an unreachable block
- // 2) We transform the incoming value so that the code below doesn't
- // mess around with IR in unreachable blocks.
- BasicBlock *IncomingBB = P->getIncomingBlock(i);
- if (!ReachableBlocks.count(IncomingBB)) {
- P->setIncomingValue(i, UndefValue::get(P->getType()));
- continue;
- }
-
- Value *V = LVI->getConstantOnEdge(Incoming, IncomingBB, BB, P);
+ Value *V = LVI->getConstantOnEdge(Incoming, P->getIncomingBlock(i), BB, P);
// Look if the incoming value is a select with a scalar condition for which
// LVI can tells us the value. In that case replace the incoming value with
@@ -575,14 +563,6 @@ static Constant *getConstantAt(Value *V, Instruction *At, LazyValueInfo *LVI) {
static bool runImpl(Function &F, LazyValueInfo *LVI, const SimplifyQuery &SQ) {
bool FnChanged = false;
-
- // Compute reachability from the entry block of this function via an RPO
- // walk. We use this information when processing PHIs.
- DenseSet<BasicBlock *> ReachableBlocks;
- ReversePostOrderTraversal<Function *> RPOT(&F);
- for (BasicBlock *BB : RPOT)
- ReachableBlocks.insert(BB);
-
// Visiting in a pre-order depth-first traversal causes us to simplify early
// blocks before querying later blocks (which require us to analyze early
// blocks). Eagerly simplifying shallow blocks means there is strictly less
@@ -597,7 +577,7 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, const SimplifyQuery &SQ) {
BBChanged |= processSelect(cast<SelectInst>(II), LVI);
break;
case Instruction::PHI:
- BBChanged |= processPHI(cast<PHINode>(II), LVI, SQ, ReachableBlocks);
+ BBChanged |= processPHI(cast<PHINode>(II), LVI, SQ);
break;
case Instruction::ICmp:
case Instruction::FCmp:
OpenPOWER on IntegriCloud