[llvm] [X86] Add vXi64 MULHU lowering, keeping full-width products scalar (PR #206983)

Rito Takeuchi via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 2 17:01:13 PDT 2026


Licht-T wrote:

@Andarwinux @phoebewang  Re-taken on the same EC2 metal instances with https://github.com/llvm/llvm-project/pull/169819, each binary now built with the target's own `-march`/`-mtune` (turbo off, pinned core):

| microarch | CPU | EC2 instance type |
|---|---|---|
| Skylake/Cascade Lake | Xeon Platinum 8275CL | `c5.metal` |
| Ice Lake-SP | Xeon Platinum 8375C | `c6i.metal` |
| Sapphire Rapids (SPR) | Xeon Platinum 8488C | `c7i.metal-24xl` |
| Zen 4 / Genoa | EPYC 9R14 | `c7a.metal-48xl` |

## Summary

- **`MULHU` (unsigned div) is a clean win** everywhere: **1.66 - 2.15x**, unchanged.
- **`MULHS` (signed div) is now a win on AVX-512 across every microarch** once tuned for the target: Cascade **1.18 - 1.22x**, Ice Lake **1.25 - 1.31x**, SPR **1.31x**, Zen 4 **2.04 - 2.11x**.
- **AVX2** signed `div` regresses on Intel (0.75 - 0.82x): with no AVX512DQ the `MULHS` schoolbook (`vpmuludq`) loses to scalar, so `MULHS` vectorization should stay **AVX512DQ-gated**.
- **`wyhash` (full-128) still regresses** here (0.6 - 0.9x) because both halves of the wide product are used: the high half is vectorized while the low half still needs the full multiply. This is exactly what the `UMUL_LOHI`/`SMUL_LOHI` guard in this PR fixes (keeps it scalar → ~1.0x).

## Results

Numbers are ns/elem, `stock → patched (ratio)`, higher ratio = faster.

**Result 1. MULHU** - `uint64 / constant`:

| build | Cascade | Ice Lake | SPR | Zen 4 |
|---|---|---|---|---|
| AVX2 | 1.098→0.623 (1.76x) | 0.954→0.576 (1.66x) | 0.948→0.498 (1.90x) | 0.580→0.270 (2.15x) |
| AVX-512 256b | 1.099→0.644 (1.71x) | 0.955→0.557 (1.71x) | 0.965→0.543 (1.78x) | 0.555→0.295 (1.88x) |
| AVX-512 512b | 1.097→0.604 (1.82x) | 0.955→0.558 (1.71x) | 0.965→0.543 (1.78x) | 0.554→0.313 (1.77x) |

**Result 2. MULHS** — `int64 / constant`:

| build | Cascade | Ice Lake | SPR | Zen 4 |
|---|---|---|---|---|
| AVX2 | 1.058→1.291 (**0.82x**) | 0.964→1.279 (**0.75x**) | 0.942→1.210 (**0.78x**) | 0.731→0.610 (1.20x) |
| AVX-512 256b | 1.057→0.898 (1.18x) | 0.964→0.772 (1.25x) | 0.940→0.717 (1.31x) | 0.724→0.355 (2.04x) |
| AVX-512 512b | 1.057→0.863 (1.22x) | 0.963→0.737 (1.31x) | 0.941→0.717 (1.31x) | 0.719→0.340 (2.11x) |

**Result 3. full-128** : `wyhash` `lo ^ hi` (both halves used; **without** the guard):

| build | Cascade | Ice Lake | SPR | Zen 4 |
|---|---|---|---|---|
| AVX2 | 1.599→2.142 (0.75x) | 1.253→1.837 (0.68x) | 1.145→1.818 (0.63x) | 0.806→1.062 (0.76x) |
| AVX-512 256b | 1.482→2.016 (0.74x) | 1.178→1.839 (0.64x) | 1.137→1.831 (0.62x) | 0.811→1.159 (0.70x) |
| AVX-512 512b | 1.789→2.268 (0.79x) | 1.677→1.928 (0.87x) | 1.963→2.167 (0.91x) | 0.772→1.117 (0.69x) |

**Result 4. FP register-pressure**: 14 live `<4 x double>` accumulators + one integer `/C`, AVX-512 256b, `stock → patched (ratio)`. c0 = no call; c1 = a register-clobbering call each iter:

| µarch | c0 (no call) | c1 (with call) |
|---|---|---|
| Cascade | 1.069→1.029 (1.04x) | 3.002→2.429 (1.24x) |
| Ice Lake | 0.956→0.983 (0.97x) | 1.985→1.999 (0.99x) |
| SPR | 1.101→1.256 (0.88x) | 2.509→2.421 (1.04x) |
| Zen 4 | 0.752→0.654 (1.15x) | 1.579→2.091 (0.76x) |

**Result 5. FP register-pressure (Original concern 2)**: 20-run medians, turbo off 14 live `<4 x double>` accumulators + one integer dividing with constant. ns `stock → patched (ratio)`. c0 = no call; c1 = a register-clobbering call each iteration (caller-saved spill).

| µarch | build | c0 (no call) | c1 (with call) |
|---|---|---|---|
| SPR| AVX2 (16 vec regs) | 1.612→2.040 (0.79x) | 2.655→3.247 (0.82x) |
| SPR | AVX-512 256b (32 regs) | 1.097→1.184 (0.93x) | 1.991→2.129 (0.94x) |
| SPR | AVX-512 512b (32 regs) | 1.097→1.184 (0.93x) | 2.252→2.532 (0.89x) |
| Cascade Lake | AVX2 (16 vec regs) | 1.571→1.748 (0.90x) | 2.846→3.171 (0.90x) |
| Cascade Lake | AVX-512 256b (32 regs) | 1.030→1.238 (0.83x) | 3.038→3.037 (1.00x) |
| Cascade Lake | AVX-512 512b (32 regs) | 1.030→1.242 (0.83x) | 3.040→2.949 (1.03x) |

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


More information about the llvm-commits mailing list