Teach instsimplify to simplify calls to undef.
[oota-llvm.git] / lib / Analysis / InstructionSimplify.cpp
index c2ddc6d486372a434562efad2dbdeb4cbe5f5fe4..c1416328b742ee68f48ac43b0e64a36862e6daac 100644 (file)
@@ -2474,6 +2474,14 @@ Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
   return ::SimplifyCmpInst(Predicate, LHS, RHS, TD, DT, RecursionLimit);
 }
 
+static Value *SimplifyCallInst(CallInst *CI) {
+  // call undef -> undef
+  if (isa<UndefValue>(CI->getCalledValue()))
+    return UndefValue::get(CI->getType());
+
+  return 0;
+}
+
 /// SimplifyInstruction - See if we can compute a simplified version of this
 /// instruction.  If not, this returns null.
 Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD,
@@ -2569,6 +2577,9 @@ Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD,
   case Instruction::PHI:
     Result = SimplifyPHINode(cast<PHINode>(I), DT);
     break;
+  case Instruction::Call:
+    Result = SimplifyCallInst(cast<CallInst>(I));
+    break;
   }
 
   /// If called on unreachable code, the above logic may report that the