@@ -974,7 +974,7 @@ ir_ref ir_folding(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3,
974974 } while (1 );
975975
976976ir_fold_restart :
977- if (!( ctx -> flags2 & IR_OPT_IN_SCCP ) ) {
977+ if (!ctx -> use_lists ) {
978978 op1_insn = ctx -> ir_base + op1 ;
979979 op2_insn = ctx -> ir_base + op2 ;
980980 op3_insn = ctx -> ir_base + op3 ;
@@ -987,7 +987,7 @@ ir_ref ir_folding(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3,
987987 return IR_FOLD_DO_RESTART ;
988988 }
989989ir_fold_cse :
990- if (!( ctx -> flags2 & IR_OPT_IN_SCCP ) ) {
990+ if (!ctx -> use_lists ) {
991991 /* Local CSE */
992992 ref = _ir_fold_cse (ctx , opt , op1 , op2 , op3 );
993993 if (ref ) {
@@ -1017,7 +1017,7 @@ ir_ref ir_folding(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3,
10171017 return IR_FOLD_DO_CSE ;
10181018 }
10191019ir_fold_emit :
1020- if (!( ctx -> flags2 & IR_OPT_IN_SCCP ) ) {
1020+ if (!ctx -> use_lists ) {
10211021 return ir_emit (ctx , opt , op1 , op2 , op3 );
10221022 } else {
10231023 ctx -> fold_insn .optx = opt ;
@@ -1027,14 +1027,14 @@ ir_ref ir_folding(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3,
10271027 return IR_FOLD_DO_EMIT ;
10281028 }
10291029ir_fold_copy :
1030- if (!( ctx -> flags2 & IR_OPT_IN_SCCP ) ) {
1030+ if (!ctx -> use_lists ) {
10311031 return ref ;
10321032 } else {
10331033 ctx -> fold_insn .op1 = ref ;
10341034 return IR_FOLD_DO_COPY ;
10351035 }
10361036ir_fold_const :
1037- if (!( ctx -> flags2 & IR_OPT_IN_SCCP ) ) {
1037+ if (!ctx -> use_lists ) {
10381038 return ir_const (ctx , val , IR_OPT_TYPE (opt ));
10391039 } else {
10401040 ctx -> fold_insn .opt = IR_OPT (IR_OPT_TYPE (opt ), IR_OPT_TYPE (opt ));
@@ -2015,7 +2015,7 @@ ir_alias ir_check_partial_aliasing(const ir_ctx *ctx, ir_ref addr1, ir_ref addr2
20152015 return IR_MAY_ALIAS ;
20162016}
20172017
2018- IR_ALWAYS_INLINE ir_ref ir_find_aliasing_load_i (ir_ctx * ctx , ir_ref ref , ir_type type , ir_ref addr , ir_ref limit , bool allow_casting )
2018+ IR_ALWAYS_INLINE ir_ref ir_find_aliasing_load_i (ir_ctx * ctx , ir_ref ref , ir_type type , ir_ref addr , ir_ref limit )
20192019{
20202020 ir_insn * insn ;
20212021 uint32_t modified_regset = 0 ;
@@ -2026,13 +2026,11 @@ IR_ALWAYS_INLINE ir_ref ir_find_aliasing_load_i(ir_ctx *ctx, ir_ref ref, ir_type
20262026 if (insn -> op2 == addr ) {
20272027 if (insn -> type == type ) {
20282028 return ref ; /* load forwarding (L2L) */
2029- } else if (!allow_casting ) {
2030- /* pass */
20312029 } else if (ir_type_size [insn -> type ] == ir_type_size [type ]) {
2032- return ir_fold1 ( ctx , IR_OPT ( IR_BITCAST , type ), ref ) ; /* load forwarding with bitcast (L2L) */
2030+ return ref ; /* load forwarding with bitcast (L2L) */
20332031 } else if (ir_type_size [insn -> type ] > ir_type_size [type ]
20342032 && IR_IS_TYPE_INT (type ) && IR_IS_TYPE_INT (insn -> type )) {
2035- return ir_fold1 ( ctx , IR_OPT ( IR_TRUNC , type ), ref ) ; /* partial load forwarding (L2L) */
2033+ return ref ; /* partial load forwarding (L2L) */
20362034 }
20372035 }
20382036 } else if (insn -> op == IR_STORE ) {
@@ -2045,13 +2043,11 @@ IR_ALWAYS_INLINE ir_ref ir_find_aliasing_load_i(ir_ctx *ctx, ir_ref ref, ir_type
20452043 return IR_UNUSED ;
20462044 } else if (type2 == type ) {
20472045 return insn -> op3 ; /* store forwarding (S2L) */
2048- } else if (!allow_casting ) {
2049- return IR_UNUSED ;
20502046 } else if (ir_type_size [type2 ] == ir_type_size [type ]) {
2051- return ir_fold1 ( ctx , IR_OPT ( IR_BITCAST , type ), insn -> op3 ) ; /* store forwarding with bitcast (S2L) */
2047+ return insn -> op3 ; /* store forwarding with bitcast (S2L) */
20522048 } else if (ir_type_size [type2 ] > ir_type_size [type ]
20532049 && IR_IS_TYPE_INT (type ) && IR_IS_TYPE_INT (type2 )) {
2054- return ir_fold1 ( ctx , IR_OPT ( IR_TRUNC , type ), insn -> op3 ) ; /* partial store forwarding (S2L) */
2050+ return insn -> op3 ; /* partial store forwarding (S2L) */
20552051 } else {
20562052 return IR_UNUSED ;
20572053 }
@@ -2071,10 +2067,10 @@ IR_ALWAYS_INLINE ir_ref ir_find_aliasing_load_i(ir_ctx *ctx, ir_ref ref, ir_type
20712067
20722068ir_ref ir_find_aliasing_load (ir_ctx * ctx , ir_ref ref , ir_type type , ir_ref addr )
20732069{
2074- return ir_find_aliasing_load_i (ctx , ref , type , addr , (addr > 0 && addr < ref ) ? addr : 1 , 0 );
2070+ return ir_find_aliasing_load_i (ctx , ref , type , addr , (addr > 0 && addr < ref ) ? addr : 1 );
20752071}
20762072
2077- IR_ALWAYS_INLINE ir_ref ir_find_aliasing_vload_i (ir_ctx * ctx , ir_ref ref , ir_type type , ir_ref var , bool allow_casting )
2073+ IR_ALWAYS_INLINE ir_ref ir_find_aliasing_vload_i (ir_ctx * ctx , ir_ref ref , ir_type type , ir_ref var )
20782074{
20792075 ir_insn * insn ;
20802076
@@ -2084,8 +2080,6 @@ IR_ALWAYS_INLINE ir_ref ir_find_aliasing_vload_i(ir_ctx *ctx, ir_ref ref, ir_typ
20842080 if (insn -> op2 == var ) {
20852081 if (insn -> type == type ) {
20862082 return ref ; /* load forwarding (L2L) */
2087- } else if (!allow_casting ) {
2088- /* pass */ ;
20892083 } else if (ir_type_size [insn -> type ] == ir_type_size [type ]) {
20902084 return ir_fold1 (ctx , IR_OPT (IR_BITCAST , type ), ref ); /* load forwarding with bitcast (L2L) */
20912085 } else if (ir_type_size [insn -> type ] > ir_type_size [type ]
@@ -2099,8 +2093,6 @@ IR_ALWAYS_INLINE ir_ref ir_find_aliasing_vload_i(ir_ctx *ctx, ir_ref ref, ir_typ
20992093 if (insn -> op2 == var ) {
21002094 if (type2 == type ) {
21012095 return insn -> op3 ; /* store forwarding (S2L) */
2102- } else if (!allow_casting ) {
2103- break ;
21042096 } else if (ir_type_size [type2 ] == ir_type_size [type ]) {
21052097 return ir_fold1 (ctx , IR_OPT (IR_BITCAST , type ), insn -> op3 ); /* store forwarding with bitcast (S2L) */
21062098 } else if (ir_type_size [type2 ] > ir_type_size [type ]
@@ -2121,7 +2113,7 @@ IR_ALWAYS_INLINE ir_ref ir_find_aliasing_vload_i(ir_ctx *ctx, ir_ref ref, ir_typ
21212113
21222114ir_ref ir_find_aliasing_vload (ir_ctx * ctx , ir_ref ref , ir_type type , ir_ref var )
21232115{
2124- return ir_find_aliasing_vload_i (ctx , ref , type , var , 0 );
2116+ return ir_find_aliasing_vload_i (ctx , ref , type , var );
21252117}
21262118
21272119IR_ALWAYS_INLINE ir_ref ir_find_aliasing_store_i (ir_ctx * ctx , ir_ref ref , ir_ref addr , ir_ref val , ir_ref limit )
@@ -3120,16 +3112,23 @@ void _ir_AFREE(ir_ctx *ctx, ir_ref size)
31203112
31213113ir_ref _ir_VLOAD (ir_ctx * ctx , ir_type type , ir_ref var )
31223114{
3123- ir_ref ref = IR_UNUSED ;
3115+ ir_ref ref ;
31243116
31253117 IR_ASSERT (ctx -> control );
31263118 if (EXPECTED (ctx -> flags & IR_OPT_FOLDING )) {
3127- ref = ir_find_aliasing_vload_i (ctx , ctx -> control , type , var , 1 );
3128- }
3129- if (!ref ) {
3130- ctx -> control = ref = ir_emit2 (ctx , IR_OPT (IR_VLOAD , type ), ctx -> control , var );
3119+ ref = ir_find_aliasing_vload_i (ctx , ctx -> control , type , var );
3120+ if (ref ) {
3121+ ir_insn * insn = & ctx -> ir_base [ref ];
3122+ if (insn -> type == type ) {
3123+ return ref ;
3124+ } else if (ir_type_size [insn -> type ] == ir_type_size [type ]) {
3125+ return ir_fold1 (ctx , IR_OPT (IR_BITCAST , type ), ref ); /* load forwarding with bitcast (L2L) */
3126+ } else {
3127+ return ir_fold1 (ctx , IR_OPT (IR_TRUNC , type ), ref ); /* partial load forwarding (L2L) */
3128+ }
3129+ }
31313130 }
3132- return ref ;
3131+ return ctx -> control = ir_emit2 ( ctx , IR_OPT ( IR_VLOAD , type ), ctx -> control , var ) ;
31333132}
31343133
31353134void _ir_VSTORE (ir_ctx * ctx , ir_ref var , ir_ref val )
@@ -3164,22 +3163,36 @@ void _ir_RSTORE(ir_ctx *ctx, ir_ref reg, ir_ref val)
31643163
31653164ir_ref _ir_LOAD (ir_ctx * ctx , ir_type type , ir_ref addr )
31663165{
3167- ir_ref ref = IR_UNUSED ;
3166+ ir_ref ref ;
31683167
31693168 IR_ASSERT (ctx -> control );
31703169 if (EXPECTED (ctx -> flags & IR_OPT_FOLDING )) {
3171- ref = ir_find_aliasing_load_i (ctx , ctx -> control , type , addr , (addr > 0 ) ? addr : 1 , 1 );
3172- }
3173- if (!ref ) {
3174- ctx -> control = ref = ir_emit2 (ctx , IR_OPT (IR_LOAD , type ), ctx -> control , addr );
3170+ if (ctx -> ir_base [addr ].op == IR_VADDR ) {
3171+ return _ir_VLOAD (ctx , type , ctx -> ir_base [addr ].op1 );
3172+ }
3173+ ref = ir_find_aliasing_load_i (ctx , ctx -> control , type , addr , (addr > 0 ) ? addr : 1 );
3174+ if (ref ) {
3175+ ir_insn * insn = & ctx -> ir_base [ref ];
3176+ if (insn -> type == type ) {
3177+ return ref ;
3178+ } else if (ir_type_size [insn -> type ] == ir_type_size [type ]) {
3179+ return ir_fold1 (ctx , IR_OPT (IR_BITCAST , type ), ref ); /* load forwarding with bitcast (L2L) */
3180+ } else {
3181+ return ir_fold1 (ctx , IR_OPT (IR_TRUNC , type ), ref ); /* partial load forwarding (L2L) */
3182+ }
3183+ }
31753184 }
3176- return ref ;
3185+ return ctx -> control = ir_emit2 ( ctx , IR_OPT ( IR_LOAD , type ), ctx -> control , addr ) ;
31773186}
31783187
31793188void _ir_STORE (ir_ctx * ctx , ir_ref addr , ir_ref val )
31803189{
31813190 IR_ASSERT (ctx -> control );
31823191 if (EXPECTED (ctx -> flags & IR_OPT_FOLDING )) {
3192+ if (ctx -> ir_base [addr ].op == IR_VADDR ) {
3193+ _ir_VSTORE (ctx , ctx -> ir_base [addr ].op1 , val );
3194+ return ;
3195+ }
31833196 if (ir_find_aliasing_store_i (ctx , ctx -> control , addr , val , (addr > 0 ) ? addr : 1 )) {
31843197 /* dead STORE */
31853198 return ;
0 commit comments