LoongArch: Switch the default code model to medium
It has turned out the normal code model isn't enough for some large
LoongArch link units in practice. Quoting WANG Rui's comment [1]:
We’ve actually been considering pushing for a change to the default
code model for LoongArch compilers (including GCC) for a while now.
In fact, this was one of the topics discussed in yesterday’s internal
compiler tool-chain meeting. The reason we haven’t moved forward with
it yet is that the medium code model generates a R_LARCH_CALL36
relocation, which had some issues with earlier versions of the linker.
We need to assess the impact on users before proceeding with the change.
In GCC we have build-time probe for linker call36 support and if the
linker does not support it, we fall back to pcalau12i + jirl or
la.{local,global} + jirl for the medium code model. I also had some
concern about a potential performance regression caused by the
conservative nature of the relaxation process, but when I tested this
patch it turned out the relaxation is powerful enough to eliminate all
the pcaddu18i instructions in cc1plus and libstdc++.so.
The Loong Arch Linux project has been using -mcmodel=medium in their
{C,CXX}FLAGS building packages for a while [2] and they've not reported
any issues with that.
The Linux kernel developers has already anticipated the change and
explicitly specified -mcmodel=normal for a while [3].
Thus to me it's safe to make GCC 16 the first release with the medium
code model as the default now. If someone must keep the normal code
model as the default for any reason, it's possible to configure GCC
using --with-cmodel=normal.
[1]: https://discourse.llvm.org/t/rfc-changing-the-default-code-model-for-loongarch/85317/3
[2]: https://github.com/lcpu-club/loongarch-packages/pull/340
[3]: https://git.kernel.org/torvalds/c/
e67e0eb6a98b
gcc/
* config.gcc: Support --with-cmodel={medium,normal} and make
medium the default for LoongArch, define TARGET_DEFAULT_CMODEL
as the selected value.
* config/loongarch/loongarch-opts.cc: Use TARGET_DEFAULT_CMODEL
instead of hard coding CMODEL_NORMAL.
* doc/install.texi: Document that --with-cmodel= is supported
for LoongArch.
* doc/invoke.texi: Update the document about default code model
on LoongArch.
gcc/testsuite/
* gcc.target/loongarch/vect-frint-no-inexact.c (dg-options): Add
-mcmodel=normal.
* gcc.target/loongarch/vect-frint-scalar-no-inexact.c: Likewise.
* gcc.target/loongarch/vect-frint-scalar.c: Likewise.
* gcc.target/loongarch/vect-frint.c: Likewise.
* gcc.target/loongarch/vect-ftint-no-inexact.c: Likewise.
* gcc.target/loongarch/vect-ftint.c: Likewise.