https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126640

--- Comment #3 from Kito Cheng <kito at gcc dot gnu.org> ---
(In reply to Michiel Derhaeg from comment #2)
> I noticed that QEMU started enforcing zicclsm. It feels a bit wrong to me
> that there is a separate feature concept tied to mcpu while there already is
> an extension that enforces exactly this.

Zicclsm only says that misaligned accesses will work.  The hardware may 
not support them; OpenSBI or the kernel may emulate them instead [1].
So Zicclsm says nothing about speed.

Zicclsm also covers scalar and vector accesses together [2].  That is too 
coarse to decide what the compiler may emit.  The C908 is a real case that
came up in LLVM [3]: scalar misaligned accesses work in hardware and are 
fast, but vector element-misaligned accesses trap and are not emulated.
This core does not have Zicclsm, yet misaligned scalar accesses are safe
on it and give a clear speedup.  If codegen only looked at Zicclsm, we
could not express this.

This is why LLVM codegen ignores Zicclsm: even with Zicclsm in -march, it
does not emit misaligned accesses.  LLVM split the option into
-m[no-]scalar-strict-align and -m[no-]vector-strict-align [4], and -mcpu
sets the matching features.  -mtune never does.

GCC has had the same two options since 2024.  The only problem is the 
default when they are not given: it comes from -mtune, so -mtune can turn
on misaligned vector accesses.  That is this bug.  I have sent a patch [5] 
that does the same as LLVM: an explicit -m[no-]{scalar,vector}-strict-align
wins; otherwise -mcpu decides whether misaligned accesses are allowed, and 
-mtune can only say they are slow.  As in LLVM, Zicclsm does not change
codegen.

[1] https://github.com/riscv/riscv-profiles/issues/193
[2] https://github.com/riscv/riscv-profiles/issues/58
[3] https://github.com/llvm/llvm-project/issues/88029
[4] https://github.com/llvm/llvm-project/pull/95024
[5]
https://patchwork.sourceware.org/project/gcc/list/?series=69023&state=%2A&archive=both

Reply via email to