factor / factor

Factor programming language
https://factorcode.org/
BSD 2-Clause "Simplified" License
1.65k stars 211 forks source link

Dead code elimination? #2389

Open mrjbq7 opened 3 years ago

mrjbq7 commented 3 years ago

Seems like this should remove the check for less than zero, since the contents of the if are removed...

IN: scratchpad [ [ /mod ] keep over 0 < [ + [ -1 + ] dip ] [ drop ] if drop integer? ] optimized.
[ mod 0 < [ ] [ ] if \ t ]

IN: scratchpad [ [ /mod ] keep over 0 < [ + [ -1 + ] dip ] [ drop ] if drop integer? ] disassemble
0000000104e7d940: 8905bab60cff          mov [rip-0xf34946], eax
0000000104e7d946: 53                    push rbx
0000000104e7d947: e8241071ff            call 0x10458e970 (mod)
0000000104e7d94c: 4983c608              add r14, 0x8
0000000104e7d950: 49c70600000000        mov qword [r14], 0x0
0000000104e7d957: e8b49638ff            call 0x104207010 (<)
0000000104e7d95c: 4983ee08              sub r14, 0x8
0000000104e7d960: 48b8fcf5770901000000  mov rax, 0x10977f5fc
0000000104e7d96a: 4983c608              add r14, 0x8
0000000104e7d96e: 498906                mov [r14], rax
0000000104e7d971: 890589b60cff          mov [rip-0xf34977], eax
0000000104e7d977: 5b                    pop rbx
0000000104e7d978: c3                    ret
0000000104e7d979: 0000                  add [rax], al
0000000104e7d97b: 0000                  add [rax], al
0000000104e7d97d: 0000                  add [rax], al
0000000104e7d97f: 00                    invalid
mrjbq7 commented 3 years ago

(It should probably remove mod as well since we know the output is an integer and inline t...