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: unassig...@gcc.gnu.org ReportedBy: egg...@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.