[llvm] [X86] Generate `kmov` for masking integers (PR #120593)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 05:33:42 PST 2025


================
@@ -55311,48 +55311,35 @@ static SDValue combineAVX512SetCCToKMOV(EVT VT, SDValue Op0, ISD::CondCode CC,
     return SDValue();
 
   SDValue Load = Op0.getOperand(1);
-  if (Load.getOpcode() != ISD::LOAD)
-    return SDValue();
-
-  SDValue Wrapper = Load.getOperand(1);
-  if (Wrapper.getOpcode() != X86ISD::Wrapper)
-    return SDValue();
-
-  const auto *TargetConstPool =
-      dyn_cast<ConstantPoolSDNode>(Wrapper.getOperand(0));
-  if (!TargetConstPool)
-    return SDValue();
-
-  const auto *ConstVec = TargetConstPool->getConstVal();
-  const auto *ConstVecType = dyn_cast<FixedVectorType>(ConstVec->getType());
-  if (!ConstVecType)
-    return SDValue();
+  EVT LoadVT = Load.getSimpleValueType();
 
-  const auto *First = ConstVec->getAggregateElement(0U);
-  if (llvm::isa<UndefValue>(First) || !First->getUniqueInteger().isPowerOf2())
+  APInt UndefElts;
+  SmallVector<APInt, 32> EltBits;
+  if (!getTargetConstantBitsFromNode(Load, LoadVT.getScalarSizeInBits(),
+                                     UndefElts, EltBits,
+                                     /*AllowWholeUndefs*/ true,
+                                     /*AllowPartialUndefs*/ false) ||
+      UndefElts[0] || !EltBits[0].isPowerOf2())
     return SDValue();
 
-  unsigned N = First->getUniqueInteger().logBase2();
-
-  for (unsigned I = 1, E = ConstVecType->getNumElements(); I < E; ++I) {
-    const auto *Element = ConstVec->getAggregateElement(I);
-    if (llvm::isa<llvm::UndefValue>(Element)) {
-      for (unsigned J = I + 1; J != E; ++J) {
-        if (!llvm::isa<llvm::UndefValue>(ConstVec->getAggregateElement(J)))
+  unsigned N = EltBits[0].logBase2();
+  unsigned Len = UndefElts.getBitWidth();
+  for (unsigned I = 1; I != Len; ++I) {
+    if (UndefElts[I]) {
+      for (unsigned J = I + 1; J != Len; ++J)
----------------
RKSimon wrote:

Can you use something like "UndefElts.extractBits(Len -(I + 1), I + 1).isAllOnes()" or "UndefElts.lshr(I + 1).isAllOnes()" ?

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


More information about the llvm-commits mailing list