[llvm] AMDGPU/GlobalISel: Lower G_EXTRACT in legalizer (PR #181036)
Petar Avramovic via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 10 03:06:41 PDT 2026
================
@@ -1941,39 +1941,31 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
for (unsigned Op : {G_EXTRACT, G_INSERT}) {
unsigned BigTyIdx = Op == G_EXTRACT ? 1 : 0;
unsigned LitTyIdx = Op == G_EXTRACT ? 0 : 1;
-
- // FIXME: Doesn't handle extract of illegal sizes.
getActionDefinitionsBuilder(Op)
- .lowerIf(all(typeIs(LitTyIdx, S16), sizeIs(BigTyIdx, 32)))
- .lowerIf([=](const LegalityQuery &Query) {
- // Sub-vector(or single element) insert and extract.
- // TODO: verify immediate offset here since lower only works with
- // whole elements.
- const LLT BigTy = Query.Types[BigTyIdx];
- return BigTy.isVector();
- })
- // FIXME: Multiples of 16 should not be legal.
- .legalIf([=](const LegalityQuery &Query) {
+ .widenScalarIf(
+ [=](const LegalityQuery &Query) {
+ const LLT BigTy = Query.Types[BigTyIdx];
+ return (BigTy.getScalarSizeInBits() < 16);
+ },
+ LegalizeMutations::widenScalarOrEltToNextPow2(BigTyIdx, 16))
+ .widenScalarIf(
+ [=](const LegalityQuery &Query) {
+ const LLT LitTy = Query.Types[LitTyIdx];
+ return (LitTy.getScalarSizeInBits() < 16);
+ },
+ LegalizeMutations::widenScalarOrEltToNextPow2(LitTyIdx, 16))
+ .moreElementsIf(isSmallOddVector(BigTyIdx), oneMoreElement(BigTyIdx))
+ .widenScalarToNextPow2(BigTyIdx, 32)
+ .customIf([=](const LegalityQuery &Query) {
+ // Generic lower is not aware of subregs and can produce inefficient
+ // shift+trunc/mask sequences. We can instead use custom lowering
----------------
petar-avramovic wrote:
Need to clarify a bit, not sure what are subregs in this context
https://github.com/llvm/llvm-project/pull/181036
More information about the llvm-commits
mailing list