SimplifyBuiltin: support metatype and function types when optimizing Builtin.sizeof/alignof/strideof/destroyArray

Get the maximally abstracted lowered type instead of bailing if the ast type isn't equal to the lowered SIL type.
This commit is contained in:
Erik Eckstein
2024-12-19 20:25:29 +01:00
parent 4fdf16de1b
commit 89353506f5
2 changed files with 54 additions and 7 deletions

View File

@@ -33,9 +33,8 @@ extension BuiltinInst : OnoneSimplifyable {
.Alignof:
optimizeTargetTypeConst(context)
case .DestroyArray:
if let elementType = substitutionMap.replacementTypes[0].canonical.silType,
elementType.isTrivial(in: parentFunction)
{
let elementType = substitutionMap.replacementType.loweredType(in: parentFunction, maximallyAbstracted: true)
if elementType.isTrivial(in: parentFunction) {
context.erase(instruction: self)
return
}
@@ -161,10 +160,7 @@ private extension BuiltinInst {
}
func optimizeTargetTypeConst(_ context: SimplifyContext) {
guard let ty = substitutionMap.replacementTypes[0].canonical.silType else {
return
}
let ty = substitutionMap.replacementType.loweredType(in: parentFunction, maximallyAbstracted: true)
let value: Int?
switch id {
case .Sizeof: