Avoid andb %dil when optimizing for size.
The simple test case below has the unfortunate property that on x86_64,
it is larger when compiled with -Os than when compiled with -O2.
int foo(char x)
{
return (x & 123) != 0;
}
The issue is x86's complex instruction encoding, where andb $XX,%dil
requires more bytes than andl $XX,%edi. This patch adds logic to
i386.md's *testqi_1_maybe_si and *andqi_2_maybe_si define_insn patterns
to prefer the shorter SImode alternative when optimizing for size.
2022-05-10 Uroš Bizjak <ubizjak@gmail.com>
Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* config/i386/i386.md (*testqi_1_maybe_si): Prefer shorter SImode
alternative when optimizing for size and the immediate operand is
const_0_to_127_operand.
(*andqi_2_maybe_si): Likewise.
* config/i386/predicates.md (const_0_to_127_operand): New predicate.
gcc/testsuite/ChangeLog
* gcc.target/i386/and-1.c: New test case.