summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2011-09-05 06:52:48 +0000
committerDuncan Sands <baldrick@free.fr>2011-09-05 06:52:48 +0000
commitfd26a954a8e87ae58838da691e49b1c629252cef (patch)
tree7e3666b391e6b9730ec013521dc1cba610a5b795 /llvm/lib/Analysis/InstructionSimplify.cpp
parent58b3749d6cdbc3de390a3ee280a3065e7b4fa9b1 (diff)
downloadbcm5719-llvm-fd26a954a8e87ae58838da691e49b1c629252cef.tar.gz
bcm5719-llvm-fd26a954a8e87ae58838da691e49b1c629252cef.zip
Add some simple insertvalue simplifications, for the purpose of cleaning
up do-nothing exception handling code produced by dragonegg. llvm-svn: 139113
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index cfff9c03c83..deb7fed18b3 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2270,6 +2270,35 @@ Value *llvm::SimplifyGEPInst(ArrayRef<Value *> Ops,
return ConstantExpr::getGetElementPtr(cast<Constant>(Ops[0]), Ops.slice(1));
}
+/// SimplifyInsertValueInst - Given operands for an InsertValueInst, see if we
+/// can fold the result. If not, this returns null.
+Value *llvm::SimplifyInsertValueInst(Value *Agg, Value *Val,
+ ArrayRef<unsigned> Idxs,
+ const TargetData *,
+ const DominatorTree *) {
+ if (Constant *CAgg = dyn_cast<Constant>(Agg))
+ if (Constant *CVal = dyn_cast<Constant>(Val))
+ return ConstantFoldInsertValueInstruction(CAgg, CVal, Idxs);
+
+ // insertvalue x, undef, n -> x
+ if (match(Val, m_Undef()))
+ return Agg;
+
+ // insertvalue x, (extractvalue y, n), n
+ if (ExtractValueInst *EV = dyn_cast<ExtractValueInst>(Val))
+ if (EV->getIndices() == Idxs) {
+ // insertvalue undef, (extractvalue y, n), n -> y
+ if (match(Agg, m_Undef()))
+ return EV->getAggregateOperand();
+
+ // insertvalue y, (extractvalue y, n), n -> y
+ if (Agg == EV->getAggregateOperand())
+ return Agg;
+ }
+
+ return 0;
+}
+
/// SimplifyPHINode - See if we can fold the given phi. If not, returns null.
static Value *SimplifyPHINode(PHINode *PN, const DominatorTree *DT) {
// If all of the PHI's incoming values are the same then replace the PHI node
@@ -2471,6 +2500,13 @@ Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD,
Result = SimplifyGEPInst(Ops, TD, DT);
break;
}
+ case Instruction::InsertValue: {
+ InsertValueInst *IV = cast<InsertValueInst>(I);
+ Result = SimplifyInsertValueInst(IV->getAggregateOperand(),
+ IV->getInsertedValueOperand(),
+ IV->getIndices(), TD, DT);
+ break;
+ }
case Instruction::PHI:
Result = SimplifyPHINode(cast<PHINode>(I), DT);
break;
OpenPOWER on IntegriCloud