[llvm] [AArch64][CostModel] Improve cost estimate of scalarizing a vector di… (PR #118055)

Sushant Gokhale via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 05:07:24 PST 2025


sushgokh wrote:

> The urem patch I mentioned is now in #122236.

Thanks for the patch. This serves as direction for sdiv/srem and will take this up next.

Although it resolves the motivating case, it does not resolve the generic case where Op2 is unknown. Consider below example(motivating  example modified with sdiv->udiv and divisor changed to unknowns)
```
define <2 x i32> @vectorize_udiv_v2i32(<2 x i32> %a, <2 x i32> %x, <2 x i32> %y, <2 x i32> %z)
{
  %a0 = extractelement <2 x i32> %a, i64 0
  %a1 = extractelement <2 x i32> %a, i64 1
  %1 = udiv i32 %a0, %a1
  %2 = udiv i32 %a1, %a0
  %x0 = extractelement <2 x i32> %x, i64 0
  %x1 = extractelement <2 x i32> %x, i64 1
  %3 = add i32 %1, %x0
  %4 = add i32 %2, %x1
  %y0 = extractelement <2 x i32> %y, i64 0
  %y1 = extractelement <2 x i32> %y, i64 1
  %5 = sub i32 %3, %y0
  %6 = sub i32 %4, %y1
  %z0 = extractelement <2 x i32> %z, i64 0
  %z1 = extractelement <2 x i32> %z, i64 1
  %7 = mul i32 %5, %z0
  %8 = mul i32 %6, %z1
  %res0 = insertelement <2 x i32> poison, i32 %7, i32 0
  %res1 = insertelement <2 x i32> %res0, i32 %8, i32 1
  ret <2 x i32> %res1
}
```

urem patch fails to vectorize this while this patch vectorizes this.

In summary, this patch is necessary as it refines the scalar cost. 

Last thing: I will update the motivating case as above.

https://github.com/llvm/llvm-project/pull/118055


More information about the llvm-commits mailing list