[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 02:40:22 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:

It'd be tricky as its the TRUNC user node that implies the min leading sign/zero count on the source node, not the source node itself. So we'd have to check for users of a node and retroactively adjust the analysis.

I'll do some experiments but I'm not confident

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


More information about the llvm-commits mailing list