Hi Jakub, > Well, with the patch the decision which insn is chosen is done in C code. > So it could look like: > if (operands[2] == const0_rtx > || INTVAL (operands[2]) == -HOST_WIDE_INT_C (0x80000000) > subs; // mandatory > else if (TARGET_THUMB2 > && arm_immediate_operand (operands[2], SImode) > && arm_neg_immediate_operand (operands[2], SImode)) > { > // Both adds and subs can do the job here, and unlike > // non-thumb mode, the instructions can have different > // sizes. Pick the shorter one. > } > else if (which_alternative == 1) > subs; > else > adds; > > This can be done incrementally, I just have no idea what the rules > for thumb2 constant encoding are.
This is overcomplicating something simple - adds/subs are completely symmetrical on all Arm targets. So for addition you simply place adds alternative first and then subs. For comparison/subtraction place the subs alternative first, then adds. Now all special cases will be correct automatically without needing any extra work or code. In terms of codesize you need one little tweak for Thumb-2 given that add(s) and sub(s) of -1 would use a 32-bit rather than 16-bit encoding. This is handled by not allowing it as a valid immediate on Thumb-2, so that add -1 is emitted as sub 1 instead (this is not really a loss given that AND -1, OR -1, EOR -1 etc are all redundant). Wilco