From: Jeff Law Date: Mon, 21 Nov 2016 18:19:12 +0000 (-0700) Subject: re PR target/25128 ([m68k] Suboptimal comparisons against 65536) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=83ad4fac5aaba0075ce2f5fd395e49802b4cdb22;p=gcc.git re PR target/25128 ([m68k] Suboptimal comparisons against 65536) PR target/25128 * config/m68k/predicates.md (swap_peephole_relational_operator): New predicate. * config/m68k/m68k.md (relational tests against 65535/65536): New peephole2. PR target/25128 * gcc.target/m68k/pr25128.c: New test. From-SVN: r242676 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b30319eb664..d546162cc64 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2016-11-20 Jeff Law + + PR target/25128 + * config/m68k/predicates.md (swap_peephole_relational_operator): New + predicate. + * config/m68k/m68k.md (relational tests against 65535/65536): New + peephole2. + 2016-11-21 Kyrylo Tkachov * tree-ssa-loop-prefetch.c: Delete FIXME after the includes. diff --git a/gcc/config/m68k/m68k.md b/gcc/config/m68k/m68k.md index 208561996e7..c6130f12386 100644 --- a/gcc/config/m68k/m68k.md +++ b/gcc/config/m68k/m68k.md @@ -7786,7 +7786,6 @@ operands[6] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1)); operands[7] = operands[2]; }") - (define_peephole2 [(set (cc0) (compare (match_operand:SI 0 "register_operand" "") (match_operand:SI 1 "pow2_m1_operand" ""))) @@ -7804,3 +7803,23 @@ (match_dup 2) (match_dup 3)))] "{ operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1)); }") +;; When optimizing for size or for the original 68000 or 68010, we can +;; improve some relational tests against 65536 (which get canonicalized +;; internally against 65535). +;; The rotate in the output pattern will turn into a swap. +(define_peephole2 + [(set (cc0) (compare (match_operand:SI 0 "register_operand" "") + (const_int 65535))) + (set (pc) (if_then_else (match_operator 1 "swap_peephole_relational_operator" + [(cc0) (const_int 0)]) + (match_operand 2 "pc_or_label_operand") + (match_operand 3 "pc_or_label_operand")))] + "peep2_reg_dead_p (1, operands[0]) + && (operands[2] == pc_rtx || operands[3] == pc_rtx) + && (optimize_size || TUNE_68000_10) + && DATA_REG_P (operands[0])" + [(set (match_dup 0) (rotate:SI (match_dup 0) (const_int 16))) + (set (cc0) (compare (subreg:HI (match_dup 0) 2) (const_int 0))) + (set (pc) (if_then_else (match_op_dup 1 [(cc0) (const_int 0)]) + (match_dup 2) (match_dup 3)))] + "") diff --git a/gcc/config/m68k/predicates.md b/gcc/config/m68k/predicates.md index bfb548ab86f..be32ef60db3 100644 --- a/gcc/config/m68k/predicates.md +++ b/gcc/config/m68k/predicates.md @@ -279,3 +279,6 @@ ;; Used to detect (pc) or (label_ref) in some jumping patterns to cut down (define_predicate "pc_or_label_operand" (match_code "pc,label_ref")) + +(define_predicate "swap_peephole_relational_operator" + (match_code "gtu,leu,gt,le")) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 828c941265e..7dbfcaa8c30 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-20 Jeff Law + + PR target/25128 + * gcc.target/m68k/pr25128.c: New test. + 2016-11-21 Richard Sandiford * gcc.dg/tree-ssa/tailcall-7.c: New test. diff --git a/gcc/testsuite/gcc.target/m68k/pr25128.c b/gcc/testsuite/gcc.target/m68k/pr25128.c new file mode 100644 index 00000000000..f99f817d426 --- /dev/null +++ b/gcc/testsuite/gcc.target/m68k/pr25128.c @@ -0,0 +1,48 @@ +/* { dg-do compile } */ +/* { dg-options "-Os" } */ + +/* { dg-final { scan-assembler-times "swap" 4 } } */ +/* { dg-final { scan-assembler-times "tst.w" 4 } } */ +/* { dg-final { scan-assembler-not "cmp.l" } } */ + + +unsigned int bar (void); +void +foo1 (void) +{ + unsigned int a = bar (); + if (0x10000 <= a) + bar (); +} + + +void +foo2 (void) +{ + unsigned int a = bar (); + if (0x10000 > a) + bar (); +} + + +void +foo3 (void) +{ + int a = bar (); + if (0x10000 <= a) + bar (); +} + + +void +foo4 (void) +{ + int a = bar (); + if (0x10000 > a) + bar (); +} + + + + +