aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-10 01:08:51 +0000
committerChris Lattner <sabre@nondot.org>2009-11-10 01:08:51 +0000
commite34537856a544c83513e390ac9552a8bc3823346 (patch)
tree22c3def24ccc951dc07bb42f4eff7ed067705530 /lib/Analysis/InstructionSimplify.cpp
parent81cf4325698b48b02eddab921ac333c7f25005c3 (diff)
add a new SimplifyInstruction API, which is like ConstantFoldInstruction,
except that the result may not be a constant. Switch jump threading to use it so that it gets things like (X & 0) -> 0, which occur when phi preds are deleted and the remaining phi pred was a zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86637 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--lib/Analysis/InstructionSimplify.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 3c1529ce6d..6953f16dc9 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -291,3 +291,23 @@ Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
return SimplifyFCmpInst(Predicate, LHS, RHS, TD);
}
+
+/// 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) {
+ switch (I->getOpcode()) {
+ default:
+ return ConstantFoldInstruction(I, TD);
+ case Instruction::And:
+ return SimplifyAndInst(I->getOperand(0), I->getOperand(1), TD);
+ case Instruction::Or:
+ return SimplifyOrInst(I->getOperand(0), I->getOperand(1), TD);
+ case Instruction::ICmp:
+ return SimplifyICmpInst(cast<ICmpInst>(I)->getPredicate(),
+ I->getOperand(0), I->getOperand(1), TD);
+ case Instruction::FCmp:
+ return SimplifyFCmpInst(cast<FCmpInst>(I)->getPredicate(),
+ I->getOperand(0), I->getOperand(1), TD);
+ }
+}
+