Teach instsimplify to simplify calls to undef.
authorDan Gohman <gohman@apple.com>
Fri, 4 Nov 2011 18:32:42 +0000 (18:32 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 4 Nov 2011 18:32:42 +0000 (18:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143719 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/undef.ll

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
index 8134cc8487499215ebfa1bc74a7391e34394a366..9f5a1e82f5f89a74f6ece051e753124e263c04c2 100644 (file)
@@ -125,3 +125,10 @@ define i64 @test17(i64 %a) {
   %r = select i1 undef, i64 undef, i64 %a
   ret i64 %r
 }
+
+; @test18
+; CHECK: ret i64 undef
+define i64 @test18(i64 %a) {
+  %r = call i64 (i64)* undef(i64 %a)
+  ret i64 %r
+}