public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/51084] New: bounds checking not optimized to a single comparison
@ 2011-11-10 17:43 eggert at gnu dot org
  2011-11-11  0:48 ` [Bug middle-end/51084] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: eggert at gnu dot org @ 2011-11-10 17:43 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51084
           Summary: bounds checking not optimized to a single comparison
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eggert@gnu.org
              Host: x86-64
            Target: x86-64
             Build: x86-64


Created attachment 25788
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25788
code for pure0 and pure1 is slower than for pure2 and pure3

I ran into this problem when tuning GNU Emacs; see
<http://lists.gnu.org/archive/html/emacs-devel/2011-11/msg00145.html>.
Emacs checks whether a pointer P points into an
array A by doing the equivalent of
(A <= P && P < &A[sizeof A]).  This can be
done with a subtraction followed by a single
comparison, but GCC generates slower code that does
two comparisons and a conditional branch.

The attached source code illustrates the problem.
When compiled using "gcc -O2 -S", the functions
pure0 and pure1 should generate code as fast as
that generated by pure2 and pure3.  But the slower
code is generated.


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

* [Bug middle-end/51084] bounds checking not optimized to a single comparison
  2011-11-10 17:43 [Bug c/51084] New: bounds checking not optimized to a single comparison eggert at gnu dot org
@ 2011-11-11  0:48 ` pinskia at gcc dot gnu.org
  2012-01-07 22:40 ` [Bug tree-optimization/51084] " pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-11-11  0:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
          Component|c                           |middle-end
           Severity|normal                      |enhancement


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

* [Bug tree-optimization/51084] bounds checking not optimized to a single comparison
  2011-11-10 17:43 [Bug c/51084] New: bounds checking not optimized to a single comparison eggert at gnu dot org
  2011-11-11  0:48 ` [Bug middle-end/51084] " pinskia at gcc dot gnu.org
@ 2012-01-07 22:40 ` pinskia at gcc dot gnu.org
  2021-07-26 19:39 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-01-07 22:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-01-07
          Component|middle-end                  |tree-optimization
     Ever Confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-07 22:39:53 UTC ---
Confirmed.


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

* [Bug tree-optimization/51084] bounds checking not optimized to a single comparison
  2011-11-10 17:43 [Bug c/51084] New: bounds checking not optimized to a single comparison eggert at gnu dot org
  2011-11-11  0:48 ` [Bug middle-end/51084] " pinskia at gcc dot gnu.org
  2012-01-07 22:40 ` [Bug tree-optimization/51084] " pinskia at gcc dot gnu.org
@ 2021-07-26 19:39 ` pinskia at gcc dot gnu.org
  2021-11-24  5:10 ` pinskia at gcc dot gnu.org
  2024-02-18  8:18 ` eggert at cs dot ucla.edu
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-26 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2012-01-07 00:00:00         |2021-7-26

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
pure0:
  _5 = obj_2(D) < &pure[1000000];
  _6 = obj_2(D) >= &pure;
  _7 = _5 & _6;

pure1:
  _5 = obj_2(D) < &MEM <char[1000000]> [(void *)&pure + 1000000B];
  _6 = obj_2(D) >= &pure;
  _7 = _5 & _6;

pure2:
  obj.2_1 = (long unsigned int) obj_5(D);
  pure.3_2 = (long unsigned int) &pure;
  _3 = obj.2_1 - pure.3_2;
  _4 = _3 <= 1000000;

pure3:
  _1 = obj_4(D) - &pure;
  _2 = (long unsigned int) _1;
  _3 = _2 <= 1000000;

We should be able to convert pure0 and pure1 into pure3 really.

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

* [Bug tree-optimization/51084] bounds checking not optimized to a single comparison
  2011-11-10 17:43 [Bug c/51084] New: bounds checking not optimized to a single comparison eggert at gnu dot org
                   ` (2 preceding siblings ...)
  2021-07-26 19:39 ` pinskia at gcc dot gnu.org
@ 2021-11-24  5:10 ` pinskia at gcc dot gnu.org
  2024-02-18  8:18 ` eggert at cs dot ucla.edu
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-24  5:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(simplify
 (bit_and:c (lt @0 ADDR_EXPR@1) (ge @0 ADDR_EXPR@2))
 (with { poly_int64 diff; }
  (if (ptr_difference_const (@2, @1, &diff))
   (le (pointer_diff:ssizetype .....


I will implement this for GCC 13.

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

* [Bug tree-optimization/51084] bounds checking not optimized to a single comparison
  2011-11-10 17:43 [Bug c/51084] New: bounds checking not optimized to a single comparison eggert at gnu dot org
                   ` (3 preceding siblings ...)
  2021-11-24  5:10 ` pinskia at gcc dot gnu.org
@ 2024-02-18  8:18 ` eggert at cs dot ucla.edu
  4 siblings, 0 replies; 6+ messages in thread
From: eggert at cs dot ucla.edu @ 2024-02-18  8:18 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Eggert <eggert at cs dot ucla.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eggert at cs dot ucla.edu

--- Comment #4 from Paul Eggert <eggert at cs dot ucla.edu> ---
I still see the problem with gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6) on
x86-64.

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

end of thread, other threads:[~2024-02-18  8:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-10 17:43 [Bug c/51084] New: bounds checking not optimized to a single comparison eggert at gnu dot org
2011-11-11  0:48 ` [Bug middle-end/51084] " pinskia at gcc dot gnu.org
2012-01-07 22:40 ` [Bug tree-optimization/51084] " pinskia at gcc dot gnu.org
2021-07-26 19:39 ` pinskia at gcc dot gnu.org
2021-11-24  5:10 ` pinskia at gcc dot gnu.org
2024-02-18  8:18 ` eggert at cs dot ucla.edu

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