diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index 76990628150..fee4d07b7fd 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -2658,6 +2658,14 @@ ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1) machine_mode cmpmode; rtx tmp, flags; + /* Swap operands to emit carry flag comparison. */ + if ((code == GTU || code == LEU) + && nonimmediate_operand (op1, VOIDmode)) + { + std::swap (op0, op1); + code = swap_condition (code); + } + cmpmode = SELECT_CC_MODE (code, op0, op1); flags = gen_rtx_REG (cmpmode, FLAGS_REG); diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index eff189f17b4..b7f3e36a70c 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -6777,7 +6777,7 @@ (define_insn "*add3_carry_0" [(match_operand 2 "flags_reg_operand") (const_int 0)]) (match_operand:SWI 1 "nonimmediate_operand" "0"))) (clobber (reg:CC FLAGS_REG))] - "ix86_unary_operator_ok (PLUS, mode, operands)" + "!MEM_P (operands[0]) || rtx_equal_p (operands[0], operands[1])" "adc{}\t{$0, %0|%0, 0}" [(set_attr "type" "alu") (set_attr "use_carry" "1") @@ -6919,7 +6919,7 @@ (define_insn "*sub3_carry_0" (match_operator:SWI 3 "ix86_carry_flag_operator" [(match_operand 2 "flags_reg_operand") (const_int 0)]))) (clobber (reg:CC FLAGS_REG))] - "ix86_unary_operator_ok (MINUS, mode, operands)" + "!MEM_P (operands[0]) || rtx_equal_p (operands[0], operands[1])" "sbb{}\t{$0, %0|%0, 0}" [(set_attr "type" "alu") (set_attr "use_carry" "1")