Is this compiler bug in Zig or LLVM?

Hi, I’ve been doing some attempts at Playstation 1 homebrew development with Zig. The PS1’s CPU uses the MIPS-I instruction set, so I target it using -target mipsel-freestanding -mcpu mips1.

I think I found a bug:

With divisions, the compiled output when safety checks are enabled includes the teq (Trap if equal) instruction to check for divide by zero. The MIPS-I instruction set does not have this yet, it was introduced in MIPS-II.

So the bug is that the compiled output includes teq even when the mips1 CPU is targeted. Here’s a godbolt link, the teq is on line 25: Compiler Explorer

I’m unsure who or how to report this. Is it an LLVM bug or a Zig bug? (…or do I have my compiler flags wrong?)

(For now, I’m able to continue by always compiling with OReleaseFast no matter what. It does mean I don’t get proper asserts though :frowning: )

This is an LLVM bug. Its support for MIPS III and older is very experimental/incomplete.

1 Like

Thanks. Just in case anyone else stumbles across this with the same issue, I did some searching and found this issue in the LLVM bug tracker: mips1 target generates invalid instruction · Issue #80554 · llvm/llvm-project · GitHub

and it looks like there is a PR for a fix as well! [Mips] Handle division by zero trap on MIPS1 by neoto · Pull Request #201133 · llvm/llvm-project · GitHub

1 Like