[fpc-devel] x86 TEST instruction

Marc Weustink marc at dommelstein.nl
Thu Jun 30 10:31:47 CEST 2022



On 27-6-2022 04:43, J. Gareth Moreton via fpc-devel wrote:
> Hi everyone,
> 
> I'm playing around with a peephole optimization (back to my roots!) and 
> I've come across a relatively simple one that aims to reduce instruction 
> size occasionally.  One part involves reducing the opsize if the 
> constant is numeric.  For example:
> 
> testl    $17,76(%rcx) -> testb $17,76(%rcx)
> 
> Or:
> 
> testl    $1,%ebx -> testb    $1,%bl
> 
> Obviously I check to make sure the constant fits into the smaller size. 
> Is there a time when this is NOT recommended?  I'm trying to remember 
> issues with partial register or memory writes, but in this case, it's 
> just a partial read.

It's not only the constant size which has to fit, but also the other 
operand. So you cannot use it for testing an integer for the value of 1

Marc


More information about the fpc-devel mailing list