@@ -1860,22 +1860,30 @@ static ir_ref ir_find_aliasing_load(ir_ctx *ctx, ir_ref ref, ir_type type, ir_re
1860
1860
while (ref > limit ) {
1861
1861
insn = & ctx -> ir_base [ref ];
1862
1862
if (insn -> op == IR_LOAD ) {
1863
- if (insn -> type == type && insn -> op2 == addr ) {
1864
- return ref ; /* load forwarding (L2L) */
1863
+ if (insn -> op2 == addr ) {
1864
+ if (insn -> type == type ) {
1865
+ return ref ; /* load forwarding (L2L) */
1866
+ } else if (ir_type_size [insn -> type ] == ir_type_size [type ]) {
1867
+ return ir_fold1 (ctx , IR_OPT (IR_BITCAST , type ), ref ); /* load forwarding with bitcast (L2L) */
1868
+ } else if (ir_type_size [insn -> type ] > ir_type_size [type ]
1869
+ && IR_IS_TYPE_INT (type ) && IR_IS_TYPE_INT (insn -> type )) {
1870
+ return ir_fold1 (ctx , IR_OPT (IR_TRUNC , type ), ref ); /* partial load forwarding (L2L) */
1871
+ }
1865
1872
}
1866
1873
} else if (insn -> op == IR_STORE ) {
1867
1874
ir_type type2 = ctx -> ir_base [insn -> op3 ].type ;
1868
1875
1869
1876
if (insn -> op2 == addr ) {
1870
- if (type2 == type ) {
1871
- ref = insn -> op3 ;
1872
- insn = & ctx -> ir_base [ref ];
1873
- if (insn -> op == IR_RLOAD && (modified_regset & (1 << insn -> op2 ))) {
1874
- /* anti-dependency */
1875
- return IR_UNUSED ;
1876
- }
1877
- return ref ; /* store forwarding (S2L) */
1878
- } else if (IR_IS_TYPE_INT (type ) && ir_type_size [type2 ] > ir_type_size [type ]) {
1877
+ if (ctx -> ir_base [insn -> op3 ].op == IR_RLOAD
1878
+ && (modified_regset & (1 << ctx -> ir_base [insn -> op3 ].op2 ))) {
1879
+ /* anti-dependency */
1880
+ return IR_UNUSED ;
1881
+ } else if (type2 == type ) {
1882
+ return insn -> op3 ; /* store forwarding (S2L) */
1883
+ } else if (ir_type_size [type2 ] == ir_type_size [type ]) {
1884
+ return ir_fold1 (ctx , IR_OPT (IR_BITCAST , type ), insn -> op3 ); /* store forwarding with bitcast (S2L) */
1885
+ } else if (ir_type_size [type2 ] > ir_type_size [type ]
1886
+ && IR_IS_TYPE_INT (type ) && IR_IS_TYPE_INT (type2 )) {
1879
1887
return ir_fold1 (ctx , IR_OPT (IR_TRUNC , type ), insn -> op3 ); /* partial store forwarding (S2L) */
1880
1888
} else {
1881
1889
return IR_UNUSED ;
@@ -2664,6 +2672,43 @@ void _ir_AFREE(ir_ctx *ctx, ir_ref size)
2664
2672
2665
2673
ir_ref _ir_VLOAD (ir_ctx * ctx , ir_type type , ir_ref var )
2666
2674
{
2675
+ ir_ref ref = ctx -> control ;
2676
+ ir_insn * insn ;
2677
+
2678
+ while (ref > var ) {
2679
+ insn = & ctx -> ir_base [ref ];
2680
+ if (insn -> op == IR_VLOAD ) {
2681
+ if (insn -> op2 == var ) {
2682
+ if (insn -> type == type ) {
2683
+ return ref ; /* load forwarding (L2L) */
2684
+ } else if (ir_type_size [insn -> type ] == ir_type_size [type ]) {
2685
+ return ir_fold1 (ctx , IR_OPT (IR_BITCAST , type ), ref ); /* load forwarding with bitcast (L2L) */
2686
+ } else if (ir_type_size [insn -> type ] > ir_type_size [type ]
2687
+ && IR_IS_TYPE_INT (type ) && IR_IS_TYPE_INT (insn -> type )) {
2688
+ return ir_fold1 (ctx , IR_OPT (IR_TRUNC , type ), ref ); /* partial load forwarding (L2L) */
2689
+ }
2690
+ }
2691
+ } else if (insn -> op == IR_VSTORE ) {
2692
+ ir_type type2 = ctx -> ir_base [insn -> op3 ].type ;
2693
+
2694
+ if (insn -> op2 == var ) {
2695
+ if (type2 == type ) {
2696
+ return insn -> op3 ; /* store forwarding (S2L) */
2697
+ } else if (ir_type_size [type2 ] == ir_type_size [type ]) {
2698
+ return ir_fold1 (ctx , IR_OPT (IR_BITCAST , type ), insn -> op3 ); /* store forwarding with bitcast (S2L) */
2699
+ } else if (ir_type_size [type2 ] > ir_type_size [type ]
2700
+ && IR_IS_TYPE_INT (type ) && IR_IS_TYPE_INT (type2 )) {
2701
+ return ir_fold1 (ctx , IR_OPT (IR_TRUNC , type ), insn -> op3 ); /* partial store forwarding (S2L) */
2702
+ } else {
2703
+ break ;
2704
+ }
2705
+ }
2706
+ } else if (insn -> op == IR_MERGE || insn -> op == IR_LOOP_BEGIN || insn -> op == IR_CALL || insn -> op == IR_STORE ) {
2707
+ break ;
2708
+ }
2709
+ ref = insn -> op1 ;
2710
+ }
2711
+
2667
2712
IR_ASSERT (ctx -> control );
2668
2713
return ctx -> control = ir_emit2 (ctx , IR_OPT (IR_VLOAD , type ), ctx -> control , var );
2669
2714
}
0 commit comments