File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change 103
103
'stack_switching_switch.wast' ,
104
104
# TODO: fuzzer support for exact references
105
105
'exact-references.wast' ,
106
+ 'optimize-instructions-exact.wast' ,
106
107
]
107
108
108
109
Original file line number Diff line number Diff line change @@ -2346,18 +2346,20 @@ struct OptimizeInstructions
2346
2346
}
2347
2347
[[fallthrough]];
2348
2348
case GCTypeUtils::SuccessOnlyIfNull: {
2349
- auto nullType = Type (curr->type .getHeapType ().getBottom (), Nullable);
2350
2349
// The cast either returns null or traps. In trapsNeverHappen mode
2351
2350
// we know the result, since by assumption it will not trap.
2352
2351
if (getPassOptions ().trapsNeverHappen ) {
2353
- replaceCurrent (builder.makeBlock (
2354
- {builder.makeDrop (curr->ref ), builder.makeRefNull (nullType)},
2355
- curr->type ));
2352
+ replaceCurrent (
2353
+ builder.makeBlock ({builder.makeDrop (curr->ref ),
2354
+ builder.makeRefNull (curr->type .getHeapType ())},
2355
+ curr->type ));
2356
2356
return ;
2357
2357
}
2358
2358
// Otherwise, we should have already refined the cast type to cast
2359
- // directly to null.
2360
- assert (curr->type == nullType);
2359
+ // directly to null. We do not further refine the cast type to exact
2360
+ // null because the extra precision is not useful and doing so would
2361
+ // increase the size of the instruction encoding.
2362
+ assert (curr->type .isNull ());
2361
2363
break ;
2362
2364
}
2363
2365
case GCTypeUtils::Unreachable:
Original file line number Diff line number Diff line change
1
+ ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2
+
3
+ ;; Check that optimizations on casts involving exact reference types work
4
+ ;; correctly.
5
+
6
+ ;; RUN: wasm-opt %s -all --optimize-instructions -S -o - | filecheck %s
7
+
8
+ (module
9
+ ;; CHECK: (func $cast-to-exact-none (type $0) (param $0 anyref)
10
+ ;; CHECK-NEXT: (drop
11
+ ;; CHECK-NEXT: (ref.cast (exact nullref)
12
+ ;; CHECK-NEXT: (local.get $0)
13
+ ;; CHECK-NEXT: )
14
+ ;; CHECK-NEXT: )
15
+ ;; CHECK-NEXT: )
16
+ (func $cast-to-exact-none (param anyref )
17
+ (drop
18
+ ;; This will not be changed, but should not trigger an assertion.
19
+ (ref.cast (exact nullref)
20
+ (local.get 0 )
21
+ )
22
+ )
23
+ )
24
+ )
You can’t perform that action at this time.
0 commit comments