[llvm] [InstCombine] Fixing wrong select folding in vectors with undef elements (PR #102244)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 01:03:50 PDT 2024


================
@@ -1740,9 +1740,13 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
         Constant *CElt = CV->getAggregateElement(i);
         if (isa<ConstantExpr>(CElt))
           continue;
+
         // TODO: If a select condition element is undef, we can demand from
         // either side. If one side is known undef, choosing that side would
         // propagate undef.
+        if (isa<UndefValue>(CElt))
+          continue;
----------------
nikic wrote:

Instead of explicitly checking for `isa<UndefValue>`, it would be better to check `isOneValue()` for the else below. That way we do not rely on a full enumeration of possibilities. (We can also drop the ConstantExpr check above in that case.)

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


More information about the llvm-commits mailing list