Skip to content

[LLVM][LangRef] Restrict vscale to be a signed power-of-two integer.#183080

Merged
paulwalker-arm merged 2 commits intollvm:mainfrom
paulwalker-arm:restrict-vscale-to-power-of-two
Feb 24, 2026
Merged

[LLVM][LangRef] Restrict vscale to be a signed power-of-two integer.#183080
paulwalker-arm merged 2 commits intollvm:mainfrom
paulwalker-arm:restrict-vscale-to-power-of-two

Conversation

@paulwalker-arm
Copy link
Copy Markdown
Collaborator

The rational for this change comes from #145098 and #183065 and essentially boils down to there being no known requirement to support non-power-of-two values of vscale and yet said support is leading to unnecessary complexity within LLVM.

Hopefully it's ok to land the LangRef change in isolation and then follow up with the codebase simplifications.

@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Feb 24, 2026

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-llvm-ir

Author: Paul Walker (paulwalker-arm)

Changes

The rational for this change comes from #145098 and #183065 and essentially boils down to there being no known requirement to support non-power-of-two values of vscale and yet said support is leading to unnecessary complexity within LLVM.

Hopefully it's ok to land the LangRef change in isolation and then follow up with the codebase simplifications.


Full diff: https://github.com/llvm/llvm-project/pull/183080.diff

1 Files Affected:

  • (modified) llvm/docs/LangRef.rst (+5-5)
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 50a2515f69189..a7baeb94bc86b 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -4678,9 +4678,9 @@ elementtype may be any integer, floating-point, pointer type, or a sized
 target extension type that has the ``CanBeVectorElement`` property. Vectors
 of size zero are not allowed. For scalable vectors, the total number of
 elements is a constant multiple (called vscale) of the specified number
-of elements; vscale is a positive integer that is unknown at compile time
-and the same hardware-dependent constant for all scalable vectors at run
-time. The size of a specific scalable vector type is thus constant within
+of elements; vscale is a positive power-of-two integer that is unknown at
+compile time and the same hardware-dependent constant for all scalable vectors
+at run time. The size of a specific scalable vector type is thus constant within
 IR, even if the exact size in bytes cannot be determined until run time.
 
 :Examples:
