aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-06 18:57:34 +0000
committerChris Lattner <sabre@nondot.org>2007-04-06 18:57:34 +0000
commit4802d90ca8deabe490d7baa263609a514bc11c16 (patch)
tree61a389e0dfad97ba2bf180370ea3c5012ffe52d1
parentb62eee4a693db56b2397aa325e0e4083b1a66c80 (diff)
implement Transforms/InstCombine/malloc2.ll and PR1313
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35700 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index d9b15de1af..2167144fc1 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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.