Better HN
topnewbestaskshowjobs
Log inSign up

ospr3y

1 karma · joined Jan 10, 2020 (6y ago) · 1 submissions

Submissions

comment 6y ago · link · parent

As a compiler writer I can tell you that this is a complex optimisation with very limited use.

N.B. the || (logical or) operator is an "early out" operator whereas the | (binary or) operator is NOT

The compiler would need to look for special cases of value1, value2 and value3... such as: are any of them volatile, perhaps one refers to a memory mapped I/O device, perhaps one if actually a function call, or array dereference, or pointer dereference, what about value1 being a "char" which needs to be promoted before it can be or'd, what about any of the "values" being a constant < 0 which would short circuit the "if" statement and remove the need for any tests.

As I said, this is not as simple as it first appears.