[GlobalISel] Add G_STEP_VECTOR to computeKnownBits.#190598
Merged
Merged
Conversation
Member
|
@llvm/pr-subscribers-llvm-globalisel @llvm/pr-subscribers-backend-aarch64 Author: Dhruva (Xylecrack) ChangesThis code is adapted from SelectionDAG::computeKnownBits. Full diff: https://github.com/llvm/llvm-project/pull/190598.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp b/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
index f0b455fbdc7d0..a00e17cb3e441 100644
--- a/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
@@ -285,6 +285,30 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known,
}
break;
}
+ case TargetOpcode::G_STEP_VECTOR: {
+ APInt Step = MI.getOperand(1).getCImm()->getValue();
+
+ if (Step.isPowerOf2())
+ Known.Zero.setLowBits(Step.logBase2());
+
+ if (!isUIntN(BitWidth, DstTy.getElementCount().getKnownMinValue()))
+ break;
+
+ const APInt MinNumElts =
+ APInt(BitWidth, DstTy.getElementCount().getKnownMinValue());
+ const Function &F = getMachineFunction().getFunction();
+ bool Overflow;
+ const APInt MaxNumElts = getVScaleRange(&F, BitWidth)
+ .getUnsignedMax()
+ .umul_ov(MinNumElts, Overflow);
+ if (Overflow)
+ break;
+ const APInt MaxValue = (MaxNumElts - 1).umul_ov(Step, Overflow);
+ if (Overflow)
+ break;
+ Known.Zero.setHighBits(MaxValue.countl_zero());
+ break;
+ }
case TargetOpcode::G_CONSTANT: {
Known = KnownBits::makeConstant(MI.getOperand(1).getCImm()->getValue());
break;
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/knownbits-stepvector.mir b/llvm/test/CodeGen/AArch64/GlobalISel/knownbits-stepvector.mir
new file mode 100644
index 0000000000000..73c76f78d4ac0
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/knownbits-stepvector.mir
@@ -0,0 +1,59 @@
+# NOTE: Assertions have been autogenerated by utils/update_givaluetracking_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=aarch64 -passes="print<gisel-value-tracking>" -filetype=null %s 2>&1 | FileCheck %s
+
+---
+name: StepVector_One
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: @StepVector_One
+ ; CHECK-NEXT: %0:_ KnownBits:???????????????????????????????? SignBits:1
+ %0:_(<vscale x 4 x s32>) = G_STEP_VECTOR i32 1
+...
+---
+name: StepVector_Pow2
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: @StepVector_Pow2
+ ; CHECK-NEXT: %0:_ KnownBits:????????????????????????????0000 SignBits:1
+ %0:_(<vscale x 4 x s32>) = G_STEP_VECTOR i32 16
+...
+---
+name: StepVector_NonPow2
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: @StepVector_NonPow2
+ ; CHECK-NEXT: %0:_ KnownBits:???????????????????????????????? SignBits:1
+ %0:_(<vscale x 4 x s32>) = G_STEP_VECTOR i32 3
+...
+---
+name: StepVector_Narrow
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: @StepVector_Narrow
+ ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1
+ %0:_(<vscale x 8 x s8>) = G_STEP_VECTOR i8 1
+...
+---
+name: StepVector_Narrow_Pow2
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: @StepVector_Narrow_Pow2
+ ; CHECK-NEXT: %0:_ KnownBits:??????00 SignBits:1
+ %0:_(<vscale x 8 x s8>) = G_STEP_VECTOR i8 4
+...
+---
+name: StepVector_Wide
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: @StepVector_Wide
+ ; CHECK-NEXT: %0:_ KnownBits:???????????????????????????????????????????????????????????????? SignBits:1
+ %0:_(<vscale x 2 x s64>) = G_STEP_VECTOR i64 1
+...
+---
+name: StepVector_Wide_Pow2
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: @StepVector_Wide_Pow2
+ ; CHECK-NEXT: %0:_ KnownBits:?????????????????????????????????????????????????????????????000 SignBits:1
+ %0:_(<vscale x 2 x s64>) = G_STEP_VECTOR i64 8
+...
|
arsenm
reviewed
Apr 6, 2026
Comment on lines
+304
to
+308
| if (Overflow) | ||
| break; | ||
| const APInt MaxValue = (MaxNumElts - 1).umul_ov(Step, Overflow); | ||
| if (Overflow) | ||
| break; |
Contributor
There was a problem hiding this comment.
Missing negative tests for these cases?
| if (Step.isPowerOf2()) | ||
| Known.Zero.setLowBits(Step.logBase2()); | ||
|
|
||
| if (!isUIntN(BitWidth, DstTy.getElementCount().getKnownMinValue())) |
| ; CHECK-LABEL: name: @StepVector_Wide_Pow2 | ||
| ; CHECK-NEXT: %0:_ KnownBits:?????????????????????????????????????????????????????????????000 SignBits:1 | ||
| %0:_(<vscale x 2 x s64>) = G_STEP_VECTOR i64 8 | ||
| ... |
arsenm
requested changes
Apr 8, 2026
arsenm
left a comment
Contributor
There was a problem hiding this comment.
code change lgtm but should add the missing test cases
6fc0a25 to
8dcf051
Compare
arsenm
approved these changes
Apr 9, 2026
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/225/builds/5447 Here is the relevant piece of the build log for the reference |
YonahGoldberg
pushed a commit
to YonahGoldberg/llvm-project
that referenced
this pull request
Apr 21, 2026
This code is adapted from SelectionDAG::computeKnownBits. part of llvm#150515. ticks off STEP_VECTOR.
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.
This code is adapted from SelectionDAG::computeKnownBits.
part of #150515.
ticks off STEP_VECTOR.