[llvm] r323630 - [CVP] Don't Replace incoming values from unreachable blocks with undef.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 28 21:59:55 PST 2018


Author: davide
Date: Sun Jan 28 21:59:55 2018
New Revision: 323630

URL: http://llvm.org/viewvc/llvm-project?rev=323630&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
    llvm/trunk/test/Transforms/CorrelatedValuePropagation/pr35807.ll

Modified: llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp?rev=323630&r1=323629&r2=323630&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp Sun Jan 28 21:59:55 2018
@@ -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,
   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, LazyV
     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,
 
 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, LazyVal
         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:

Modified: llvm/trunk/test/Transforms/CorrelatedValuePropagation/pr35807.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CorrelatedValuePropagation/pr35807.ll?rev=323630&r1=323629&r2=323630&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CorrelatedValuePropagation/pr35807.ll (original)
+++ llvm/trunk/test/Transforms/CorrelatedValuePropagation/pr35807.ll Sun Jan 28 21:59:55 2018
@@ -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




More information about the llvm-commits mailing list