teach silcombine to merge upcast instructions that feed each other, now that

sema is emitting each step of a conversion independently.  Also, as a driveby,
fix an optimizer crash in the "(ref_to_raw_pointer (ref_to_object_pointer x)) 
to (ref_to_raw_pointer x)" peephole when the ref_to_object_pointer had other
uses (noticed by inspection).



Swift SVN r14603
This commit is contained in:
Chris Lattner
2014-03-03 18:52:05 +00:00
parent b3cbbb6c4e
commit dfc39abd3e
2 changed files with 31 additions and 2 deletions

View File

@@ -261,6 +261,7 @@ public:
SILInstruction *visitCondFailInst(CondFailInst *CFI);
SILInstruction *visitStrongRetainInst(StrongRetainInst *SRI);
SILInstruction *visitRefToRawPointerInst(RefToRawPointerInst *RRPI);
SILInstruction *visitUpcastInst(UpcastInst *UCI);
SILInstruction *visitLoadInst(LoadInst *LI);
private:
@@ -443,6 +444,7 @@ bool SILCombiner::doOneIteration(SILFunction &F, unsigned Iteration) {
// Visitors
//===----------------------------------------------------------------------===//
SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
// Given a load with multiple struct_extracts/tuple_extracts and no other
// uses, canonicalize the load into several (struct_element_addr (load))
@@ -701,14 +703,26 @@ SILCombiner::visitRefToRawPointerInst(RefToRawPointerInst *RRPI) {
//
// (ref_to_raw_pointer (ref_to_object_pointer x))
// -> (ref_to_raw_pointer x)
if (auto *ROPI = dyn_cast<RefToObjectPointerInst>(&*RRPI->getOperand())) {
if (auto *ROPI = dyn_cast<RefToObjectPointerInst>(RRPI->getOperand())) {
RRPI->setOperand(ROPI->getOperand());
return eraseInstFromFunction(*ROPI);
return ROPI->use_empty() ? eraseInstFromFunction(*ROPI) : nullptr;
}
return nullptr;
}
SILInstruction *SILCombiner::visitUpcastInst(UpcastInst *UCI) {
// Ref to raw pointer consumption of other ref casts.
//
// (upcast (upcast x)) -> (upcast x)
if (auto *Op = dyn_cast<UpcastInst>(UCI->getOperand())) {
UCI->setOperand(Op->getOperand());
return Op->use_empty() ? eraseInstFromFunction(*Op) : nullptr;
}
return nullptr;
}
class SILCombine : public SILFunctionTransform {
/// The entry point to the transformation.