DynamicCasts: Emit a direct copy if soure and target SIL types match

unconditional_checked_cast_addr ImplicitlyUnwrappedOptional<AnyObject> in %136 : *Optional<AnyObject> to *Optional<AnyObject> in %135

rdar://35987160
This commit is contained in:
Arnold Schwaighofer
2017-12-18 14:28:07 -08:00
parent ed58c152bf
commit e0ce894fd0
2 changed files with 22 additions and 2 deletions

View File

@@ -737,6 +737,8 @@ namespace {
bool isAddress() const { return Value->getType().isAddress(); }
SILType getSILType() const { return Value->getType(); }
Source() = default;
Source(SILValue value, CanType formalType)
: Value(value), FormalType(formalType) {}
@@ -758,6 +760,12 @@ namespace {
assert(!value->getType().isAddress());
return { value, FormalType };
}
SILType getSILType() const {
if (isAddress())
return Address->getType();
else
return LoweredType;
}
Target() = default;
Target(SILValue address, CanType formalType)
@@ -813,7 +821,8 @@ namespace {
}
Source emitSameType(Source source, Target target) {
assert(source.FormalType == target.FormalType);
assert(source.FormalType == target.FormalType ||
source.getSILType() == target.getSILType());
auto &srcTL = getTypeLowering(source.Value->getType());
@@ -845,7 +854,8 @@ namespace {
}
Source emit(Source source, Target target) {
if (source.FormalType == target.FormalType)
if (source.FormalType == target.FormalType ||
source.getSILType() == target.getSILType())
return emitSameType(source, target);
// Handle subtype conversions involving optionals.