eliminating more useless operations

This commit is contained in:
Jakub Doka 2024-10-26 12:48:57 +02:00
parent 39588579a8
commit 45e1c6743a
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
6 changed files with 145 additions and 155 deletions

View file

@ -4019,15 +4019,17 @@ impl<'a> Function<'a> {
self.add_instr(nid, ops); self.add_instr(nid, ops);
} }
Kind::Stck Kind::Stck
if node.ty.loc(self.tys) == Loc::Reg && node.outputs.iter().all(|&n| { if node.outputs.iter().all(|&n| {
matches!(self.nodes[n].kind, Kind::Stre | Kind::Load) matches!(self.nodes[n].kind, Kind::Stre | Kind::Load
if self.nodes[n].ty.loc(self.tys) == Loc::Reg)
|| matches!(self.nodes[n].kind, Kind::BinOp { op: TokenKind::Add } || matches!(self.nodes[n].kind, Kind::BinOp { op: TokenKind::Add }
if self.nodes.is_const(self.nodes[n].inputs[2]) if self.nodes.is_const(self.nodes[n].inputs[2])
&& self.nodes[n] && self.nodes[n]
.outputs .outputs
.iter() .iter()
.all(|&n| matches!(self.nodes[n].kind, Kind::Stre | Kind::Load))) .all(|&n| matches!(self.nodes[n].kind, Kind::Stre | Kind::Load
}) => {} if self.nodes[n].ty.loc(self.tys) == Loc::Reg)))
}) => self.nodes.lock(nid),
Kind::Stck if self.tys.size_of(node.ty) == 0 => self.nodes.lock(nid), Kind::Stck if self.tys.size_of(node.ty) == 0 => self.nodes.lock(nid),
Kind::Stck => { Kind::Stck => {
let ops = vec![self.drg(nid)]; let ops = vec![self.drg(nid)];

View file

@ -2,24 +2,23 @@ main:
ADDI64 r254, r254, -36d ADDI64 r254, r254, -36d
ST r31, r254, 28a, 8h ST r31, r254, 28a, 8h
LI8 r1, 0b LI8 r1, 0b
ADDI64 r5, r254, 0d
ST r1, r254, 0a, 1h ST r1, r254, 0a, 1h
ST r1, r254, 1a, 1h ST r1, r254, 1a, 1h
LI8 r6, 255b LI8 r5, 255b
ST r6, r254, 2a, 1h ST r5, r254, 2a, 1h
LI8 r9, 1b LI8 r8, 1b
ST r9, r254, 3a, 1h ST r8, r254, 3a, 1h
LI64 r1, 1d LI64 r11, 1d
ADDI64 r2, r254, 4d ADDI64 r2, r254, 4d
ST r1, r254, 4a, 8h ST r11, r254, 4a, 8h
LI64 r5, 2d LI64 r3, 2d
ST r5, r254, 12a, 8h ST r3, r254, 12a, 8h
LI64 r8, 4d LI64 r6, 4d
ST r8, r254, 20a, 8h ST r6, r254, 20a, 8h
JAL r31, r0, :pass JAL r31, r0, :pass
LD r2, r254, 3a, 1h LD r12, r254, 3a, 1h
ANDI r4, r2, 255d ANDI r2, r12, 255d
ADD64 r1, r1, r4 ADD64 r1, r1, r2
LD r31, r254, 28a, 8h LD r31, r254, 28a, 8h
ADDI64 r254, r254, 36d ADDI64 r254, r254, 36d
JALA r0, r31, 0a JALA r0, r31, 0a
@ -32,6 +31,6 @@ pass:
LD r11, r11, 0a, 8h LD r11, r11, 0a, 8h
ADD64 r1, r11, r10 ADD64 r1, r11, r10
JALA r0, r31, 0a JALA r0, r31, 0a
code size: 327 code size: 316
ret: 8 ret: 8
status: Ok(()) status: Ok(())

View file

@ -23,29 +23,25 @@ scalar_values:
JALA r0, r31, 0a JALA r0, r31, 0a
structs: structs:
ADDI64 r254, r254, -48d ADDI64 r254, r254, -48d
ADDI64 r1, r254, 40d LI64 r1, 0d
LI64 r3, 0d ST r1, r254, 40a, 8h
ST r3, r254, 40a, 8h LI64 r4, 20d
ADDI64 r7, r254, 0d ST r4, r254, 0a, 8h
LI64 r9, 20d LI64 r7, 5d
ST r9, r254, 0a, 8h ST r7, r254, 8a, 8h
LI64 r1, 5d ST r7, r254, 16a, 8h
ADDI64 r2, r254, 8d LD r11, r254, 0a, 8h
ST r1, r254, 8a, 8h LD r1, r254, 8a, 8h
ST r1, r254, 16a, 8h ADD64 r5, r1, r11
LD r6, r254, 0a, 8h SUB64 r5, r5, r7
LD r8, r254, 8a, 8h ST r5, r254, 24a, 8h
ADD64 r11, r8, r6 ST r4, r254, 32a, 8h
SUB64 r11, r11, r1 LD r9, r254, 40a, 8h
ADDI64 r5, r254, 24d LD r11, r254, 24a, 8h
ST r11, r254, 24a, 8h ADD64 r2, r11, r9
ST r9, r254, 32a, 8h SUB64 r1, r2, r4
LD r5, r254, 40a, 8h
LD r7, r254, 24a, 8h
ADD64 r10, r7, r5
SUB64 r1, r10, r9
ADDI64 r254, r254, 48d ADDI64 r254, r254, 48d
JALA r0, r31, 0a JALA r0, r31, 0a
code size: 417 code size: 373
ret: 0 ret: 0
status: Ok(()) status: Ok(())

View file

@ -15,17 +15,16 @@ main:
set: set:
ADDI64 r254, r254, -25d ADDI64 r254, r254, -25d
LI8 r7, 5b LI8 r7, 5b
ADDI64 r11, r254, 0d
ST r7, r254, 0a, 1h ST r7, r254, 0a, 1h
ANDI r11, r4, 4294967295d ANDI r10, r4, 4294967295d
ST r11, r254, 1a, 4h ST r10, r254, 1a, 4h
LI32 r4, 8w LI32 r1, 8w
ST r4, r254, 5a, 4h ST r1, r254, 5a, 4h
ST r2, r254, 9a, 8h ST r2, r254, 9a, 8h
ST r3, r254, 17a, 8h ST r3, r254, 17a, 8h
LD r1, r254, 1a, 4h LD r1, r254, 1a, 4h
ADDI64 r254, r254, 25d ADDI64 r254, r254, 25d
JALA r0, r31, 0a JALA r0, r31, 0a
code size: 295 code size: 284
ret: 1024 ret: 1024
status: Ok(()) status: Ok(())

View file

@ -1,118 +1,113 @@
main: main:
ADDI64 r254, r254, -168d ADDI64 r254, r254, -168d
LI8 r1, 0b LI8 r1, 0b
ADDI64 r3, r254, 148d
ST r1, r254, 148a, 1h ST r1, r254, 148a, 1h
ST r1, r254, 149a, 1h ST r1, r254, 149a, 1h
ST r1, r254, 150a, 1h ST r1, r254, 150a, 1h
ST r1, r254, 151a, 1h ST r1, r254, 151a, 1h
LI8 r10, 1b LI8 r7, 1b
ADDI64 r11, r254, 144d ST r7, r254, 144a, 1h
ST r10, r254, 144a, 1h ST r7, r254, 145a, 1h
ST r10, r254, 145a, 1h ST r7, r254, 146a, 1h
ST r10, r254, 146a, 1h ST r7, r254, 147a, 1h
ST r10, r254, 147a, 1h LD r2, r254, 144a, 1h
LD r6, r254, 144a, 1h
LD r7, r254, 148a, 1h
ADD8 r9, r6, r7
ST r9, r254, 148a, 1h
LD r1, r254, 145a, 1h
LD r2, r254, 149a, 1h
ADD8 r4, r2, r1
ST r4, r254, 149a, 1h
LD r8, r254, 146a, 1h
LD r9, r254, 150a, 1h
ADD8 r11, r9, r8
ST r11, r254, 150a, 1h
LD r3, r254, 147a, 1h
LD r4, r254, 151a, 1h
ADD8 r6, r4, r3
ST r6, r254, 151a, 1h
LD r10, r254, 149a, 1h
LD r11, r254, 150a, 1h
ADD8 r1, r11, r10
LD r3, r254, 148a, 1h LD r3, r254, 148a, 1h
ADD8 r7, r3, r1 ADD8 r5, r2, r3
LI8 r8, 4b ST r5, r254, 148a, 1h
ADD8 r7, r7, r6 LD r9, r254, 145a, 1h
ANDI r7, r7, 255d LD r10, r254, 149a, 1h
ANDI r8, r8, 255d ADD8 r12, r10, r9
JEQ r7, r8, :0 ST r12, r254, 149a, 1h
LD r4, r254, 146a, 1h
LD r5, r254, 150a, 1h
ADD8 r7, r5, r4
ST r7, r254, 150a, 1h
LD r11, r254, 147a, 1h
LD r12, r254, 151a, 1h
ADD8 r2, r12, r11
ST r2, r254, 151a, 1h
LD r6, r254, 149a, 1h
LD r7, r254, 150a, 1h
ADD8 r9, r7, r6
LD r11, r254, 148a, 1h
ADD8 r3, r11, r9
LI8 r4, 4b
ADD8 r3, r3, r2
ANDI r3, r3, 255d
ANDI r4, r4, 255d
JEQ r3, r4, :0
LI64 r1, 1008d LI64 r1, 1008d
JMP :1 JMP :1
0: LI64 r3, 1d 0: LI64 r11, 1d
ADDI64 r6, r254, 80d ADDI64 r2, r254, 80d
ST r3, r254, 80a, 8h ST r11, r254, 80a, 8h
LI64 r7, 2d LI64 r3, 2d
ST r7, r254, 88a, 8h ST r3, r254, 88a, 8h
LI64 r11, 3d LI64 r7, 3d
ADDI64 r2, r254, 32d ST r7, r254, 32a, 8h
ST r11, r254, 32a, 8h LI64 r10, 4d
LI64 r3, 4d ST r10, r254, 40a, 8h
ST r3, r254, 40a, 8h LD r4, r254, 32a, 8h
LD r10, r254, 32a, 8h LD r5, r254, 80a, 8h
LD r11, r254, 80a, 8h ADDI64 r3, r254, 0d
ADDI64 r9, r254, 0d ADD64 r7, r4, r5
ADD64 r1, r10, r11 ST r7, r254, 0a, 8h
ST r1, r254, 0a, 8h LD r11, r254, 40a, 8h
LD r5, r254, 40a, 8h LD r12, r254, 88a, 8h
LD r7, r254, 88a, 8h ADD64 r4, r11, r12
ADD64 r8, r5, r7 ST r4, r254, 8a, 8h
ST r8, r254, 8a, 8h LD r6, r254, 80a, 8h
LD r12, r254, 80a, 8h LD r7, r254, 32a, 8h
LD r1, r254, 32a, 8h SUB64 r9, r7, r6
SUB64 r3, r1, r12 ST r9, r254, 16a, 8h
ST r3, r254, 16a, 8h LD r1, r254, 88a, 8h
LD r7, r254, 88a, 8h LD r4, r254, 40a, 8h
LD r8, r254, 40a, 8h SUB64 r4, r4, r1
SUB64 r10, r8, r7 ST r4, r254, 24a, 8h
ST r10, r254, 24a, 8h ADDI64 r7, r254, 112d
ADDI64 r1, r254, 112d BMC r3, r7, 32h
BMC r9, r1, 32h LI64 r10, 0d
LI64 r4, 0d ST r10, r254, 96a, 8h
ADDI64 r7, r254, 96d ST r10, r254, 104a, 8h
ST r4, r254, 96a, 8h LD r3, r254, 32a, 8h
ST r4, r254, 104a, 8h LD r4, r254, 96a, 8h
LD r11, r254, 32a, 8h ADDI64 r10, r254, 48d
LD r12, r254, 96a, 8h SUB64 r7, r4, r3
ADDI64 r7, r254, 48d ST r7, r254, 48a, 8h
LD r11, r254, 40a, 8h
LD r12, r254, 104a, 8h
SUB64 r3, r12, r11 SUB64 r3, r12, r11
ST r3, r254, 48a, 8h
LD r8, r254, 40a, 8h
LD r9, r254, 104a, 8h
SUB64 r10, r9, r8
ST r10, r254, 56a, 8h
ADDI64 r8, r7, 16d
BMC r6, r8, 16h
LD r5, r254, 112a, 8h
LD r6, r254, 48a, 8h
ADD64 r8, r6, r5
ST r8, r254, 48a, 8h
LD r12, r254, 120a, 8h
LD r1, r254, 56a, 8h
ADD64 r3, r12, r1
ST r3, r254, 56a, 8h ST r3, r254, 56a, 8h
LD r8, r254, 128a, 8h ADDI64 r12, r10, 16d
LD r9, r254, 64a, 8h BMC r2, r12, 16h
ADD64 r11, r8, r9 LD r9, r254, 112a, 8h
ST r11, r254, 64a, 8h LD r10, r254, 48a, 8h
LD r3, r254, 136a, 8h ADD64 r12, r10, r9
LD r4, r254, 72a, 8h ST r12, r254, 48a, 8h
ADD64 r6, r3, r4 LD r4, r254, 120a, 8h
ST r6, r254, 72a, 8h LD r5, r254, 56a, 8h
LD r10, r254, 64a, 8h ADD64 r7, r4, r5
LD r11, r254, 48a, 8h ST r7, r254, 56a, 8h
ADDI64 r5, r254, 152d LD r12, r254, 128a, 8h
ADD64 r2, r10, r11 LD r1, r254, 64a, 8h
ST r2, r254, 152a, 8h ADD64 r3, r12, r1
LD r6, r254, 72a, 8h ST r3, r254, 64a, 8h
LD r7, r254, 56a, 8h LD r7, r254, 136a, 8h
ADD64 r9, r6, r7 LD r8, r254, 72a, 8h
ST r9, r254, 160a, 8h ADD64 r10, r7, r8
LD r1, r254, 152a, 8h ST r10, r254, 72a, 8h
ADD64 r1, r1, r9 LD r2, r254, 64a, 8h
LD r3, r254, 48a, 8h
ADD64 r5, r2, r3
ST r5, r254, 152a, 8h
LD r9, r254, 72a, 8h
LD r10, r254, 56a, 8h
ADD64 r12, r9, r10
ST r12, r254, 160a, 8h
LD r3, r254, 152a, 8h
ADD64 r1, r3, r12
1: ADDI64 r254, r254, 168d 1: ADDI64 r254, r254, 168d
JALA r0, r31, 0a JALA r0, r31, 0a
code size: 1200 code size: 1145
ret: 10 ret: 10
status: Ok(()) status: Ok(())

View file

@ -35,20 +35,19 @@ main:
ADDI64 r254, r254, -26d ADDI64 r254, r254, -26d
ST r31, r254, 2a, 24h ST r31, r254, 2a, 24h
LI8 r32, 10b LI8 r32, 10b
ADDI64 r3, r254, 0d
ST r32, r254, 0a, 1h ST r32, r254, 0a, 1h
ST r32, r254, 1a, 1h ST r32, r254, 1a, 1h
LD r7, r254, 0a, 1h LD r5, r254, 0a, 1h
ANDI r2, r7, 255d ANDI r2, r5, 255d
JAL r31, r0, :fib JAL r31, r0, :fib
CP r33, r1 CP r33, r1
ANDI r2, r32, 255d ANDI r2, r32, 255d
JAL r31, r0, :fib_iter JAL r31, r0, :fib_iter
CP r6, r33 CP r4, r33
SUB64 r1, r6, r1 SUB64 r1, r4, r1
LD r31, r254, 2a, 24h LD r31, r254, 2a, 24h
ADDI64 r254, r254, 26d ADDI64 r254, r254, 26d
JALA r0, r31, 0a JALA r0, r31, 0a
code size: 362 code size: 351
ret: 0 ret: 0
status: Ok(()) status: Ok(())