diff options
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 6b2a5a1cd..c2142fe6c 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1595,6 +1595,21 @@ struct OptimizeInstructions } } + // A nullable cast can be turned into a non-nullable one: + // + // (struct.get ;; or something else that traps on a null ref + // (ref.cast null + // => + // (struct.get + // (ref.cast ;; now non-nullable + // + // Either way we trap here, but refining the type may have benefits later. + if (ref->type.isNullable()) { + if (auto* cast = ref->dynCast<RefCast>()) { + cast->type = Type(cast->type.getHeapType(), NonNullable); + } + } + auto fallthrough = Properties::getFallthrough(ref, getPassOptions(), *getModule()); |