[llvm] [X86] Narrow vXi32/vXi64 usubsat to vpsubusb/vpsubusw when LHS is known to fit in fewer bits (PR #206592)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 2 13:06:45 PDT 2026


================

----------------
sipher-01 wrote:

hi @phoebewang , thanks for the feedback 
I understood the issue here and I'd like to fix this in two ways:

1.When N1 is also known to fit within NarrowBits (via computeKnownBits), skip the mask entirely — no constant, no extra register, strictly fewer instructions than today's emulation on every target.

2.When N1 doesn't fit narrow and the mask is genuinely needed, only take the narrow path where the OR can fold the mask as a broadcast memory operand (AVX512) — otherwise fall back to the existing vpmaxu+vpsub emulation.

For (2), since this lives in generic DAGCombiner, I don't have a clean way to ask "can this target fold a broadcast-OR" without a new TargetLowering hook. Would you prefer I add a small virtual function for that (defaulting to false, overridden in X86ISelLowering), or is there an existing hook/idiom you'd rather I reuse for this kind of "is this constant foldable into this op on this target" check

Alternatively, if preferred, I can skip the case 2nd case where N1 doesn't fit in the NarrowBits logic and simply use the old emulation except for the first case 

your help is appreciated  

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


More information about the llvm-commits mailing list