[llvm] [LLVM][InstCombine] Extend masked_gather's demanded elt analysis. (PR #151732)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 1 12:48:06 PDT 2025


================
@@ -1834,14 +1834,22 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
       // segfaults which didn't exist in the original program.
       APInt DemandedPtrs(APInt::getAllOnes(VWidth)),
           DemandedPassThrough(DemandedElts);
-      if (auto *CV = dyn_cast<ConstantVector>(II->getOperand(2)))
-        for (unsigned i = 0; i < VWidth; i++) {
-          Constant *CElt = CV->getAggregateElement(i);
-          if (CElt->isNullValue())
-            DemandedPtrs.clearBit(i);
-          else if (CElt->isAllOnesValue())
-            DemandedPassThrough.clearBit(i);
+      if (auto *CMask = dyn_cast<Constant>(II->getOperand(2))) {
----------------
nikic wrote:

I think an alternative would be to replace `dyn_cast<ConstantVector>` with `dyn_cast<Constant>`? Less efficient, but simpler.

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


More information about the llvm-commits mailing list