[llvm] [LegalizeVectorTypes] Don't emit VP_SELECT when widening MLOAD to VP_LOAD (PR #179478)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 3 06:54:56 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-selectiondag

Author: Luke Lau (lukel97)

<details>
<summary>Changes</summary>

This is part of the work to remove trivial VP intrinsics.

When widening an MLOAD we may use a VP_LOAD if it's supported. We use a VP_SELECT to merge in the passthru, but we don't check if it's supported by the target. This changes it to just emit a regular VSELECT instead to prevent crashing in that case.

The regression in masked-load-int.ll shouldn't matter in practice because a store or reduction will cause RISCVVectorPeephole to reduce the VL.


---
Full diff: https://github.com/llvm/llvm-project/pull/179478.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp (+2-3) 
- (modified) llvm/test/CodeGen/RISCV/rvv/masked-load-int.ll (+4-2) 


``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
index 4db9c5d009ae8..41c96296533fb 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -6604,11 +6604,10 @@ SDValue DAGTypeLegalizer::WidenVecRes_MLOAD(MaskedLoadSDNode *N) {
                       N->getMemoryVT(), N->getMemOperand());
     SDValue NewVal = NewLoad;
 
-    // Manually merge with vp.select
+    // Manually merge with vselect
     if (!N->getPassThru()->isUndef()) {
       assert(WidenVT.isScalableVector());
-      NewVal =
-          DAG.getNode(ISD::VP_SELECT, dl, WidenVT, Mask, NewVal, PassThru, EVL);
+      NewVal = DAG.getNode(ISD::VSELECT, dl, WidenVT, Mask, NewVal, PassThru);
     }
 
     // Modified the chain - switch anything that used the old chain to use
diff --git a/llvm/test/CodeGen/RISCV/rvv/masked-load-int.ll b/llvm/test/CodeGen/RISCV/rvv/masked-load-int.ll
index 40b906a481daa..2620e78c72400 100644
--- a/llvm/test/CodeGen/RISCV/rvv/masked-load-int.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/masked-load-int.ll
@@ -34,9 +34,11 @@ define <vscale x 1 x i8> @masked_load_passthru_nxv1i8(ptr %a, <vscale x 1 x i1>
 ; ZVE32:       # %bb.0:
 ; ZVE32-NEXT:    csrr a1, vlenb
 ; ZVE32-NEXT:    srli a1, a1, 3
-; ZVE32-NEXT:    vsetvli zero, a1, e8, mf4, ta, mu
-; ZVE32-NEXT:    vmv.v.i v8, 0
+; ZVE32-NEXT:    vsetvli zero, a1, e8, mf4, ta, ma
 ; ZVE32-NEXT:    vle8.v v8, (a0), v0.t
+; ZVE32-NEXT:    vsetvli a0, zero, e8, mf4, ta, ma
+; ZVE32-NEXT:    vmv.v.i v9, 0
+; ZVE32-NEXT:    vmerge.vvm v8, v9, v8, v0
 ; ZVE32-NEXT:    ret
   %load = call <vscale x 1 x i8> @llvm.masked.load.nxv1i8(ptr %a, i32 1, <vscale x 1 x i1> %mask, <vscale x 1 x i8> zeroinitializer)
   ret <vscale x 1 x i8> %load

``````````

</details>


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


More information about the llvm-commits mailing list