[llvm] [InstCombine] Simplify demanded bits of blendv mask operands (PR #173723)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 27 07:04:41 PST 2025


================
@@ -2870,11 +2870,31 @@ X86TTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
   case Intrinsic::x86_avx_blendv_ps_256:
   case Intrinsic::x86_avx_blendv_pd_256:
   case Intrinsic::x86_avx2_pblendvb: {
+
+    Value *Mask = II.getArgOperand(2);
+
+    unsigned BitWidth = Mask->getType()->getScalarSizeInBits();
+    KnownBits Known(BitWidth);
+
+    if (Mask->getType()->isIntOrIntVectorTy()) {
+      if (IC.SimplifyDemandedBits(&II, 2, APInt::getSignMask(BitWidth), Known))
+        return ⅈ
+    }
+
+    else if (auto *BC = dyn_cast<BitCastInst>(Mask)) {
+      Value *Src = BC->getOperand(0);
+      if (Src->getType()->isIntOrIntVectorTy()) {
+        unsigned SrcBitWidth = Src->getType()->getScalarSizeInBits();
+        KnownBits KnownSrc(SrcBitWidth);
+        if (IC.SimplifyDemandedBits(BC, 0, APInt::getSignMask(SrcBitWidth),
+                                    KnownSrc))
+          return &II;
+      }
+    }
----------------
RKSimon wrote:

SimplifyDemandedBits can be expensive - probably best if all of this is put further down after the constant folding - line 2913 (ish) before the peekThroughBitcast call. 

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


More information about the llvm-commits mailing list