From: Jakub Jelinek Date: Fri, 20 Dec 2019 08:22:46 +0000 (+0100) Subject: re PR target/93002 (while(i--) optimization) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=99675d5c4581c5ac01118ab64785fde1f7f25183;p=gcc.git re PR target/93002 (while(i--) optimization) PR target/93002 * config/i386/i386.md (dec reg; cmp $-1, reg; jne lab): New define_peephole2. * gcc.target/i386/pr93002.c: New test. From-SVN: r279632 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 28f5994ea0d..e486d7cffde 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-12-20 Jakub Jelinek + + PR target/93002 + * config/i386/i386.md (dec reg; cmp $-1, reg; jne lab): New + define_peephole2. + 2019-12-19 Julian Brown * gimplify.c (gimplify_omp_var_data): Add GOVD_MAP_HAS_ATTACHMENTS. diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 672fd1c2749..b0176c8bf94 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -6503,6 +6503,36 @@ [(set (reg:CC FLAGS_REG) (compare:CC (match_dup 0) (match_dup 1)))]) +;; decl %eax; cmpl $-1, %eax; jne .Lxx; can be optimized into +;; subl $1, %eax; jnc .Lxx; +(define_peephole2 + [(parallel + [(set (match_operand:SWI 0 "general_reg_operand") + (plus:SWI (match_dup 0) (const_int -1))) + (clobber (reg FLAGS_REG))]) + (set (reg:CCZ FLAGS_REG) + (compare:CCZ (match_dup 0) (const_int -1))) + (set (pc) + (if_then_else (match_operator 1 "bt_comparison_operator" + [(reg:CCZ FLAGS_REG) (const_int 0)]) + (match_operand 2) + (pc)))] + "peep2_regno_dead_p (3, FLAGS_REG)" + [(parallel + [(set (reg:CC FLAGS_REG) + (compare:CC (match_dup 0) (const_int 1))) + (set (match_dup 0) + (minus:SWI (match_dup 0) (const_int 1)))]) + (set (pc) + (if_then_else (match_dup 3) + (match_dup 2) + (pc)))] +{ + rtx cc = gen_rtx_REG (CCmode, FLAGS_REG); + operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[1]) == NE + ? GEU : LTU, VOIDmode, cc, const0_rtx); +}) + (define_insn "*subsi_3_zext" [(set (reg FLAGS_REG) (compare (match_operand:SI 1 "register_operand" "0") diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8c2abb64d37..c4231c82de7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-12-20 Jakub Jelinek + + PR target/93002 + * gcc.target/i386/pr93002.c: New test. + 2019-12-19 Julian Brown * gfortran.dg/goacc/derived-types.f90: New test. diff --git a/gcc/testsuite/gcc.target/i386/pr93002.c b/gcc/testsuite/gcc.target/i386/pr93002.c new file mode 100644 index 00000000000..0248fcc00a5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr93002.c @@ -0,0 +1,22 @@ +/* PR target/93002 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "cmp\[^\n\r]*-1" } } */ + +volatile int sink; + +void +foo (void) +{ + unsigned i = 1000; + while (i--) + sink = i; +} + +void +bar (void) +{ + int i = 2000; + while (i--) + sink = i; +}