llvm / llvm/llvm-project

[SDAG] Scalarization as an option in `LegalizeAction`

Open
#171,909 0 comments 0 reactions 0 assignees View on GitHub
llvm:SelectionDAG
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Sometimes, a target might desire to legalize an operation by scalarizing it.
Consider a target that has a scalar `ISD::ABDS` for `MVT::i16` but no vector version for `MVT::v2i16`. the current options are quite limited:
```
enum LegalizeAction : uint8_t {
Legal, // The target natively supports this operation.
Promote, // This operation should be executed in a larger type.
Expand, // Try to expand this to other ops, otherwise use a libcall.
LibCall, // Don't try to expand this to other ops, always use a libcall.
Custom // Use the LowerOperation hook to implement custom lowering.
};
```
clearly it is not Legal, Promote might not be supported, Expand returns in our case completely different ops (min, max, sub, which is 3 instructions instead of two vector instructions), LibCall is more expensive than two instructions and we are left with Custom - in a lot of cases we just point to one function downstream that basically scalarizes the operation or converts to shorter vectors (v16i16 -> v8i16 x 2). Could be great to have that upstream. opinions?

(that or just "try reduce the type, then combine immediately/call hook" instead)

or maybe consider adding a utility function that does it,

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.