@@ -10107,6 +10107,13 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code,
*cost += rtx_cost (XEXP (op0, 0), mode, MINUS, 0, speed_p);
return true;
}
+ /* (Carry_op - reg) can be done as RSC Rd, Rn, #1 on Arm.
+ Note we do mean ~borrow here. */
+ else if (TARGET_ARM && arm_carry_operation (op0, SImode))
+ {
+ *cost += rtx_cost (op1, mode, code, 1, speed_p);
+ return true;
+ }
shift_op = shifter_op_p (op0, &shift_by_reg);
if (shift_op == NULL)
@@ -1649,6 +1649,19 @@ (define_insn "subsi3_carryin"
(set_attr "type" "adc_reg,adc_imm,alu_shift_imm")]
)
+;; Special canonicalization of the above when operand1 == (const_int 1):
+;; in this case the 'borrow' needs to treated like subtracting from the carry.
+(define_insn "rsbsi_carryin_reg"
+ [(set (match_operand:SI 0 "s_register_operand" "=r")
+ (minus:SI (match_operand:SI 1 "arm_carry_operation" "")
+ (match_operand:SI 2 "s_register_operand" "r")))]
+ "TARGET_ARM"
+ "rsc%?\\t%0, %2, #1"
+ [(set_attr "conds" "use")
+ (set_attr "predicable" "yes")
+ (set_attr "type" "adc_imm")]
+)
+
(define_insn "cmpsi3_carryin_<CC_EXTEND>out"
[(set (reg:<CC_EXTEND> CC_REGNUM)
(compare:<CC_EXTEND>