https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115659
--- Comment #8 from Kewen Lin <linkw at gcc dot gnu.org> --- Inspired by Andrew's comments, it looks we can have: c = x CMP y r = c ? 0 : z => r = ~c & z (1) r = c ? z : 0 => r = c & z (2) r = c ? -1 : z => r = c | z (3) r = c ? z : -1 => r = ~c | z (4) so if target supports vector "or" and "and", (2)(3) is clearly an improvement (basic logical operation should not be slower than vector select), (1)(4) may need further cost comparison (or if target supports the compound operation then query with optab support).