[llvm] 683a9ac - [X86] combineVectorPack - use APInt::truncSSat for PACKSS constant folding. NFC.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 10:10:43 PDT 2024


Author: Simon Pilgrim
Date: 2024-03-12T17:10:27Z
New Revision: 683a9ac803a56f6dda9b783a6e2d6d92a5d0626c

URL: https://github.com/llvm/llvm-project/commit/683a9ac803a56f6dda9b783a6e2d6d92a5d0626c
DIFF: https://github.com/llvm/llvm-project/commit/683a9ac803a56f6dda9b783a6e2d6d92a5d0626c.diff

LOG: [X86] combineVectorPack - use APInt::truncSSat for PACKSS constant folding. NFC.

Unfortunately PACKUS can't use APInt::truncUSat

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86ISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index b4d0421c14c0b6..72b45d462dfee2 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -47630,16 +47630,12 @@ static SDValue combineVectorPack(SDNode *N, SelectionDAG &DAG,
           // PACKSS: Truncate signed value with signed saturation.
           // Source values less than dst minint are saturated to minint.
           // Source values greater than dst maxint are saturated to maxint.
-          if (Val.isSignedIntN(DstBitsPerElt))
-            Val = Val.trunc(DstBitsPerElt);
-          else if (Val.isNegative())
-            Val = APInt::getSignedMinValue(DstBitsPerElt);
-          else
-            Val = APInt::getSignedMaxValue(DstBitsPerElt);
+          Val = Val.truncSSat(DstBitsPerElt);
         } else {
           // PACKUS: Truncate signed value with unsigned saturation.
           // Source values less than zero are saturated to zero.
           // Source values greater than dst maxuint are saturated to maxuint.
+          // NOTE: This is 
diff erent from APInt::truncUSat.
           if (Val.isIntN(DstBitsPerElt))
             Val = Val.trunc(DstBitsPerElt);
           else if (Val.isNegative())


        


More information about the llvm-commits mailing list