[llvm] [VPlan] Explicitly handle scalar pointer inductions. (PR #83068)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 25 12:49:11 PDT 2024
================
@@ -270,10 +271,47 @@ VPInstruction::VPInstruction(unsigned Opcode,
assert(isFPMathOp() && "this op can't take fast-math flags");
}
-Value *VPInstruction::generateInstruction(VPTransformState &State,
- unsigned Part) {
+bool VPInstruction::doesGeneratePerAllLanes() const {
+ return Opcode == VPInstruction::PtrAdd && !vputils::onlyFirstLaneUsed(this);
+}
+
+bool VPInstruction::canGenerateScalarForFirstLane() const {
+ if (Instruction::isBinaryOp(getOpcode()))
+ return true;
+
+ switch (Opcode) {
+ case VPInstruction::BranchOnCond:
+ case VPInstruction::BranchOnCount:
+ case VPInstruction::CalculateTripCountMinusVF:
+ case VPInstruction::CanonicalIVIncrementForPart:
+ case VPInstruction::ComputeReductionResult:
+ case VPInstruction::PtrAdd:
+ return true;
+ default:
+ return false;
+ }
+}
+
+Value *VPInstruction::generatePerLane(VPTransformState &State,
+ const VPIteration &Lane) {
+ IRBuilderBase &Builder = State.Builder;
+
+ switch (getOpcode()) {
+ case VPInstruction::PtrAdd: {
+ auto *P = Builder.CreatePtrAdd(State.get(getOperand(0), Lane),
+ State.get(getOperand(1), Lane), Name);
+ return P;
+ }
+ default: {
+ Value *Res = generatePerPart(State, Lane.Part);
----------------
fhahn wrote:
This is a consequence of `generatePerLane` being responsible to generate all lanes and/or the first lane, while `generatePerPart` can either generate the vector or scalar per-part, but would need to also support PtrAdd. It seems clearer to flip around the delegation and have generatePerPart call generatePerLane for PtrAdd. Updated.
https://github.com/llvm/llvm-project/pull/83068
More information about the llvm-commits
mailing list