[llvm] [AArch64] - Improve costing for Identity shuffles for SVE targets. (PR #165375)

Pawan Nirpal via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 28 05:12:42 PDT 2025


pawan-nirpal-031 wrote:

This costing change allows for aggressive vector combines via identity shuffles. The following diff demonstrates this. Sorry I don't have a prettier diff :) 
```
<   %mul58 = mul nuw nsw <16 x i32> %zext57, splat (i32 19595)
118d116
<   %mul60 = mul nuw nsw <16 x i32> %zext59, splat (i32 38470)
120,133d117
<   %mul62 = mul nuw nsw <16 x i32> %zext61, splat (i32 7471)
<   %add63 = add nuw nsw <16 x i32> %mul58, splat (i32 32768)
<   %add64 = add nuw nsw <16 x i32> %add63, %mul60
<   %add65 = add nuw nsw <16 x i32> %add64, %mul62
<   %lshr = lshr <16 x i32> %add65, splat (i32 16)
<   %trunc66 = trunc nuw <16 x i32> %lshr to <16 x i8>
<   %mul67 = mul nuw nsw <16 x i32> %zext57, splat (i32 32767)
<   %mul68 = mul nuw <16 x i32> %zext59, splat (i32 16762097)
<   %mul69 = mul nuw <16 x i32> %zext61, splat (i32 16759568)
<   %add70 = add nuw nsw <16 x i32> %mul67, splat (i32 32768)
<   %add71 = add nuw <16 x i32> %add70, %mul68
<   %add72 = add <16 x i32> %add71, %mul69
<   %lshr73 = lshr <16 x i32> %add72, splat (i32 16)
<   %trunc74 = trunc <16 x i32> %lshr73 to <16 x i8>
142c126,136
<   %shufflevector83 = shufflevector <16 x i8> %trunc66, <16 x i8> %trunc74, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
---
>   %0 = shufflevector <16 x i32> %zext57, <16 x i32> %zext57, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
>   %1 = mul nuw nsw <32 x i32> %0, <i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767>
>   %2 = add nuw nsw <32 x i32> %1, splat (i32 32768)
>   %3 = shufflevector <16 x i32> %zext59, <16 x i32> %zext59, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
>   %4 = mul nuw <32 x i32> %3, <i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097>
>   %5 = add nuw <32 x i32> %2, %4
>   %6 = shufflevector <16 x i32> %zext61, <16 x i32> %zext61, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
>   %7 = mul nuw <32 x i32> %6, <i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568>
>   %8 = add <32 x i32> %5, %7
>   %9 = lshr <32 x i32> %8, splat (i32 16)
>   %shufflevector83 = trunc <32 x i32> %9 to <32 x i8>
184d177
<   %mul116 = mul nuw nsw <8 x i32> %zext115, splat (i32 19595)
186d178
<   %mul118 = mul nuw nsw <8 x i32> %zext117, splat (i32 38470)
188,201d179
<   %mul120 = mul nuw nsw <8 x i32> %zext119, splat (i32 7471)
<   %add121 = add nuw nsw <8 x i32> %mul116, splat (i32 32768)
<   %add122 = add nuw nsw <8 x i32> %add121, %mul118
<   %add123 = add nuw nsw <8 x i32> %add122, %mul120
<   %lshr124 = lshr <8 x i32> %add123, splat (i32 16)
<   %trunc125 = trunc nuw <8 x i32> %lshr124 to <8 x i8>
<   %mul126 = mul nuw nsw <8 x i32> %zext115, splat (i32 32767)
<   %mul127 = mul nuw <8 x i32> %zext117, splat (i32 16762097)
<   %mul128 = mul nuw <8 x i32> %zext119, splat (i32 16759568)
<   %add129 = add nuw nsw <8 x i32> %mul126, splat (i32 32768)
<   %add130 = add nuw <8 x i32> %add129, %mul127
<   %add131 = add <8 x i32> %add130, %mul128
<   %lshr132 = lshr <8 x i32> %add131, splat (i32 16)
<   %trunc133 = trunc <8 x i32> %lshr132 to <8 x i8>
210c188,198
<   %shufflevector142 = shufflevector <8 x i8> %trunc125, <8 x i8> %trunc133, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
---
>   %10 = shufflevector <8 x i32> %zext115, <8 x i32> %zext115, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
>   %11 = mul nuw nsw <16 x i32> %10, <i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 19595, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767, i32 32767>
>   %12 = add nuw nsw <16 x i32> %11, splat (i32 32768)
>   %13 = shufflevector <8 x i32> %zext117, <8 x i32> %zext117, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
>   %14 = mul nuw <16 x i32> %13, <i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 38470, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097, i32 16762097>
>   %15 = add nuw <16 x i32> %12, %14
>   %16 = shufflevector <8 x i32> %zext119, <8 x i32> %zext119, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
>   %17 = mul nuw <16 x i32> %16, <i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 7471, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568, i32 16759568>
>   %18 = add <16 x i32> %15, %17
>   %19 = lshr <16 x i32> %18, splat (i32 16)
>   %shufflevector142 = trunc <16 x i32> %19 to <16 x i8>
```

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


More information about the llvm-commits mailing list