public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/65250] New: [SH] Improve comparisons followed by a negated cstore
@ 2015-02-28 11:59 olegendo at gcc dot gnu.org
  2023-10-22  1:32 ` [Bug target/65250] " olegendo at gcc dot gnu.org
  2023-10-22  2:52 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-02-28 11:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65250

            Bug ID: 65250
           Summary: [SH] Improve comparisons followed by a negated cstore
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olegendo at gcc dot gnu.org
            Target: sh*-*-*

The following example

bool test (int value)
{
  switch(value)
  {
    case 0:
    case 1:
    case 2:
      return true;
    default:
      return false;
  }
}

with -O2 -m4 compiles to:
        mov     #2,r1
        cmp/hi  r1,r4
        mov     #-1,r0
        rts
    negc    r0,r0

On SH4 there is no movrt, so it's better to do that as:
        mov     #2,r1
        cmp/hs  r4,r2
        rts
        movt    r0

..which is just inverting the comparison.


Combine tries the following pattern:

Failed to match this instruction:
(parallel [
        (set (reg:SI 168)
            (leu:SI (reg:SI 4 r4 [ value ])
                (const_int 2 [0x2])))
        (set (reg:SI 147 t)
            (const_int 1 [0x1]))
        (use (reg:SI 169))
    ])

..which is a combination of the inverted comparison and the expanded movrt (via
negc), which always sets T = 1.

A treg_set_expr pattern like the following could be added:

(define_insn_and_split "*"
  [(set (match_operand:SI 0 "arith_reg_dest")
        (match_operand 1 "treg_set_expr_not_const01"))
   (set (reg:SI T_REG) (const_int 1))
   (use (match_operand:SI 2 "arith_reg_operand"))]
 ...)

which would then split out the comparison insn and a trailing sett.  If the
sett is a dead store it will (should) get eliminated afterwards.

However, before that, the initial comparison and cstore expansion should be
investigated.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/65250] [SH] Improve comparisons followed by a negated cstore
  2015-02-28 11:59 [Bug target/65250] New: [SH] Improve comparisons followed by a negated cstore olegendo at gcc dot gnu.org
@ 2023-10-22  1:32 ` olegendo at gcc dot gnu.org
  2023-10-22  2:52 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: olegendo at gcc dot gnu.org @ 2023-10-22  1:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65250

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Briefly checked this one on GCC-13.  It generates the optimal sequence.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/65250] [SH] Improve comparisons followed by a negated cstore
  2015-02-28 11:59 [Bug target/65250] New: [SH] Improve comparisons followed by a negated cstore olegendo at gcc dot gnu.org
  2023-10-22  1:32 ` [Bug target/65250] " olegendo at gcc dot gnu.org
@ 2023-10-22  2:52 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-22  2:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65250

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |8.0

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC by r8-2701-g9dc3d6a96167b4c84824be5e472fba4956297033 .

Basically the gimple level is able to optimize that directly to:
  _1 = (unsigned int) value_3(D);
  _5 = _1 <= 2;

No reason to try to have combine optimize it any more.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-22  2:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-28 11:59 [Bug target/65250] New: [SH] Improve comparisons followed by a negated cstore olegendo at gcc dot gnu.org
2023-10-22  1:32 ` [Bug target/65250] " olegendo at gcc dot gnu.org
2023-10-22  2:52 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).