Why isn't minmax branchless?

Yes, that’s why we have SIMD library. You can hardcode SIMD code by yourself, which is not a good idea definitely. That’s why we have vectorization pass in compiler to do this automatically. You might ask whether it’s possible to give some hints to compiler that the code should be branchless. But the problem is that there are many ways to be branchless. You might indicate a suboptimal solution, just like the minmax example (it’s branchless, but not vectorized).

Instead, I think we should just define Base.ifelse only on a constraint set of types (Int,Float64,NTuple{4,Int}…). Base.ifelse acts like vifelse in the SIMD libraries. It provides no further function than ? : and is used only for optimization. It’s not generic by design (it lowers to select and not all the values can be the operands of select). Misuse of this function can hurt performance, since Julia’s frontend compiler isn’t aware of this function (thus does no special optimization) and lowering to select early might block further vectorization, as seen by the minmax example.