[llvm] [VPlan] Encode single-scalar-ness of VPInstruction in a field (NFC). (PR #227761)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 12:52:17 PDT 2026
================
@@ -605,15 +605,36 @@ Type *VPReplicateRecipe::computeScalarType(const Instruction *I,
return computeScalarTypeForInstruction(Opcode, Operands);
}
+/// Returns true if VPInstructions with \p Opcode always produce a single
+/// scalar.
+static bool isAlwaysSingleScalar(unsigned Opcode) {
+ switch (Opcode) {
+ case Instruction::Load:
+ case Instruction::PHI:
+ case VPInstruction::ExplicitVectorLength:
+ case VPInstruction::ResumeForEpilogue:
+ case VPInstruction::Intrinsic:
+ return true;
+ default:
+ return false;
+ }
+}
+
VPInstruction::VPInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands,
const VPIRFlags &Flags, const VPIRMetadata &MD,
- DebugLoc DL, const Twine &Name, Type *ResultTy)
+ DebugLoc DL, const Twine &Name, Type *ResultTy,
+ std::optional<bool> GeneratesSingleScalar)
: VPRecipeWithIRFlags(
VPRecipeBase::VPInstructionSC, Operands,
ResultTy ? ResultTy
: computeScalarTypeForInstruction(Opcode, Operands),
Flags, DL),
- VPIRMetadata(MD), Opcode(Opcode), Name(Name.str()) {
+ VPIRMetadata(MD), Opcode(Opcode), Name(Name.str()),
+ GeneratesSingleScalar(
+ GeneratesSingleScalar.value_or(isAlwaysSingleScalar(Opcode))) {
+ assert((!isAlwaysSingleScalar(Opcode) || this->GeneratesSingleScalar) &&
+ "GeneratesSingleScalar must be set for opcodes that always generate "
+ "a single scalar");
----------------
artagnon wrote:
Hm, I'm confused by this assert: if GeneratesSingleScalar is supplied, use it; otherwise use isAlwaysSingleScalar. If it is not isAlwaysSingleScalar, a GeneratesSingleScalar must be supplied. Accordingly, the message should be "GeneratesSingleSingleScalar must be supplied for opcodes that are not determined always-single-scalar"?
https://github.com/llvm/llvm-project/pull/227761
More information about the llvm-commits
mailing list