#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"
Instruction *visitSetCondInst(BinaryOperator *I);
Instruction *visitShiftInst(Instruction *I);
Instruction *visitCastInst(CastInst *CI);
+ Instruction *visitPHINode(PHINode *PN);
Instruction *visitGetElementPtrInst(GetElementPtrInst *GEP);
Instruction *visitMemAccessInst(MemAccessInst *MAI);
// 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()) {
}
+// 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