@@ -347,7 +347,8 @@ static void ir_sccp_remove_insn(ir_ctx *ctx, ir_insn *_values, ir_ref ref, ir_bi
347347 for (j = 1 , p = insn -> ops + j ; j <= n ; j ++ , p ++ ) {
348348 ir_ref input = * p ;
349349 * p = IR_UNUSED ;
350- if (input > 0 && _values [input ].op == IR_BOTTOM ) {
350+ /* we may skip nodes that are going to be removed by SCCP (TOP, CONST and COPY) */
351+ if (input > 0 && _values [input ].op > IR_COPY ) {
351352 ir_use_list_remove_all (ctx , input , ref );
352353 if (ir_is_dead (ctx , input )) {
353354 /* schedule DCE */
@@ -396,13 +397,12 @@ static void ir_sccp_replace_insn(ir_ctx *ctx, ir_insn *_values, ir_ref ref, ir_r
396397 for (j = 1 , p = insn -> ops + 1 ; j <= n ; j ++ , p ++ ) {
397398 ir_ref input = * p ;
398399 * p = IR_UNUSED ;
399- if (input > 0 ) {
400+ /* we may skip nodes that are going to be removed by SCCP (TOP, CONST and COPY) */
401+ if (input > 0 && _values [input ].op > IR_COPY ) {
400402 ir_use_list_remove_all (ctx , input , ref );
401- if (_values [input ].op == IR_BOTTOM ) {
402- if (ir_is_dead (ctx , input )) {
403- /* schedule DCE */
404- ir_bitqueue_add (worklist , input );
405- }
403+ if (ir_is_dead (ctx , input )) {
404+ /* schedule DCE */
405+ ir_bitqueue_add (worklist , input );
406406 }
407407 }
408408 }
@@ -429,8 +429,9 @@ static void ir_sccp_replace_insn(ir_ctx *ctx, ir_insn *_values, ir_ref ref, ir_r
429429 }
430430 }
431431#endif
432- /* schedule folding */
433- if (worklist && _values [use ].op == IR_BOTTOM ) {
432+ /* we may skip nodes that are going to be removed by SCCP (TOP, CONST and COPY) */
433+ if (worklist && _values [use ].op > IR_COPY ) {
434+ /* schedule folding */
434435 ir_bitqueue_add (worklist , use );
435436 }
436437 }
@@ -1067,7 +1068,7 @@ static ir_ref ir_ext_const(ir_ctx *ctx, ir_insn *val_insn, ir_op op, ir_type typ
10671068 return ir_const (ctx , new_val , type );
10681069}
10691070
1070- static ir_ref ir_ext_ref (ir_ctx * ctx , ir_ref var_ref , ir_ref src_ref , ir_op op , ir_type type )
1071+ static ir_ref ir_ext_ref (ir_ctx * ctx , ir_ref var_ref , ir_ref src_ref , ir_op op , ir_type type , ir_bitqueue * worklist )
10711072{
10721073 uint32_t optx = IR_OPTX (op , type , 1 );
10731074 ir_ref ref ;
@@ -1079,6 +1080,7 @@ static ir_ref ir_ext_ref(ir_ctx *ctx, ir_ref var_ref, ir_ref src_ref, ir_op op,
10791080 if (!IR_IS_CONST_REF (src_ref )) {
10801081 ir_use_list_remove_one (ctx , src_ref , var_ref );
10811082 }
1083+ ir_bitqueue_add (worklist , ref );
10821084 return ref ;
10831085 }
10841086 }
@@ -1091,6 +1093,8 @@ static ir_ref ir_ext_ref(ir_ctx *ctx, ir_ref var_ref, ir_ref src_ref, ir_op op,
10911093 if (!IR_IS_CONST_REF (src_ref )) {
10921094 ir_use_list_replace_one (ctx , src_ref , var_ref , ref );
10931095 }
1096+ ir_bitqueue_grow (worklist , ref + 1 );
1097+ ir_bitqueue_add (worklist , ref );
10941098 return ref ;
10951099}
10961100
@@ -1162,17 +1166,15 @@ static bool ir_try_promote_ext(ir_ctx *ctx, ir_ref ext_ref, ir_insn *insn, ir_bi
11621166 && !IR_IS_SYM_CONST (ctx -> ir_base [use_insn -> op1 ].op )) {
11631167 ctx -> ir_base [use ].op1 = ir_ext_const (ctx , & ctx -> ir_base [use_insn -> op1 ], op , type );
11641168 } else {
1165- ctx -> ir_base [use ].op1 = ir_ext_ref (ctx , use , use_insn -> op1 , op , type );
1166- ir_bitqueue_add (worklist , ctx -> ir_base [use ].op1 );
1169+ ctx -> ir_base [use ].op1 = ir_ext_ref (ctx , use , use_insn -> op1 , op , type , worklist );
11671170 }
11681171 }
11691172 if (use_insn -> op2 != ref ) {
11701173 if (IR_IS_CONST_REF (use_insn -> op2 )
11711174 && !IR_IS_SYM_CONST (ctx -> ir_base [use_insn -> op2 ].op )) {
11721175 ctx -> ir_base [use ].op2 = ir_ext_const (ctx , & ctx -> ir_base [use_insn -> op2 ], op , type );
11731176 } else {
1174- ctx -> ir_base [use ].op2 = ir_ext_ref (ctx , use , use_insn -> op2 , op , type );
1175- ir_bitqueue_add (worklist , ctx -> ir_base [use ].op2 );
1177+ ctx -> ir_base [use ].op2 = ir_ext_ref (ctx , use , use_insn -> op2 , op , type , worklist );
11761178 }
11771179 }
11781180 }
@@ -1185,8 +1187,7 @@ static bool ir_try_promote_ext(ir_ctx *ctx, ir_ref ext_ref, ir_insn *insn, ir_bi
11851187 && !IR_IS_SYM_CONST (ctx -> ir_base [phi_insn -> op2 ].op )) {
11861188 ctx -> ir_base [ref ].op2 = ir_ext_const (ctx , & ctx -> ir_base [phi_insn -> op2 ], op , type );
11871189 } else {
1188- ctx -> ir_base [ref ].op2 = ir_ext_ref (ctx , ref , phi_insn -> op2 , op , type );
1189- ir_bitqueue_add (worklist , ctx -> ir_base [ref ].op2 );
1190+ ctx -> ir_base [ref ].op2 = ir_ext_ref (ctx , ref , phi_insn -> op2 , op , type , worklist );
11901191 }
11911192
11921193 return 1 ;
0 commit comments