Skip to content

Commit 1c1a2f3

Browse files
committed
Added more GETBYTE optimizations
1 parent 14de0a5 commit 1c1a2f3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Version 6.7.2
22
- Added putchar to libc.a
3+
- Added another optimization for more AND x, #255 cases.
34

45
Version 6.7.1
56
- Added a memory read optimization in -O2, courtesy of Ada

backends/asm/optimize_ir.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6067,7 +6067,6 @@ static PeepholePattern pat_movadd[] = {
60676067
{ 0, 0, 0, 0, PEEP_FLAGS_DONE }
60686068
};
60696069

6070-
60716070
// replace mov x, #2; shl x, y; sub x, #1 with bmask x, y
60726071
static PeepholePattern pat_bmask1[] = {
60736072
{ COND_ANY, OPC_MOV, PEEP_OP_SET|0, PEEP_OP_IMM|2, PEEP_FLAGS_P2 },
@@ -6442,6 +6441,23 @@ static int FixupDeleteInstr(int arg, IRList *irl, IR *ir) {
64426441
return 1;
64436442
}
64446443

6444+
6445+
// convert mov x, #255; and x, y to getbyte x, y, #0
6446+
static PeepholePattern pat_mov255_and[] = {
6447+
{ COND_TRUE, OPC_MOV, PEEP_OP_SET|0, PEEP_OP_IMM|255, PEEP_FLAGS_P2 },
6448+
{ COND_TRUE, OPC_AND, PEEP_OP_MATCH|0, PEEP_OP_SET|1, PEEP_FLAGS_P2 },
6449+
{ 0, 0, 0, 0, PEEP_FLAGS_DONE }
6450+
};
6451+
6452+
static int FixupMov255And(int arg, IRList *irl, IR *ir) {
6453+
IR *next_ir = ir->next;
6454+
DeleteIR(irl, ir);
6455+
ir = next_ir;
6456+
ReplaceOpcode(ir, OPC_GETBYTE);
6457+
ir->src2 = NewImmediate(0);
6458+
return 1;
6459+
}
6460+
64456461
static int ReplaceMaxMin(int arg, IRList *irl, IR *ir)
64466462
{
64476463
IR *irnext;
@@ -7139,6 +7155,8 @@ struct Peepholes {
71397155
{ pat_mux_qmux_2p, 2, FixupQMux },
71407156

71417157
{ pat_jmp_jmp, 1, FixupDeleteInstr },
7158+
7159+
{ pat_mov255_and, 1, FixupMov255And },
71427160
};
71437161

71447162

0 commit comments

Comments
 (0)