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

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 03:26:44 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()) {
----------------
RKSimon wrote:

First thing I've noticed - as soon as the ISD::TRUNCATE node disappears we lose this extra analysis on the upper bits of the source node, which is acceptable for the x86 PACK nodes, but might not be for other nodes that were relying on access to that information?

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


More information about the llvm-commits mailing list