x86: Generate shorter load-immediate constants with -Oz.
This change reduces code size on x86 by using `xorl` and `movb` to load small constants, replacing larger `movl` instructions at -Oz.
This commit introduces peephole optimizations for x86 that reduce code size when compiling with -Oz (optimize for size). It replaces movl $const, %eax (5 bytes) with an xorl %eax, %eax followed by a movb $const,%al or movb $const,%ah (4 bytes total) sequence when the flags register is dead. This optimization applies when loading small integer constants into suitable general-purpose registers, resulting in smaller executables.
In Details
The patch adds two peephole2 patterns to i386.md which transforms movl $const, %eax into xorl %eax, %eax ; movb $const, %al to reduce code size. It is guarded by -Oz and applies only when flags are dead. The intent is that modern x86 CPUs fuse the xorl; movb sequence into a single uop.
For Context
When compiling for x86, the compiler often needs to load constant values into registers. A common way to do this is with the movl instruction, which moves a 32-bit constant into a register. However, for small constants, there are shorter instruction sequences that can achieve the same result. This commit makes the compiler smarter at choosing these shorter sequences when you're trying to minimize the size of the compiled code (using the -Oz flag), which improves performance and reduces memory usage.