summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp28
-rw-r--r--llvm/test/Transforms/CorrelatedValuePropagation/pr35807.ll1
2 files changed, 5 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:
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/pr35807.ll b/llvm/test/Transforms/CorrelatedValuePropagation/pr35807.ll
index 8f72b596d28..a9705caaf3c 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/pr35807.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/pr35807.ll
@@ -25,6 +25,7 @@ define void @patatino() {
; CHECK: bb32:
; CHECK-NEXT: br i1 undef, label [[BB40]], label [[BB24]]
; CHECK: bb40:
+; CHECK-NEXT: [[TMP41:%.*]] = phi i64 [ 4, [[BB4]] ], [ [[TMP20]], [[BB14]] ], [ undef, [[BB32]] ]
; CHECK-NEXT: ret void
;
br i1 undef, label %bb3, label %bb4
OpenPOWER on IntegriCloud