[llvm] [Matrix] Propagate shape information through cast insts (PR #141869)
Jon Roelofs via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 5 14:10:51 PDT 2025
================
@@ -2198,6 +2230,37 @@ class LowerMatrixIntrinsics {
return true;
}
+ /// Lower cast instructions, if shape information is available.
+ bool VisitCastInstruction(CastInst *Inst) {
+ auto I = ShapeMap.find(Inst);
+ if (I == ShapeMap.end())
+ return false;
+
+ Value *Op = Inst->getOperand(0);
+
+ IRBuilder<> Builder(Inst);
+ ShapeInfo &Shape = I->second;
+
+ MatrixTy Result;
+ MatrixTy M = getMatrix(Op, Shape, Builder);
+
+ Builder.setFastMathFlags(getFastMathFlags(Inst));
+
+ auto *OrigVTy = cast<VectorType>(Inst->getType());
+ auto *NewVTy = VectorType::get(OrigVTy->getElementType(),
+ ElementCount::getFixed(M.getStride()));
+
+ for (unsigned I = 0; I < Shape.getNumVectors(); ++I)
+ Result.addVector(
+ Builder.CreateCast(Inst->getOpcode(), M.getVector(I), NewVTy));
+
+ finalizeLowering(Inst,
+ Result.addNumComputeOps(getNumOps(Result.getVectorTy()) *
+ Result.getNumVectors()),
+ Builder);
----------------
jroelofs wrote:
let's do that in a separate PR after the rest of these have landed. I think we'll want the Visit* to return MatrixTy, and it'll be easier to do that refactor all at once, rather than add yet another conflict I'll have to resolve on each patch.
https://github.com/llvm/llvm-project/pull/141869
More information about the llvm-commits
mailing list