[llvm] [LV][VPlan] Add initial support for CSA vectorization (PR #106560)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 22 13:20:06 PST 2024
================
@@ -649,6 +652,57 @@ Value *VPInstruction::generate(VPTransformState &State) {
Value *A = State.get(getOperand(0));
return Builder.CreateOrReduce(A);
}
+ case VPInstruction::AnyOfEVL: {
+ Value *WidenedCond = State.get(getOperand(0));
+ Value *AllOnesMask = Constant::getAllOnesValue(
+ VectorType::get(Type::getInt1Ty(State.Builder.getContext()), State.VF));
+ Value *EVL = State.get(getOperand(1), /*NeedsScalar=*/true);
+
+ Value *StartValue =
+ ConstantInt::get(WidenedCond->getType()->getScalarType(), 0);
+ Value *AnyOf = State.Builder.CreateIntrinsic(
+ WidenedCond->getType()->getScalarType(), Intrinsic::vp_reduce_or,
+ {StartValue, WidenedCond, AllOnesMask, EVL}, nullptr, "any.active");
+ return AnyOf;
+ }
+ case VPInstruction::CSAMaskPhi: {
+ BasicBlock *PreheaderBB = State.CFG.getPreheaderBBFor(this);
+ Value *InitMask = State.get(getOperand(0));
+ PHINode *MaskPhi =
+ State.Builder.CreatePHI(InitMask->getType(), 2, "csa.mask.phi");
+ MaskPhi->addIncoming(InitMask, PreheaderBB);
+ State.set(this, MaskPhi);
+ return MaskPhi;
+ }
+ case VPInstruction::CSAMaskSel: {
+ Value *WidenedCond = State.get(getOperand(0));
+ Value *MaskPhi = State.get(getOperand(1));
+ Value *AnyOf = State.get(getOperand(2), /*NeedsScalar=*/true);
+ Value *MaskSel =
+ State.Builder.CreateSelect(AnyOf, WidenedCond, MaskPhi, "csa.mask.sel");
+ cast<PHINode>(MaskPhi)->addIncoming(MaskSel, State.CFG.PrevBB);
+ return MaskSel;
+ }
+ case VPInstruction::CSAVLPhi: {
+ IRBuilder<>::InsertPointGuard Guard(State.Builder);
+ State.Builder.SetInsertPoint(State.CFG.PrevBB->getFirstNonPHI());
+ BasicBlock *PreheaderBB = State.CFG.getPreheaderBBFor(this);
+
+ // InitVL can be anything since it won't be used if no mask was active
+ Value *InitVL = ConstantInt::get(State.Builder.getInt32Ty(), 0);
+ PHINode *VLPhi =
+ State.Builder.CreatePHI(InitVL->getType(), 2, "csa.vl.phi");
+ VLPhi->addIncoming(InitVL, PreheaderBB);
+ return VLPhi;
+ }
+ case VPInstruction::CSAVLSel: {
+ Value *AnyOf = State.get(getOperand(0), /*NeedsScalar=*/true);
+ Value *VLPhi = State.get(getOperand(1), /*NeedsScalar=*/true);
+ Value *EVL = State.get(getOperand(2), /*NeedsScalar=*/true);
+ Value *VLSel = State.Builder.CreateSelect(AnyOf, EVL, VLPhi, "csa.vl.sel");
+ cast<PHINode>(VLPhi)->addIncoming(VLSel, State.CFG.PrevBB);
----------------
fhahn wrote:
Why do we have to update the IR for one of the operands here? Can we not update the incoming values like for other phi recipes?
Then we could use regular select?
https://github.com/llvm/llvm-project/pull/106560
More information about the llvm-commits
mailing list