[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:12:18 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;
----------------
mshockwave wrote:

I thought it only checked `BitCastInst` for X86 AMX: https://github.com/llvm/llvm-project/blob/a109303236e2aef39c9abe0f3264af5fa482fe1a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp#L707

For other cases it checked `CastInst` followed by a check with `isNoopCast`: https://github.com/llvm/llvm-project/blob/a109303236e2aef39c9abe0f3264af5fa482fe1a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp#L715

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


More information about the llvm-commits mailing list