[llvm] [VPlan] Add ExtractLane VPInst to extract across multiple parts. (PR #148817)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 23 07:22:30 PDT 2025
================
@@ -46,8 +77,27 @@ define i64 @same_exit_block_pre_inc_use1() #0 {
; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 510, [[N_VEC]]
; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOP_END:%.*]], label [[SCALAR_PH]]
; CHECK: vector.early.exit:
+; CHECK-NEXT: [[TMP39:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[TMP40:%.*]] = mul nuw i64 [[TMP39]], 16
+; CHECK-NEXT: [[TMP41:%.*]] = call i64 @llvm.experimental.cttz.elts.i64.nxv16i1(<vscale x 16 x i1> [[TMP59]], i1 true)
+; CHECK-NEXT: [[TMP42:%.*]] = mul i64 [[TMP40]], 3
+; CHECK-NEXT: [[TMP43:%.*]] = add i64 [[TMP42]], [[TMP41]]
+; CHECK-NEXT: [[TMP44:%.*]] = call i64 @llvm.experimental.cttz.elts.i64.nxv16i1(<vscale x 16 x i1> [[TMP31]], i1 true)
+; CHECK-NEXT: [[TMP45:%.*]] = mul i64 [[TMP40]], 2
+; CHECK-NEXT: [[TMP46:%.*]] = add i64 [[TMP45]], [[TMP44]]
+; CHECK-NEXT: [[TMP47:%.*]] = icmp ne i64 [[TMP44]], [[TMP40]]
----------------
fhahn wrote:
Hmm I might be missing something, but I think we should check & select the parts in reverse order, so that the final select (`TMP58`), picks the offset based on part 0, if part 0 has an active lane, otherwise select offset for part 1 if it has an active lane and so on. Some of the check pattern variables don't have consecutive numbers, can be a bit confusing.
For the example, below is what I think should happen, but I am not sure if I missed anything.
`[[TMP41]` should handle the mask for part 3 (`[[TMP59]]` should be the compare for the last part)
`[[TMP44]]` should handle the mask for part 2 (`[[TMP31]]` should be the compare for the second-to-last part)
`[[TMP47]]` should be true if there is an active lane in part 2. (`llvm.experimental.cttz.elts` should return the number of vector elements if no lane is active)
```
[[TMP47:%.*]] = icmp ne i64 [[TMP44]], [[TMP40]]
[[TMP48:%.*]] = select i1 [[TMP47]], i64 [[TMP46]], i64 [[TMP43]]
```
So `[[TMP48]]` should select `[[TMP46]`, if there's an active lane for part 2, which is the count based on the active lanes in part 2. Only if there's no active lane in part 2 we should select the one based on part 3.
https://github.com/llvm/llvm-project/pull/148817
More information about the llvm-commits
mailing list