https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123116
--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
Something like this:
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 7eafdf9ec1b..d59e31ceb66 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -8902,6 +8902,31 @@ (define_peephole2
(match_dup 0)))
(clobber (reg:CC FLAGS_REG))])])
+(define_insn_and_split "*add<mode>3_carry_imm"
+ [(set (match_operand:SWI 0 "nonimmediate_operand")
+ (plus:SWI
+ (plus:SWI
+ (if_then_else:SWI
+ (match_operator:SWI 4 "ix86_carry_flag_operator"
+ [(match_operand 3 "flags_reg_operand") (const_int 0)])
+ (const_int -1)
+ (const_int 0))
+ (match_operand:SWI 1 "nonimmediate_operand"))
+ (match_operand:SWI 2 "const_int_operand")))
+ (clobber (reg:CC FLAGS_REG))]
+ "ix86_binary_operator_ok (PLUS, <MODE>mode, operands, TARGET_APX_NDD)
+ && ix86_pre_reload_split ()"
+ "#"
+ "&& 1"
+ [(parallel
+ [(set (match_dup 0)
+ (minus:SWI
+ (minus:SWI (match_dup 1)
+ (match_op_dup 4 [(match_dup 3) (const_int 0)]))
+ (match_dup 2)))
+ (clobber (reg:CC FLAGS_REG))])]
+ "operands[2] = gen_int_mode (-INTVAL (operands[2]), <MODE>mode);")
+
(define_insn "*add<mode>3_carry_2"
[(set (reg FLAGS_REG)
(compare