[llvm] [AVR] Fix a crash in AVRInstrInfo::insertIndirectBranch (PR #67324)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 04:06:57 PDT 2023


aykevl wrote:

> A full solution would be introducing "code model", like riscv did https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/RISCV/jumptable.ll#L4
> 
> when `--model-mode=medium` is specified, we use indirect branch `ijmp` instead of short direct `rjmp`, for AVR devices without long direct jump.

Probably unnecessary. I think the only chips that are limited to `rjmp` are the chips that don't have enough flash to address more memory anyway. For example, the attiny85 has only 8kB flash so the entire flash area can be addressed using `rjmp`. From the ISA documentation:

> Relative jump to an address within PC - 2K +1 and PC + 2K (words). For AVR microcontrollers with pogram memory not exceeding 4K words (8 KB), this instruction can address the entire memory from every address location. See also JMP.

As for the current fix:

> This patch just fixes the crash, but incorrect code is still generated, and the assembler or the linker will report "out of range".

That seems like a reasonable solution to me. I hit this while compiling parts of the libc that will be too large anyway for these small chips, but it's nice to be able to compile those parts anyway. If those large functions are linked, they will result in a linker error anyway because they don't fit the flash space.

https://github.com/llvm/llvm-project/pull/67324


More information about the llvm-commits mailing list