https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104360
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Severity|normal |enhancement Summary|Failure to optimize abs |Failure to optimize abs |pattern on vector types |pattern (x^(x<0?-1:0)) - | |(x<0?-1:0) Keywords| |missed-optimization Last reconfirmed| |2022-02-03 Status|UNCONFIRMED |NEW --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Even the scalar version is not optimized: typedef short i16; i16 abs_i16(i16 x) { auto isN = -(x < 0); x ^= isN; return x - isN; } Shouldn't be too hard to optimize for both. What is funny is clang/LLVM does not catch the scalar version either unless you do: (x < i16{}) ? -1 : 0