| Issue |
244603
|
| Summary |
[SLP] Bounding box of points: vectorized loop with blends is 1.65x slower than scalar min/max (regression since clang 15)
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
Fedr
|
Compiler Explorer (clang 14 vs 22.1, `-O2`): https://godbolt.org/z/a1PrjzTqc
```cpp
struct Vec3 { float x, y, z; };
struct Point { Vec3 coord; int id; };
struct Box
{
Vec3 min{ 3.4e38f, 3.4e38f, 3.4e38f }, max{ -3.4e38f, -3.4e38f, -3.4e38f };
void include( const Vec3 & p )
{
min.x = p.x < min.x ? p.x : min.x; max.x = p.x > max.x ? p.x : max.x;
min.y = p.y < min.y ? p.y : min.y; max.y = p.y > max.y ? p.y : max.y;
min.z = p.z < min.z ? p.z : min.z; max.z = p.z > max.z ? p.z : max.z;
}
};
Box boxOf( const Point * p, int n )
{
Box b;
for ( int i = 0; i < n; ++i )
b.include( p[i].coord );
return b;
}
```
Since clang 15 (`-O2`, x86-64; AArch64 with clang 22 does the same), SLP packs `min.x, min.y, min.z, max.x` into one vector, so the loop does `cmpltps` + `andps/andnps/orps` blends and several `shufps` per point in a chain carried from one iteration to the next. clang 14 emitted six independent `minss`/`maxss`. With 2^20 points, `boxOf` takes 2.21 ms vs 1.33 ms with `-fno-slp-vectorize` (clang 22.1.7, Ryzen 9 3900X); on Apple M1 Pro the same pattern in a larger function was 56% slower than the scalar code.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs