https://c.godbolt.org/z/rq43Wqc5a #include <x86intrin.h> auto adjust_splat(float x, float y, int i) { __m128 r = _mm_set1_ps(x); r[i & 3] += y; return r; } auto adjust_splat2(float x, float y, int i) { __m128 r = _mm_set1_ps(x); r[i & 3] = x + y; return r; } If the variable-index of an extract from a splatted vector is known to be inrange, we should be safe to use the original scalar directly. Not sure if this can be done in IR or we wait until SelectionDAG?
The splat removal should be in IR: https://reviews.llvm.org/D104867 I'm not seeing what we want to do with the "adjust_splat2" example?
(In reply to Sanjay Patel from comment #1) > I'm not seeing what we want to do with the "adjust_splat2" example? adjust_splat2 was just for reference to show the possible codegen if adjust_splat managed to extract the splatted value
Fixed in IR with: https://reviews.llvm.org/rG3d3c0ed9323b