[llvm] [InstCombine][X86] Try to convert BLENDV(X,Y,SHL()) -> SELECT(ICMP_SGT(0,SHL()),Y,X) (PR #173389)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 24 02:06:02 PST 2025


================
@@ -2892,6 +2893,19 @@ X86TTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
 
     Mask = InstCombiner::peekThroughBitcast(Mask);
 
+    // Bitshift upto the signbit can always be converted to an efficient
+    // test+select pattern.
+    if (match(Mask, m_Shl(m_Value(), m_Value()))) {
+      if (auto *MaskTy = dyn_cast<FixedVectorType>(Mask->getType())) {
+        if (MaskTy->getScalarSizeInBits() == OpTy->getScalarSizeInBits()) {
+          Value *BoolVec = IC.Builder.CreateICmpSGT(
----------------
RKSimon wrote:

It's the expansion of the blend mask (which uses the MSB) into a regular vXi1 bool select mask. The alternative method is to shift right the MSB to LSB and then truncate, but we've done the ICMP everywhere else on this file.

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


More information about the llvm-commits mailing list