The addsi3_compare_op patterns currently only have constraints to pick the 32-bit variants of the instructions. Although the assembler may sometimes opportunistically match a 16-bit t2 instruction, there's no real control over that within the compiler. Consequently we might emit a 32-bit adds instruction with a 16-bit subs instruction would serve equally well. We do, of course still have to be careful about the small number of boundary cases by controlling the order quite carefully.
This patch adds the constraints and templates to match the t2 16-bit
variants of these instructions. Now, for example, we can generate
subs r0, r0, #1 // 16-bit instruction
adds r0, r0, #1 // 32-bit instruction.
*confit/arm/arm.md (addsi3_compare_op1): Add 16-bit thumb-2 variants. (addsi3_compare_op2): Likewise.
4fe655e951e [arm] Recognize thumb2 16-bit variants of the add and compare instructions
gcc/ChangeLog | 5 +++++
gcc/config/arm/arm.md | 30 ++++++++++++++++++++++--------
2 files changed, 27 insertions(+), 8 deletions(-)