[llvm] [InstCombine] Fold bitcast into vp.load (PR #192173)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 10:22:23 PDT 2026


================
@@ -3971,6 +3971,48 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     }
     break;
   }
+  case Intrinsic::vp_load: {
+    auto *VPI = cast<VPIntrinsic>(II);
+    // Fold away bit casts of the loaded value by loading the desired type,
+    // if the mask is all-ones.
+    Value *Mask = VPI->getMaskParam();
+    Value *EVL = VPI->getVectorLengthParam();
+    if (!isa<Constant>(Mask) || !cast<Constant>(Mask)->isAllOnesValue() ||
+        !II->hasOneUse())
+      break;
+
+    const DataLayout &DL = II->getDataLayout();
+    auto *Cast = dyn_cast<CastInst>(II->user_back());
+    if (!Cast || !Cast->isNoopCast(DL) || !isa<VectorType>(Cast->getDestTy()))
+      break;
+    VectorType *OrigVecTy = cast<VectorType>(II->getType());
+    Align OrigAlign =
+        DL.getValueOrABITypeAlignment(VPI->getPointerAlignment(), OrigVecTy);
+    ElementCount OrigVecCnt = OrigVecTy->getElementCount();
+    VectorType *NewVecTy = cast<VectorType>(Cast->getDestTy());
+    ElementCount NewVecCnt = NewVecTy->getElementCount();
+
+    // Right now we only support cases where
+    // the NewVec is longer, because for cases where
+    // it's shorter, we have to be sure that EVL can be
+    // exactly divided, otherwise it might page fault / yield
+    // incorrect results.
----------------
mshockwave wrote:

Oops, it's fixed now.

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


More information about the llvm-commits mailing list