This is the mail archive of the
mailing list for the GCC project.
Re: Bit-field struct member sign extension pattern results in redundant
- From: Richard Henderson <rth at twiddle dot net>
- To: Michael Clark <michaeljclark at mac dot com>, GCC Development <gcc at gcc dot gnu dot org>
- Cc: Andrew Waterman <andrew at sifive dot com>
- Date: Fri, 18 Aug 2017 09:10:49 -0700
- Subject: Re: Bit-field struct member sign extension pattern results in redundant
- Authentication-results: sourceware.org; auth=none
- References: <0B196F40-1146-4DAF-96C9-60D8E4532FF4@mac.com>
On 08/17/2017 03:29 PM, Michael Clark wrote:
> hand coded x86 asm (no worse because the sar depends on the lea)
> shl edi, 27
> sar edi, 27
> movsx eax, dl
Typo in the register, but I know what you mean. More interestingly, edi
already has the sign-extended value, so "mov eax, edi" sufficies (saving one
byte or perhaps allowing better register allocation).
That said, if anyone is tweaking x86-64 patterns on this, consider
rorx eax, edi, 5
sar eax, 27
where the (newish) bmi2 rorx instruction allows the data to be moved into place
while rotating, avoiding the extra move entirely.