diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-04-06 18:57:34 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-04-06 18:57:34 +0000 |
| commit | 3dbe65f80abeea7012c57c32ac2d74ef778f4b7e (patch) | |
| tree | e5a54254ed6cf911fcd288475bfb2dd03f472f03 /llvm/lib/Transforms | |
| parent | 992b451e3328a22e2893fa6f977ba89f9ef7a341 (diff) | |
| download | bcm5719-llvm-3dbe65f80abeea7012c57c32ac2d74ef778f4b7e.tar.gz bcm5719-llvm-3dbe65f80abeea7012c57c32ac2d74ef778f4b7e.zip | |
implement Transforms/InstCombine/malloc2.ll and PR1313
llvm-svn: 35700
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index d9b15de1afb..2167144fc18 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4744,7 +4744,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { if (Instruction *NV = FoldOpIntoPhi(I)) return NV; break; - case Instruction::Select: + case Instruction::Select: { // If either operand of the select is a constant, we can fold the // comparison into the select arms, which will cause one to be // constant folded and the select turned into a bitwise or. @@ -4771,6 +4771,16 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { return new SelectInst(LHSI->getOperand(0), Op1, Op2); break; } + case Instruction::Malloc: + // If we have (malloc != null), and if the malloc has a single use, we + // can assume it is successful and remove the malloc. + if (LHSI->hasOneUse() && isa<ConstantPointerNull>(RHSC)) { + AddToWorkList(LHSI); + return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, + !isTrueWhenEqual(I))); + } + break; + } } // If we can optimize a 'icmp GEP, P' or 'icmp P, GEP', do so now. |

