@@ -269,6 +269,28 @@ void WasmGCTypeAnalyzer::ProcessAllocateStruct(
269
269
wasm::ValueType::Ref (type_index));
270
270
}
271
271
272
+ wasm::ValueType WasmGCTypeAnalyzer::GetTypeForPhiInput (const PhiOp& phi,
273
+ int input_index) {
274
+ OpIndex phi_id = graph_.Index (phi);
275
+ OpIndex input = ResolveAliases (phi.input (input_index));
276
+ // If the input of the phi is in the same block as the phi and appears
277
+ // before the phi, don't use the predecessor value.
278
+
279
+ if (current_block_->begin ().id () <= input.id () && input.id () < phi_id.id ()) {
280
+ // Phi instructions have to be at the beginning of the block, so this can
281
+ // only happen for inputs that are also phis. Furthermore, this is only
282
+ // possible in loop headers of loops with a single block (endless loops) and
283
+ // only for the backedge-input.
284
+ DCHECK (graph_.Get (input).Is <PhiOp>());
285
+ DCHECK (current_block_->IsLoop ());
286
+ DCHECK (current_block_->HasBackedge (graph_));
287
+ DCHECK_EQ (current_block_->LastPredecessor (), current_block_);
288
+ DCHECK_EQ (input_index, 1 );
289
+ return types_table_.Get (input);
290
+ }
291
+ return types_table_.GetPredecessorValue (input, input_index);
292
+ }
293
+
272
294
void WasmGCTypeAnalyzer::ProcessPhi (const PhiOp& phi) {
273
295
// The result type of a phi is the union of all its input types.
274
296
// If any of the inputs is the default value ValueType(), there isn't any type
@@ -281,12 +303,10 @@ void WasmGCTypeAnalyzer::ProcessPhi(const PhiOp& phi) {
281
303
RefineTypeKnowledge (graph_.Index (phi), GetResolvedType ((phi.input (0 ))));
282
304
return ;
283
305
}
284
- wasm::ValueType union_type =
285
- types_table_.GetPredecessorValue (ResolveAliases (phi.input (0 )), 0 );
306
+ wasm::ValueType union_type = GetTypeForPhiInput (phi, 0 );
286
307
if (union_type == wasm::ValueType ()) return ;
287
308
for (int i = 1 ; i < phi.input_count ; ++i) {
288
- wasm::ValueType input_type =
289
- types_table_.GetPredecessorValue (ResolveAliases (phi.input (i)), i);
309
+ wasm::ValueType input_type = GetTypeForPhiInput (phi, i);
290
310
if (input_type == wasm::ValueType ()) return ;
291
311
// <bottom> types have to be skipped as an unreachable predecessor doesn't
292
312
// change our type knowledge.
0 commit comments