summaryrefslogtreecommitdiff
path: root/src/passes/GUFA.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/GUFA.cpp')
-rw-r--r--src/passes/GUFA.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/passes/GUFA.cpp b/src/passes/GUFA.cpp
index 137ffda17..8f58eaf8a 100644
--- a/src/passes/GUFA.cpp
+++ b/src/passes/GUFA.cpp
@@ -255,6 +255,25 @@ struct GUFAOptimizer
}
}
+ void visitRefCast(RefCast* curr) {
+ auto currType = curr->type;
+ auto inferredType = getContents(curr).getType();
+ if (inferredType.isRef() && inferredType != currType &&
+ Type::isSubType(inferredType, currType)) {
+ // We have inferred that this will only contain something of a more
+ // refined type, so we might as well cast to that more refined type.
+ //
+ // Note that we could in principle apply this in all expressions by adding
+ // a cast. However, to be careful with code size, we only refine existing
+ // casts for now.
+ curr->type = inferredType;
+ }
+
+ // Apply the usual optimizations as well, such as potentially replacing this
+ // with a constant.
+ visitExpression(curr);
+ }
+
// TODO: If an instruction would trap on null, like struct.get, we could
// remove it here if it has no possible contents and if we are in
// traps-never-happen mode (that is, we'd have proven it can only trap,