[SCEV] Always return true for isKnownToBeAPowerOfTwo for SCEVVScale#183693
Merged
[SCEV] Always return true for isKnownToBeAPowerOfTwo for SCEVVScale#183693
Conversation
After llvm#183080 vscale is always a power of two, and we don't need to check for the vscale_range attribute.
Member
|
@llvm/pr-subscribers-llvm-analysis Author: Luke Lau (lukel97) ChangesAfter #183080 vscale is always a power of two, and we don't need to Full diff: https://github.com/llvm/llvm-project/pull/183693.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 937b5aa77d467..083988f948069 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -11111,13 +11111,13 @@ bool ScalarEvolution::isKnownNonZero(const SCEV *S) {
bool ScalarEvolution::isKnownToBeAPowerOfTwo(const SCEV *S, bool OrZero,
bool OrNegative) {
- auto NonRecursive = [this, OrNegative](const SCEV *S) {
+ auto NonRecursive = [OrNegative](const SCEV *S) {
if (auto *C = dyn_cast<SCEVConstant>(S))
return C->getAPInt().isPowerOf2() ||
(OrNegative && C->getAPInt().isNegatedPowerOf2());
- // The vscale_range indicates vscale is a power-of-two.
- return isa<SCEVVScale>(S) && F.hasFnAttribute(Attribute::VScaleRange);
+ // vscale is a power-of-two.
+ return isa<SCEVVScale>(S);
};
if (NonRecursive(S))
diff --git a/llvm/test/Analysis/ScalarEvolution/trip-count-scalable-stride.ll b/llvm/test/Analysis/ScalarEvolution/trip-count-scalable-stride.ll
index 30a095fd144fa..8ba8bde322d44 100644
--- a/llvm/test/Analysis/ScalarEvolution/trip-count-scalable-stride.ll
+++ b/llvm/test/Analysis/ScalarEvolution/trip-count-scalable-stride.ll
@@ -525,3 +525,37 @@ for.body: ; preds = %entry, %for.body
for.end: ; preds = %for.body, %entry
ret void
}
+
+define void @vscale_ult_no_vscale_range(ptr nocapture %A) mustprogress {
+; CHECK-LABEL: 'vscale_ult_no_vscale_range'
+; CHECK-NEXT: Classifying expressions for: @vscale_ult_no_vscale_range
+; CHECK-NEXT: %vscale = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: --> vscale U: [1,0) S: [1,0)
+; CHECK-NEXT: %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
+; CHECK-NEXT: --> {0,+,vscale}<%for.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT: %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
+; CHECK-NEXT: --> {%A,+,(4 * vscale)}<%for.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT: %add = add i32 %i.05, %vscale
+; CHECK-NEXT: --> {vscale,+,vscale}<nw><%for.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT: Determining loop execution counts for: @vscale_ult_no_vscale_range
+; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
+; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
+; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
+;
+entry:
+ %vscale = call i32 @llvm.vscale.i32()
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
+ %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
+ %0 = load <vscale x 4 x i32>, ptr %arrayidx, align 4
+ %inc = add nsw <vscale x 4 x i32> %0, splat (i32 1)
+ store <vscale x 4 x i32> %inc, ptr %arrayidx, align 4
+ %add = add i32 %i.05, %vscale
+ %cmp = icmp ult i32 %add, u0x00010000
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body, %entry
+ ret void
+}
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After #183080 vscale is always a power of two, so we don't need to check for the vscale_range attribute.