Jakub Jelinek <[email protected]> writes:
> 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.
Yeah, agreed. Namely:
(define_expand "bswapsi2"
[(set (match_operand:SI 0 "register_operand")
(bswap:SI (match_operand:SI 1 "register_operand")))]
"TARGET_ZBB || TARGET_ZBKB || TARGET_XTHEADBB"
{
/* Expose bswapsi2 on TARGET_64BIT so that the gimple store
merging pass will create suitable bswap insns. We can actually
just FAIL that case when generating RTL and let the generic code
handle it. */
if (TARGET_64BIT && !TARGET_XTHEADBB)
FAIL;
})
I don't think that's a good enough justification for an exception
like this. Even a target hook that says "is bswap cheap?" would IMO
be better than the above (and could default to "is bswap implemented?").
But hopefully the hook could be generalised a bit. For example, maybe
the hook could be a wrapper around:
/* Return true if we can implement OP for mode MODE directly, without resorting
to a libfunc. This usually means that OP will be implemented inline.
Note that this function cannot tell whether the target pattern chooses to
use libfuncs internally. */
bool
can_open_code_p (optab op, machine_mode mode)
and additionally test for "cheapness".
Thanks,
Richard
>
> So, e.g. following patch could be used to restore riscv build.
> Of course, if we later on use the ifns for vectors, that might change.
> To be precise, BSWAP already I think is vectorized using V*QImode
> VEC_PERM_EXPRs, but BITREVERSE can't be.
>
> 2026-06-05 Jakub Jelinek <[email protected]>
>
> * genemit.cc (main): Don't mark ifns using DEF_INTERNAL_INTSZ_FN
> - IFN_BSWAP/IFN_BITREVERSE - as nofail_optabs.
>
> --- gcc/genemit.cc.jj 2026-03-27 10:17:14.156330380 +0100
> +++ gcc/genemit.cc 2026-06-05 14:30:24.033736559 +0200
> @@ -902,6 +902,8 @@ main (int argc, const char **argv)
>
> #define DEF_INTERNAL_OPTAB_FN(NAME, FLAGS, OPTAB, TYPE) \
> nofail_optabs[OPTAB##_optab] = true;
> + /* BSWAP/BITREVERSE can fail though. */
> +#define DEF_INTERNAL_INTSZ_FN(NAME, FLAGS, OPTAB, TYPE)
> #include "internal-fn.def"
>
> /* Assign sequential codes to all entries in the machine description
>
>
> Jakub