[llvm-commits] [llvm] r122516 - /llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp

Owen Anderson resistor at mac.com
Thu Dec 23 12:57:35 PST 2010


Author: resistor
Date: Thu Dec 23 14:57:35 2010
New Revision: 122516

URL: http://llvm.org/viewvc/llvm-project?rev=122516&view=rev
Log:
It is possible for SimplifyCFG to cause PHI nodes to become redundant too late in the optimization
pipeline to be caught by instcombine, and it's not feasible to catch them in SimplifyCFG because the
use-lists are in an inconsistent state at the point where it could know that it need to simplify them.
Instead, have CodeGenPrepare look for trivially redundant PHIs as part of its general cleanup effort.

Modified:
    llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=122516&r1=122515&r2=122516&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Thu Dec 23 14:57:35 2010
@@ -22,6 +22,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/IntrinsicInst.h"
 #include "llvm/Pass.h"
+#include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Analysis/ProfileInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetLowering.h"
@@ -959,7 +960,15 @@
   for (BasicBlock::iterator BBI = BB.begin(), E = BB.end(); BBI != E; ) {
     Instruction *I = BBI++;
 
-    if (CastInst *CI = dyn_cast<CastInst>(I)) {
+    if (PHINode *P = dyn_cast<PHINode>(I)) {
+      // It is possible for very late stage optimizations (such as SimplifyCFG)
+      // to introduce PHI nodes too late to be cleaned up.  If we detect such a
+      // trivial PHI, go ahead and zap it here.
+      if (Value *V = SimplifyInstruction(P)) {
+        P->replaceAllUsesWith(V);
+        P->eraseFromParent();
+      }
+    } else if (CastInst *CI = dyn_cast<CastInst>(I)) {
       // If the source of the cast is a constant, then this should have
       // already been constant folded.  The only reason NOT to constant fold
       // it is if something (e.g. LSR) was careful to place the constant





More information about the llvm-commits mailing list