diff options
author | Dan Gohman <gohman@apple.com> | 2011-11-04 18:32:42 +0000 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2011-11-14 09:11:47 -0800 |
commit | 6a79cfaee8ca55d472cddcbabbd6d769754757cc (patch) | |
tree | 6bc33fae102ff3321bc0bbff1fa139ed4b44eb12 | |
parent | c667fadfbc2b70fd5d8e733fe2287c5704839b7a (diff) | |
download | external_llvm-6a79cfaee8ca55d472cddcbabbd6d769754757cc.zip external_llvm-6a79cfaee8ca55d472cddcbabbd6d769754757cc.tar.gz external_llvm-6a79cfaee8ca55d472cddcbabbd6d769754757cc.tar.bz2 |
Teach instsimplify to simplify calls to undef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143719 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/InstructionSimplify.cpp | 11 | ||||
-rw-r--r-- | test/Transforms/InstSimplify/undef.ll | 7 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index c2ddc6d..c141632 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -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 diff --git a/test/Transforms/InstSimplify/undef.ll b/test/Transforms/InstSimplify/undef.ll index 8134cc8..9f5a1e8 100644 --- a/test/Transforms/InstSimplify/undef.ll +++ b/test/Transforms/InstSimplify/undef.ll @@ -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 +} |