summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-09 23:28:39 +0000
committerChris Lattner <sabre@nondot.org>2009-11-09 23:28:39 +0000
commitc1f19071f8631fe617a5e1a6ac07670db5c31008 (patch)
tree19e4f6e6614783e5d80e30539dfe756420ced88a /llvm/lib/Analysis/InstructionSimplify.cpp
parent60198df2626f89310827085c45625b2af58f904d (diff)
downloadbcm5719-llvm-c1f19071f8631fe617a5e1a6ac07670db5c31008.tar.gz
bcm5719-llvm-c1f19071f8631fe617a5e1a6ac07670db5c31008.zip
rename SimplifyCompare -> SimplifyCmpInst and split it into
Simplify[IF]Cmp pieces. Add some predicates to CmpInst to determine whether a predicate is fp or int. llvm-svn: 86624
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp45
1 files changed, 35 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 03bc9a01ce9..0369ab3ad5f 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -32,11 +32,12 @@ Value *llvm::SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
}
-/// SimplifyCompare - Given operands for a CmpInst, see if we can
-/// fold the result.
-Value *llvm::SimplifyCompare(unsigned Predicate, Value *LHS, Value *RHS,
- const TargetData *TD) {
+/// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
+/// fold the result. If not, this returns null.
+Value *llvm::SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
+ const TargetData *TD) {
CmpInst::Predicate Pred = (CmpInst::Predicate)Predicate;
+ assert(CmpInst::isIntPredicate(Pred) && "Not an integer compare!");
if (Constant *CLHS = dyn_cast<Constant>(LHS))
if (Constant *CRHS = dyn_cast<Constant>(RHS))
@@ -44,12 +45,36 @@ Value *llvm::SimplifyCompare(unsigned Predicate, Value *LHS, Value *RHS,
// If this is an integer compare and the LHS and RHS are the same, fold it.
if (LHS == RHS)
- if (isa<IntegerType>(LHS->getType()) || isa<PointerType>(LHS->getType())) {
- if (ICmpInst::isTrueWhenEqual(Pred))
- return ConstantInt::getTrue(LHS->getContext());
- else
- return ConstantInt::getFalse(LHS->getContext());
- }
+ if (ICmpInst::isTrueWhenEqual(Pred))
+ return ConstantInt::getTrue(LHS->getContext());
+ else
+ return ConstantInt::getFalse(LHS->getContext());
+
+ return 0;
+}
+
+/// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can
+/// fold the result. If not, this returns null.
+Value *llvm::SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
+ const TargetData *TD) {
+ CmpInst::Predicate Pred = (CmpInst::Predicate)Predicate;
+ assert(CmpInst::isFPPredicate(Pred) && "Not an FP compare!");
+
+ if (Constant *CLHS = dyn_cast<Constant>(LHS))
+ if (Constant *CRHS = dyn_cast<Constant>(RHS))
+ return ConstantFoldCompareInstOperands(Pred, CLHS, CRHS, TD);
+
return 0;
}
+
+
+/// SimplifyCmpInst - Given operands for a CmpInst, see if we can
+/// fold the result.
+Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
+ const TargetData *TD) {
+ if (CmpInst::isIntPredicate((CmpInst::Predicate)Predicate))
+ return SimplifyICmpInst(Predicate, LHS, RHS, TD);
+ return SimplifyFCmpInst(Predicate, LHS, RHS, TD);
+}
+
OpenPOWER on IntegriCloud