aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-06 18:06:38 +0000
committerChris Lattner <sabre@nondot.org>2002-05-06 18:06:38 +0000
commit473945d1dc83978d2c0f06da94a924cf71c85fb7 (patch)
tree40e3cdc13f8cbbb11ae3cf4ea22995510c1b9ada /lib
parentfee97e83ce0ca63bdb7b943ce5d09892223a745a (diff)
downloadexternal_llvm-473945d1dc83978d2c0f06da94a924cf71c85fb7.zip
external_llvm-473945d1dc83978d2c0f06da94a924cf71c85fb7.tar.gz
external_llvm-473945d1dc83978d2c0f06da94a924cf71c85fb7.tar.bz2
Handle X = phi Y --> X = Y
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2501 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 0c08912..5b9f318 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -19,6 +19,7 @@
#include "llvm/ConstantHandling.h"
#include "llvm/iMemory.h"
#include "llvm/iOther.h"
+#include "llvm/iPHINode.h"
#include "llvm/iOperators.h"
#include "llvm/Pass.h"
#include "llvm/Support/InstIterator.h"
@@ -69,6 +70,7 @@ namespace {
Instruction *visitSetCondInst(BinaryOperator *I);
Instruction *visitShiftInst(Instruction *I);
Instruction *visitCastInst(CastInst *CI);
+ Instruction *visitPHINode(PHINode *PN);
Instruction *visitGetElementPtrInst(GetElementPtrInst *GEP);
Instruction *visitMemAccessInst(MemAccessInst *MAI);
@@ -412,6 +414,8 @@ static inline bool isEliminableCastOfCast(const CastInst *CI,
// CastInst simplification
//
Instruction *InstCombiner::visitCastInst(CastInst *CI) {
+ if (CI->use_empty()) return 0; // Don't fix dead instructions...
+
// If the user is casting a value to the same type, eliminate this cast
// instruction...
if (CI->getType() == CI->getOperand(0)->getType() && !CI->use_empty()) {
@@ -436,6 +440,21 @@ Instruction *InstCombiner::visitCastInst(CastInst *CI) {
}
+// PHINode simplification
+//
+Instruction *InstCombiner::visitPHINode(PHINode *PN) {
+ if (PN->use_empty()) return 0; // Don't fix dead instructions...
+
+ // If the PHI node only has one incoming value, eliminate the PHI node...
+ if (PN->getNumIncomingValues() == 1) {
+ AddUsesToWorkList(PN); // Add all modified instrs to worklist
+ PN->replaceAllUsesWith(PN->getIncomingValue(0));
+ return PN;
+ }
+
+ return 0;
+}
+
Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst *GEP) {
// Is it getelementptr %P, uint 0