@@ -31501,8 +31501,8 @@ vectors such as ``<vscale x 16 x i8>``.
 Semantics:
 """"""""""
 
-``vscale`` is a positive value that is constant throughout program
-execution, but is unknown at compile time.
+``vscale`` is a positive power-of-two integer that is constant throughout
+program execution, but is unknown at compile time.
 If the result value does not fit in the result type, then the result is
 a :ref:`poison value <poisonvalues>`.
 

Copy link
Copy Markdown
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, based on past discussions there is broad consensus in favor of this change.

@paulwalker-arm paulwalker-arm requested review from lukel97 and removed request for Lukacma February 24, 2026 15:50
Copy link
Copy Markdown
Contributor

@lukel97 lukel97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks. +1 on splitting off the removal of the TTI hook etc

@MacDue
Copy link
Copy Markdown
Member

MacDue commented Feb 24, 2026

MLIR (when lowering to LLVM) inherits vscale semantics from LLVM, so there may be documentation there that could/should be updated too. cc @banach-space.

Copy link
Copy Markdown
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@paulwalker-arm
Copy link
Copy Markdown
Collaborator Author

MLIR (when lowering to LLVM) inherits vscale semantics from LLVM, so there may be documentation there that could/should be updated too. cc @banach-space.

Thanks @MacDue. I can see a reference in Dialects/Vector.md that I'll need to update.

Copy link
Copy Markdown
Contributor

@david-arm david-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@llvmbot llvmbot added the mlir label Feb 24, 2026
@paulwalker-arm paulwalker-arm merged commit 59661a2 into llvm:main Feb 24, 2026
12 checks passed
@paulwalker-arm paulwalker-arm deleted the restrict-vscale-to-power-of-two branch February 24, 2026 17:42
lukel97 added a commit to lukel97/llvm-project that referenced this pull request Feb 25, 2026
After llvm#183080 vscale can no longer be a power of 2, which means the canonical IV can't overflow with tail folding w/ scalable vectors anymore. Therefore we don't need to drop the NUW flag.

IVUpdateMayOverflow is left to be removed in a separate PR since it removes further runtime checks.
paulwalker-arm added a commit that referenced this pull request Feb 25, 2026
After #183080 this is no longer
a configurable property.

NOTE: No test changes expected beyond
llvm/test/Transforms/LoopVectorize/scalable-predication.ll which has
been removed because it only existed to verfiy the now unsupported
functionality.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 25, 2026
…(#183292)

After llvm/llvm-project#183080 this is no longer
a configurable property.

NOTE: No test changes expected beyond
llvm/test/Transforms/LoopVectorize/scalable-predication.ll which has
been removed because it only existed to verfiy the now unsupported
functionality.
lukel97 added a commit to lukel97/llvm-project that referenced this pull request Feb 25, 2026
… NFC

The IV can no longer overflow with tail folding after llvm#183080.
lukel97 added a commit that referenced this pull request Feb 25, 2026
… NFC (#183066)

The IV can no longer overflow with tail folding after #183080.
tudinhh pushed a commit to tudinhh/llvm-project that referenced this pull request Feb 26, 2026
…lvm#183080)

There is no known requirement to support non-power-of-two
values of vscale and yet said support is leading to unnecessary
complexity within LLVM.
lukel97 added a commit to lukel97/llvm-project that referenced this pull request Feb 27, 2026
Previously vscale_range used to add the constraint that vscale is a
power-of-two, but after llvm#183080 it's already a power-of-two to begin with.

This drops the extra mention of power-of-two to clarify it's not a new
constraint now.
lukel97 added a commit to lukel97/llvm-project that referenced this pull request Feb 27, 2026
After llvm#183080 vscale is always a power of two, and we don't need to
check for the vscale_range attribute.
lukel97 added a commit that referenced this pull request Feb 27, 2026
After #183080 vscale can no longer be a non-power of 2, which means the
canonical IV can't overflow with tail folding w/ scalable vectors
anymore. Therefore we don't need to drop the NUW flag.

IVUpdateMayOverflow is left to be removed in a separate PR since it
removes further runtime checks.
lukel97 added a commit to lukel97/llvm-project that referenced this pull request Feb 27, 2026
After llvm#183080, the canonical IV (not the increment!) can't overflow. So now canonical IVs that are unrolled will have steps that don't overflow, so we can add the nuw flag.

This allows us to tighten the VPlanVerifier isKnownMonotonic check by restricting it to adds with nuw.
lukel97 added a commit to lukel97/llvm-project that referenced this pull request Feb 27, 2026
lukel97 added a commit that referenced this pull request Feb 27, 2026
…183693)

After #183080 vscale is always a power of two, so we don't need to check
for the vscale_range attribute.
lukel97 added a commit that referenced this pull request Feb 27, 2026
lukel97 added a commit that referenced this pull request Feb 27, 2026
…ut the attribute (#183689)

Previously vscale_range used to add the constraint that vscale is a
power-of-two, but after #183080 it's already a power-of-two to begin
with.

This clarifies the sentence about assumptions when there is no attribute
lukel97 added a commit that referenced this pull request Feb 27, 2026
After #183080, the canonical IV (not the increment!) can't overflow. So
now canonical IVs that are unrolled will have steps that don't overflow,
so we can add the nuw flag.

This allows us to tighten the VPlanVerifier isKnownMonotonic check by
restricting it to adds with nuw.
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
After llvm#183080 this is no longer
a configurable property.

NOTE: No test changes expected beyond
llvm/test/Transforms/LoopVectorize/scalable-predication.ll which has
been removed because it only existed to verfiy the now unsupported
functionality.
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
… NFC (llvm#183066)

The IV can no longer overflow with tail folding after llvm#183080.
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
After llvm#183080 vscale can no longer be a non-power of 2, which means the
canonical IV can't overflow with tail folding w/ scalable vectors
anymore. Therefore we don't need to drop the NUW flag.

IVUpdateMayOverflow is left to be removed in a separate PR since it
removes further runtime checks.
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
…lvm#183693)

After llvm#183080 vscale is always a power of two, so we don't need to check
for the vscale_range attribute.
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
…ut the attribute (llvm#183689)

Previously vscale_range used to add the constraint that vscale is a
power-of-two, but after llvm#183080 it's already a power-of-two to begin
with.

This clarifies the sentence about assumptions when there is no attribute
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
After llvm#183080, the canonical IV (not the increment!) can't overflow. So
now canonical IVs that are unrolled will have steps that don't overflow,
so we can add the nuw flag.

This allows us to tighten the VPlanVerifier isKnownMonotonic check by
restricting it to adds with nuw.
HendrikHuebner pushed a commit to HendrikHuebner/llvm-project that referenced this pull request Mar 10, 2026
…lvm#183080)

There is no known requirement to support non-power-of-two
values of vscale and yet said support is leading to unnecessary
complexity within LLVM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants