llvm / llvm/llvm-project

[X86][AVX512] fabs(a) < fabs(b) ? fabs(a) : fabs(b) should lower to vrange/vminmax

Open
#206,381 7 comments 0 reactions 1 assignee Claimed by @FathimaHaris View on GitHub
backend:X86 missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125166
http://www.ecs.umass.edu/arith-2018/pdf/arith25_18.pdf

```c++
float src( float a, float b) {
return std::abs(a) < std::abs(b) ? std::abs(a) : std::abs(b);
}

__m128 tgt(__m128 a, __m128 b) {
return _mm_range_ss(a,b,10);
}

```
```asm
.LCPI0_0:
.long 0x7fffffff
src(float, float):
vbroadcastss xmm2, dword ptr [rip + .LCPI0_0]
vandps xmm0, xmm0, xmm2
vandps xmm1, xmm1, xmm2
vminss xmm0, xmm0, xmm1
ret

tgt(float vector[4], float vector[4]):
vrangess xmm0, xmm0, xmm1, 10
ret
```
https://godbolt.org/z/xeeY5qMEv

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.