STINNER Victor added the comment:

If I understood correctly, the optimization proposed by Antoine was somehow 
rejected because _PyLong_IS_SMALL_INT() may be optimized "incorrectly".

If a compiler "miscompiles" this macro, can't we disable this optimization on 
this specific compiler, instead of missing an interesting optimization on all 
compilers? I bet that no compiler will do insane optimization on such test.

Where in CPython source code do we use directly references to small_ints? The 
common case is to write PyLong_FromLong(0). Can compiler call PyLong_FromLong() 
to detect that the result is part of the small_ints array? Or that it is not 
part of small_ints?

The corner case is very unlikely to me.

--

I tested Antoine's patch with GCC 4.6 and CFLAGS="-O3 -flto" (-flto: standard 
link-time optimizer): the test suite pass. I don't see any magic optimization 
here, sorry.

--

"fwiw I've always found this helpful for undefined behavior: 
http://blog.regehr.org/archives/213 and, just as it says "x+1 > x" will be 
optimized to a nop, by the same logic "v >= &array[0] && v < &array[array_len]" 
will also be optimized to a nop."

"x+1 > x" and "v >= &array[0]" are not the same checks. In the first test, x is 
used in both parts. I don't understand.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10044>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to