llvm / llvm/llvm-project

[VectorCombine] failed to fold fptoui(fdiv(uitofp(x),uitofp(y))) into udiv(x,y) when target has native vector udiv

Open
#205,502 6 comments 0 reactions 1 assignee Claimed by @Xylecrack View on GitHub
llvm:vectorcombine missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/eafrhETE3
ref: https://github.com/llvm/llvm-project/issues/205305#issuecomment-4787165610
```c
typedef unsigned int u __attribute__((__vector_size__(16)));
typedef double d __attribute__((__vector_size__(32)));

u a(u x, u y){
d a = __builtin_convertvector(x, d);
d b = __builtin_convertvector(y, d);
d r = a / b;
return __builtin_convertvector(r, u);
}

u b(u x, u y){
return x / y;
}
```
```asm
a:
ushll v2.2d, v0.2s, #0
ushll v3.2d, v1.2s, #0
ushll2 v0.2d, v0.4s, #0
ushll2 v1.2d, v1.4s, #0
ucvtf v2.2d, v2.2d
ucvtf v3.2d, v3.2d
ucvtf v0.2d, v0.2d
ucvtf v1.2d, v1.2d
fdiv v2.2d, v2.2d, v3.2d
fdiv v0.2d, v0.2d, v1.2d
fcvtzu v1.2d, v2.2d
fcvtzu v0.2d, v0.2d
uzp1 v0.4s, v1.4s, v0.4s
ret

b:
ptrue p0.s, vl4
udiv z0.s, p0/m, z0.s, z1.s
ret
```

This is particularly important for vector cases, as u32->f64->u32 will halve the throughput.

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.