This is neither a bug nor a feature request. It is just an interesting issue that came out when using GHDL with tools at machine level. The context is the following:
-fPIC enabled; see Context of #640.ghdl -e) contains several branch instructions such as CBZ WZR <address> or CBNZ xZR <address>, where CBZ/CBNZ mean compare and branch if (not) zero; and WZR/xZR are hardcoded zero registers (32/64 bits respectively).Instructions such as CBZ WZR <address> don't make sense. Comparing WZR with zero will always be true. So, it should have been compiled to B <address> (a direct branch, not a conditional one). By the same token, CBNZ xZR <address> should be a nop or not exists at all.
The resulting code (although ugly) works ok. I am just curious about why such strange code is generated from VUnit and not from other VHDL sources. However, I don't know how to further debug this:
I'd appreciate any hint, even if it involves not being worth to dig further.
The number of LLVM optimisation passes enabled in ghdl is very limited. That's certainly something to improve.
Once enabled, I suppose these instructions shouldn't appear
Thanks @tgingold. Is that something I can tinker with? Or is it an advanced task?
No, it is not an advanced task.
LLVM has a long list of optimization passes. You need to find the most interesting ones and the best order.
There is a couple of passes already added in src/ortho/llvm-nodebug/ortho_code_main.adb (See code about PassManager).
Optimizations are enabled with -O.
I close this issue as it was answered. If you need more help, do not hesitate to reopen it.