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

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 28 07:19:49 PST 2025


================
@@ -2890,7 +2890,24 @@ X86TTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
           getNegativeIsTrueBoolVec(ConstantMask, IC.getDataLayout());
       return SelectInst::Create(NewSelector, Op1, Op0, "blendv");
     }
+    unsigned BitWidth = Mask->getType()->getScalarSizeInBits();
 
+    if (Mask->getType()->isIntOrIntVectorTy()) {
+      KnownBits Known(BitWidth);
+      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();
+        if (SrcBitWidth == BitWidth) {
----------------
RKSimon wrote:

@Xylecrack Just noticed that we can't do this if Mask had multiple uses - please can you add a `Mask->hasOneUse()` check and a negative test.

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


More information about the llvm-commits mailing list