File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -317,6 +317,35 @@ bool redundant_move_elim(ph2_ir_t *ph2_ir)
317317 return true;
318318 }
319319
320+ /* Pattern 6: Move followed by load (reverse pattern suggested by fennecJ)
321+ * {mov rd, rs; load rd, offset} → {load rd, offset}
322+ * The move is pointless if immediately overwritten by load
323+ */
324+ if (ph2_ir -> op == OP_assign &&
325+ (next -> op == OP_load || next -> op == OP_global_load ) &&
326+ ph2_ir -> dest == next -> dest ) {
327+ /* Replace move+load with just the load */
328+ ph2_ir -> op = next -> op ;
329+ ph2_ir -> src0 = next -> src0 ;
330+ ph2_ir -> src1 = next -> src1 ;
331+ ph2_ir -> next = next -> next ;
332+ return true;
333+ }
334+
335+ /* Pattern 7: Move followed by constant load (reverse pattern suggested by fennecJ)
336+ * {mov rd, rs; li rd, imm} → {li rd, imm}
337+ * The move is pointless if immediately overwritten by constant
338+ */
339+ if (ph2_ir -> op == OP_assign && next -> op == OP_load_constant &&
340+ ph2_ir -> dest == next -> dest ) {
341+ /* Replace move+li with just the li */
342+ ph2_ir -> op = OP_load_constant ;
343+ ph2_ir -> src0 = next -> src0 ;
344+ ph2_ir -> src1 = 0 ; /* Clear unused field */
345+ ph2_ir -> next = next -> next ;
346+ return true;
347+ }
348+
320349 return false;
321350}
322351
You can’t perform that action at this time.
0 commit comments