[llvm] [X86] Use NSW/NUW flags on ISD::TRUNCATE nodes to improve X86 PACKSS/PACKUS lowering (PR #123956)

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 19:17:03 PST 2025


================
@@ -20865,7 +20866,8 @@ static SDValue matchTruncateWithPACK(unsigned &PackOpcode, EVT DstVT,
   // e.g. Masks, zext_in_reg, etc.
   // Pre-SSE41 we can only use PACKUSWB.
   KnownBits Known = DAG.computeKnownBits(In);
-  if ((NumSrcEltBits - NumPackedZeroBits) <= Known.countMinLeadingZeros()) {
+  if ((Flags.hasNoUnsignedWrap() && NumDstEltBits <= NumPackedZeroBits) ||
+      (NumSrcEltBits - NumPackedZeroBits) <= Known.countMinLeadingZeros()) {
----------------
phoebewang wrote:

Can we take `NSW/NUW` into account when `countMinLeadingZeros/ComputeNumSignBits` so that other cases may benefit from it?

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


More information about the llvm-commits mailing list