https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96536
--- Comment #6 from Uroš Bizjak <ubizjak at gmail dot com> --- (In reply to Hongtao.liu from comment #1) > I'm testing patch like > > emit_insn ((word_mode == SImode) > ? gen_incsspsi (reg_255) > : gen_incsspdi (reg_255)); > - tmp = gen_rtx_SET (reg_adj, gen_rtx_MINUS (ptr_mode, > - reg_adj, > - GEN_INT (255))); > - clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG)); > - tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob)); > - emit_insn (tmp); > - > - tmp = gen_rtx_COMPARE (CCmode, reg_adj, GEN_INT (255)); > + emit_insn ((ptr_mode == SImode) > + ? gen_subsi3 (reg_adj, reg_adj, GEN_INT (255)) > + : gen_subdi3 (reg_adj, reg_adj, GEN_INT (255))); > + tmp = gen_rtx_COMPARE (CCmode, reg_adj, const0_rtx); > flags = gen_rtx_REG (CCmode, FLAGS_REG); > emit_insn (gen_rtx_SET (flags, tmp)); The above part is not correct. The original code compares result with 255, your patch compares result with 0. So, the minimum patch (for backport) should just introduce: --cut here-- diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 292de142e90..6c207be3512 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -18695,6 +18695,10 @@ tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob)); emit_insn (tmp); + tmp = gen_rtx_COMPARE (CCZmode, reg_ssp, const0_rtx); + flags = gen_rtx_REG (CCZmode, FLAGS_REG); + emit_insn (gen_rtx_SET (flags, tmp)); + /* Compare and jump over adjustment code. */ noadj_label = gen_label_rtx (); flags = gen_rtx_REG (CCZmode, FLAGS_REG); --cut here-- The patch creates correct form of sub insn (tested with cet-sjlj-1.c testcase): #(insn 15 14 16 2 (parallel [ # (set (reg:CCZ 17 flags) # (compare:CCZ (minus:DI (reg:DI 0 ax [85]) # (mem:DI (const:DI (plus:DI (symbol_ref:DI ("buf") [flags 0x2] <var_decl 0x7f41c308cb40 buf>) # (const_int 16 [0x10]))) [2 S8 A8])) # (const_int 0 [0]))) # (set (reg:DI 0 ax [85]) # (minus:DI (reg:DI 0 ax [85]) # (mem:DI (const:DI (plus:DI (symbol_ref:DI ("buf") [flags 0x2] <var_decl 0x7f41c308cb40 buf>) # (const_int 16 [0x10]))) [2 S8 A8]))) # ]) "cet-sjlj-1.c":16:3 262 {*subdi_2} # (nil)) subq buf+16(%rip), %rax # 15 [c=8 l=7] *subdi_2/1