> On 18 Nov 2026, at 12:31, Jakub Jelinek <[email protected]> wrote:
> 
> On Wed, Nov 18, 2026 at 12:25:44PM +0100, [email protected] wrote:
>> From: Kyrylo Tkachov <[email protected]>
>> 
>> expand_CLMUL expands the call in the argument mode and then moves the
>> result into the lhs with emit_move_insn.  When the lhs is a promoted
>> SUBREG, as for QImode and HImode values on AArch64, this leaves the bits
>> above the declared mode unextended.  If the backend expands the clmul
>> through a wider instruction, such as PMULL on AArch64, those bits hold the
>> high half of the product and later users read a wrong value:
>> 
>>  unsigned short f8 (unsigned char x, unsigned char y)
>>  {
>>    return (unsigned char) __builtin_clmulg (x, y);
>>  }
>> 
>> f8 (0x7e, 0x9c) returned 0x3ae8 instead of 0xe8.  This makes
>> libstdc++ 26_numerics/clmul/1.cc fail at runtime for unsigned short.
>> 
>> Use convert_move into SUBREG_REG for promoted SUBREGs, as expand_mul_overflow
>> does for its result.
> 
> Isn't this a problem for IFN_CLMUL_WIDEN too, or is COMPLEX_TYPE never
> promoted?

AFAICT COMPLEX_TYPE is not promoted indeed, so it shouldn’t need such an 
adjustment.

> If it isn't, this patch is ok (and I guess I'll need to adjust my
> bitexpand/bitcompress patch similarly).

Thanks, will push when I next get the chance.
Kyrill

> 
>> Bootstrapped and tested on aarch64-none-linux-gnu.
>> Ok for trunk?
>> Thanks,
>> Kyrill
>> 
>> Cc: Jakub Jelinek <[email protected]>
>> 
>> gcc/ChangeLog:
>> 
>> * internal-fn.cc (expand_CLMUL): Use convert_move for promoted
>> SUBREG targets.
>> 
>> gcc/testsuite/ChangeLog:
>> 
>> * gcc.dg/builtin-clmulg-promoted-1.c: New test.
>> 
>> Signed-off-by: Kyrylo Tkachov <[email protected]>
> 
> Jakub


Reply via email to