https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77859
Bug ID: 77859 Summary: Ofast needed in presence of conditional code Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vincenzo.innocente at cern dot ch Target Milestone: --- It looks to me that to vectorize this code "relaxed floating point math" is not a requirement currently gcc version 7.0.0 20161004 (experimental) [trunk revision 240754] (GCC) requires Ofast and not O3 to vectorize it #include <cmath> float x[1024]; float y[1024]; void needOfast() { for (int i=0; i<1024; ++i) { constexpr float pi4 = M_PI/4.; constexpr float pi2 = M_PI/2.; auto g1 = x[i] > pi4; auto xx = x[i]; xx = g1 ? xx-pi2 : xx; auto g2 = xx > pi4; xx = g2 ? xx-pi2 : xx; y[i] = xx; } } in case anyone wonder this alternative formulation needs Ofast as well void needOfastAsWell() { for (int i=0; i<1024; ++i) { constexpr float pi = M_PI; constexpr float pi4 = M_PI/4.; constexpr float pi34 = 3.*M_PI/4.; constexpr float pi2 = M_PI/2.; auto g1 = x[i] > pi4; auto xx = x[i]; xx = g1 ? xx-pi2 : xx; auto g2 = x[i] > pi34; xx = g2 ? x[i]-pi : xx; y[i] = xx; } }