[X86] Recognise VPMADD52H pattern via LowerMULH for the 52-bit case
Follow-up to #153787 (PR #236663).
Context
PR #236663 implements VPMADD52H matching for the restricted case where
x * y < 2^64 — i.e., mulhu(x, y) == 0. This covers inputs up to ~32
bits and folds add(lshr(mul(x, y), 52), acc) to vpmadd52huq.
The broader case — inputs up to 52 bits, product up to 104 bits — would need to match:
add(or(shl(mulhu(x, y), 12), shr(mullo(x, y), 52)), acc)
Why it's not in the original PR
As noted by @Andarwinux in the PR review, this shape doesn't survive to combineAdd on x86:
vXi64 MULHUis markedExpandand scalarizes into per-lanemulqduring operation legalization, before DAG combining runs.- The
or(shl, shr)shape never appears as a vector node in the DAG. - A matcher for the scalarized form would be fragile and highly dependent on legalizer decisions.
Suggested approach
LowerMULH custom lowering for vXi64 — mark ISD::MULHU as Custom
for v2i64/v4i64/v8i64 and emit a vector sequence using vpmuludq chains.
This would let the node survive as a proper vector op, enabling either:
- A
combineAddmatcher for the fullor(shl(mulhu, 12), shr(mullo, 52))pattern, or - Direct recognition in
LowerMULHitself when the surrounding add-shift-or shape matches.
Relation to existing work
- #206983 added vXi64 MULHU/MULHS lowering via
forceExpandMultiply— worth building on. - #169819 (RKSimon) explored this territory previously.
Testing
Would need vector tests exercising:
- Full 52-bit inputs (product in 104 bits)
- Negative cases (inputs not provably <=52 bits)
- Per-lane scalarization avoidance checks
@llvm/issue-subscribers-backend-x86
Author: Sangam Paudel (sangam151)
Context
PR #236663 implements VPMADD52H matching for the restricted case where
x * y < 2^64 — i.e., mulhu(x, y) == 0. This covers inputs up to ~32
bits and folds add(lshr(mul(x, y), 52), acc) to vpmadd52huq.
The broader case — inputs up to 52 bits, product up to 104 bits — would need to match:
add(or(shl(mulhu(x, y), 12), shr(mullo(x, y), 52)), acc)
Why it's not in the original PR
As noted by @RKSimon in the PR review, this shape doesn't survive to combineAdd on x86:
vXi64 MULHUis markedExpandand scalarizes into per-lanemulqduring operation legalization, before DAG combining runs.- The
or(shl, shr)shape never appears as a vector node in the DAG. - A matcher for the scalarized form would be fragile and highly dependent on legalizer decisions.
Suggested approach
LowerMULH custom lowering for vXi64 — mark ISD::MULHU as Custom
for v2i64/v4i64/v8i64 and emit a vector sequence using vpmuludq chains.
This would let the node survive as a proper vector op, enabling either:
- A
combineAddmatcher for the fullor(shl(mulhu, 12), shr(mullo, 52))pattern, or - Direct recognition in
LowerMULHitself when the surrounding add-shift-or shape matches.
Relation to existing work
- #206983 added vXi64 MULHU/MULHS lowering via
forceExpandMultiply— worth building on. - #169819 (RKSimon) explored this territory previously.
Testing
Would need vector tests exercising:
- Full 52-bit inputs (product in 104 bits)
- Negative cases (inputs not provably <=52 bits)
- Per-lane scalarization avoidance checks