public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/56925] New: SRA should take into account likelihood of statements being executed
@ 2013-04-11 18:58 josh.m.conner at gmail dot com
  2013-04-12  8:43 ` [Bug tree-optimization/56925] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: josh.m.conner at gmail dot com @ 2013-04-11 18:58 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56925

             Bug #: 56925
           Summary: SRA should take into account likelihood of statements
                    being executed
    Classification: Unclassified
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: josh.m.conner@gmail.com


In the following code:

  struct stype {
    unsigned int pad:4;
    unsigned int val:4;
  };

  void bar (void);
  void baz (void);

  int x, y;

  unsigned int foo (struct stype input)
  {
    if (__builtin_expect (x, 0))
      return input.val;

    if (__builtin_expect (y, 0))
      return input.val + 1;

    return 0;
  }

When compiled with -O2, SRA moves the read of input.val to the top of the
function:


  ;; Function foo (foo, funcdef_no=0, decl_uid=4988, cgraph_uid=0)

  Candidate (4987): input
  Rejected (4999): not aggregate: y.1
  Rejected (4993): not aggregate: x.0
  Created a replacement for input offset: 4, size: 4: input$val
  ...

  <bb 2>:
  input$val_14 = input.val;
  x.0_3 = x;
  _4 = __builtin_expect (x.0_3, 0);
  if (_4 != 0)
    goto <bb 3>;
  else
    goto <bb 4>;
  ...

Which means that the critical path for this function now executes an extra
instruction.

It would be nice if SRA would take into account the likelihood of statement
execution when deciding whether to apply the transformation.  We currently
verify that there are at least two reads -- perhaps we should check that there
are at least two reads that are likely to occur.

This can be seen in sub-optimal codegen for ARM, where a bitfield extract
(ubfx) is moved out of unlikely code into the critical path:

  foo:
        movw    r3, #:lower16:x
        ubfx    r2, r0, #4, #4
        movt    r3, #:upper16:x
        ldr     r3, [r3]
        cmp     r3, #0
        bne     .L6
        ...


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

* [Bug tree-optimization/56925] SRA should take into account likelihood of statements being executed
  2013-04-11 18:58 [Bug tree-optimization/56925] New: SRA should take into account likelihood of statements being executed josh.m.conner at gmail dot com
@ 2013-04-12  8:43 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-04-12  8:43 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56925

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-04-12
                 CC|                            |jamborm at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> 2013-04-12 08:43:39 UTC ---
Eventually SRA should be made flow-sensitive.


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

end of thread, other threads:[~2013-04-12  8:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-11 18:58 [Bug tree-optimization/56925] New: SRA should take into account likelihood of statements being executed josh.m.conner at gmail dot com
2013-04-12  8:43 ` [Bug tree-optimization/56925] " rguenth 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).