public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/67328] New: range test rather than single bit test for code testing enum values
@ 2015-08-23 13:41 amodra at gmail dot com
  2015-08-23 13:45 ` [Bug tree-optimization/67328] " amodra at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: amodra at gmail dot com @ 2015-08-23 13:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67328
           Summary: range test rather than single bit test for code
                    testing enum values
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amodra at gmail dot com
  Target Milestone: ---

The attached file generates ideal code, a test of a single bit, for the
condition in test_pic or test_exe depending on -DALT.  gcc ought to be able to
optimise to a single bit test for both functions whether or not -DALT.  It
looks like gcc incorrectly prefers a range test.


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

* [Bug tree-optimization/67328] range test rather than single bit test for code testing enum values
  2015-08-23 13:41 [Bug tree-optimization/67328] New: range test rather than single bit test for code testing enum values amodra at gmail dot com
@ 2015-08-23 13:45 ` amodra at gmail dot com
  2015-08-25  8:38 ` rguenth at gcc dot gnu.org
  2015-08-25 13:09 ` amodra at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: amodra at gmail dot com @ 2015-08-23 13:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Alan Modra <amodra at gmail dot com> ---
Created attachment 36247
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36247&action=edit
testcase from binutils/include/bfdlink.h


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

* [Bug tree-optimization/67328] range test rather than single bit test for code testing enum values
  2015-08-23 13:41 [Bug tree-optimization/67328] New: range test rather than single bit test for code testing enum values amodra at gmail dot com
  2015-08-23 13:45 ` [Bug tree-optimization/67328] " amodra at gmail dot com
@ 2015-08-25  8:38 ` rguenth at gcc dot gnu.org
  2015-08-25 13:09 ` amodra at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-08-25  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2015-08-25
     Ever confirmed|0                           |1

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note this is already fold-const.c:optimize_bit_field_compare at work.  With
-DALT (non-working code) we get

;; Function test_pic (null)
;; enabled by -tree-original


{
  if ((BIT_FIELD_REF <*info, 8, 0> & 3) + 254 <= 1)

and

;; Function test_exe (null)
;; enabled by -tree-original


{
  if ((SAVE_EXPR <BIT_FIELD_REF <*info, 8, 0> & 3>) == 0 || (SAVE_EXPR
<BIT_FIELD_REF <*info, 8, 0> & 3>) == 2)

from it.  Without -DALT

;; Function test_pic (null)
;; enabled by -tree-original


{
  if ((SAVE_EXPR <BIT_FIELD_REF <*info, 8, 0> & 3>) == 3 || (SAVE_EXPR
<BIT_FIELD_REF <*info, 8, 0> & 3>) == 1)

;; Function test_exe (null)
;; enabled by -tree-original


{
  if ((BIT_FIELD_REF <*info, 8, 0> & 3) <= 1)


I see more that a single bit test for both cases btw, mostly because we
need to mask the padding.  Not sure what optimal code you expect here.


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

* [Bug tree-optimization/67328] range test rather than single bit test for code testing enum values
  2015-08-23 13:41 [Bug tree-optimization/67328] New: range test rather than single bit test for code testing enum values amodra at gmail dot com
  2015-08-23 13:45 ` [Bug tree-optimization/67328] " amodra at gmail dot com
  2015-08-25  8:38 ` rguenth at gcc dot gnu.org
@ 2015-08-25 13:09 ` amodra at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: amodra at gmail dot com @ 2015-08-25 13:09 UTC (permalink / raw)
  To: gcc-bugs

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

Alan Modra <amodra at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

--- Comment #3 from Alan Modra <amodra at gmail dot com> ---
Maybe adding #if ALT only confused the issue.  For -UALT -O1 on x86_64 I get

test_pic:
        testb   $1, (%rdi)
        je      .L1
        addl    $1, result(%rip)
.L1:
        rep ret

test_exe:
        movzbl  (%rdi), %eax
        andl    $3, %eax
        cmpb    $1, %al
        ja      .L3
        addl    $1, result(%rip)
.L3:
        rep ret

For test_exe I would like to see the following equivalent and better optimised
code.

test_exe:
        testb   $2, (%rdi)
        jne     .L3
        addl    $1, result(%rip)
.L3:
        rep ret

The optimisation to a bit test for test_pic happens in reassoc1, or at least
that's where the process starts.


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

end of thread, other threads:[~2015-08-25 13:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-23 13:41 [Bug tree-optimization/67328] New: range test rather than single bit test for code testing enum values amodra at gmail dot com
2015-08-23 13:45 ` [Bug tree-optimization/67328] " amodra at gmail dot com
2015-08-25  8:38 ` rguenth at gcc dot gnu.org
2015-08-25 13:09 ` amodra at gmail dot com

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).