Skip to content

Commit

Permalink
Merge pull request #34375 from eeckstein/fix-metadat-combine
Browse files Browse the repository at this point in the history
SILCombine: fix metatype simplification
  • Loading branch information
eeckstein committed Oct 21, 2020
2 parents ce90767 + c6be347 commit 0d6e79c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/SILOptimizer/Analysis/SimplifyInstruction.cpp
Expand Up @@ -488,7 +488,8 @@ SILValue InstSimplifier::visitMetatypeInst(MetatypeInst *MI) {
|| instanceType.getStructOrBoundGenericStruct()
|| instanceType.getEnumOrBoundGenericEnum()) {
for (SILArgument *argument : MI->getFunction()->getArguments()) {
if (argument->getType().getASTType() == metaType)
if (argument->getType().getASTType() == metaType &&
argument->getType().isObject())
return argument;
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/SILOptimizer/sil_simplify_instrs.sil
Expand Up @@ -371,3 +371,16 @@ bb0(%0 : $@thick SpecialEnum.Type):
%5 = struct $Bool (%4 : $Builtin.Int1)
return %5 : $Bool
}

// CHECK-LABEL: sil @dontSimplifyIndirectMetatype : $@convention(thin) () -> @out @thick Int.Type {
// CHECK: [[MT:%[0-9]+]] = metatype $@thick Int.Type
// CHECK: store [[MT]] to %0
// CHECK-LABEL: } // end sil function 'dontSimplifyIndirectMetatype'
sil @dontSimplifyIndirectMetatype : $@convention(thin) () -> @out @thick Int.Type {
bb0(%0 : $*@thick Int.Type):
%1 = metatype $@thick Int.Type
store %1 to %0 : $*@thick Int.Type
%3 = tuple ()
return %3 : $()
}

0 comments on commit 0d6e79c

Please sign in to comment.