[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
Fri Oct 2 03:47:18 PDT 2026


artagnon wrote:

> This patch is intended to just solve a targeted issue: VPInstructions are the only recipe where the result is effectively untyped (could be vector, single-scalar or scalar for all lanes, depending on opcode and how it is used). This is contrary to all other recipes, where either the recipe type directly implies the result type (e.g. VPWidenRecipe will create a vector) or need another flag (e.g. IsSingleScalar for VPReplicateRecipe, or VF-scale for partial reductions.

I would phrase this differently: VPInstruction is the only _remaining_ recipe where the non-statically-inferable widening info is not passed explicitly. Yes, I can see your patch, and I'm aware of the problem with casts.
 
> The fact that we do not know if a VPInstruction generates a vector or scalar without looking at all uses means we cannot re-use it easily for other recipes, and would make it quite expensive to compute costs for them (each cost query for each VF would need to look at uses).

Yes, the non-statically-inferable widening info obviously needs to be computed, and this can be expensive.

> Eventually I would like to a state where transitions between vector generating to scalar generating VPInstructions is done explicitly through transforms, like we already do for other recipes.

Currently, we dynamically compute what we cannot infer statically using OnlyFirstLaneUsed on execution. Yes, this obviously suffers from the problem of not considering information of recipes that have previously been narrowed, because that information is not encoded anywhere?

> I think this is independent of an improved generic API to query whether a given recipe produces a single-scalar, multiple scalars or vector, as in almost all cases we can already retrieve the information statically.

The point isn't the helper itself, but the idea of distilling widening semantics, and showing exactly where we need to _dig_ for it. The vision was to embed the static information (VPWideningInfo) in recipes, and assert on construction asking for explicit widening information when it cannot be inferred statically. It would give us optimization benefits from the richer information, as I already show in follow ups. The problem I see currently is that the APIs are degraded unnecessarily with a IsSingleScalar, when it can be inferred statically in many cases -- the problem is not just the redundancy of the information, but also user errors where an incorrect boolean is passed?

Yes, as I previously said, this PR solves an _immediate problem_, so if other reviewers think it should land, go ahead and land it.

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


More information about the llvm-commits mailing list