store-merging, riscv: Consider widen_bswap_or_bitreverse in store-merging decisions and fix up riscv build

On Fri, Jun 05, 2026 at 02:22:25PM +0200, Andreas Schwab wrote:
> This breaks riscv:
>
> ../../gcc/config/riscv/riscv.md:5297:14: error: bswapsi2 cannot FAIL
> ../../gcc/config/riscv/bitmanip.md:543:5: note: in expansion of macro 'FAIL'
>   543 |     FAIL;
>       |     ^~~~

wtw mentioned that on IRC.
In the way IFN_BSWAP/IFN_BITREVERSE are used currently (i.e. only used
for large/huge _BitInt or in the C++ FE, but not making it to expansion)
there is no reason why FAIL wouldn't be allowed (like before my changes),
though I find the riscv hack really ugly.
Instead of adding a workaround, this patch removes the riscv hack and
instead adjusts store-merging pass to take into account
widen_bswap_or_bitreverse; currently it already takes into account
expand_doubleword_bswap_or_bitreverse (on 32-bit word targets which have
bswapsi2 expanders expects __builtin_bswap64 to be cheap).  With this
patch, it expects __builtin_bswap32 to be cheap if bswapdi2 expander
is present, because widen_bswap_or_bitreverse will handle it as
(subreg:SI (lshiftrt:DI (bswap:DI (subreg:DI (arg:SI) 0)) (const_int 32)) low)

2026-06-05  Jakub Jelinek  <jakub@redhat.com>

	* gimple-ssa-store-merging.cc (maybe_optimize_vector_constructor):
	Also support bswap32 if bswapdi2 expander is present.  Add comment
	about bswap64 support on 32-bit targets with bswapsi2 expander.
	(pass_optimize_bswap::execute): Likewise.
	* config/riscv/bitmanip.md (bswapsi2): Change condition to disable
	the expander on TARGET_64BIT without TARGET_XTHEADBB, never FAIL.

Reviewed-by: Richard Sandiford <rdsandiford@googlemail.com>
Reviewed-by: Richard Biener <rguenth@suse.de>
2 files changed