Skip to content

Commit

Permalink
[VPlan] Use onlyFirstLaneUsed in sinkScalarOperands.
Browse files Browse the repository at this point in the history
Replace custom code to check if only the first lane is used by generic
helper `onlyFirstLaneUsed`. This enables VPlan-based sinking in a few
additional cases and was suggested in D133760.

Reviewed By: Ayal

Differential Revision: https://reviews.llvm.org/D136368
  • Loading branch information
fhahn committed Oct 29, 2022
1 parent 323fb62 commit 43f0f1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 3 additions & 8 deletions llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Expand Up @@ -138,21 +138,16 @@ bool VPlanTransforms::sinkScalarOperands(VPlan &Plan) {
// All recipe users of the sink candidate must be in the same block SinkTo
// or all users outside of SinkTo must be uniform-after-vectorization (
// i.e., only first lane is used) . In the latter case, we need to duplicate
// SinkCandidate. At the moment, we identify such UAV's by looking for the
// address operands of widened memory recipes.
// SinkCandidate.
auto CanSinkWithUser = [SinkTo, &NeedsDuplicating,
SinkCandidate](VPUser *U) {
auto *UI = dyn_cast<VPRecipeBase>(U);
if (!UI)
return false;
if (UI->getParent() == SinkTo)
return true;
auto *WidenI = dyn_cast<VPWidenMemoryInstructionRecipe>(UI);
if (WidenI && WidenI->getAddr() == SinkCandidate) {
NeedsDuplicating = true;
return true;
}
return false;
NeedsDuplicating = UI->onlyFirstLaneUsed(SinkCandidate);
return NeedsDuplicating;
};
if (!all_of(SinkCandidate->users(), CanSinkWithUser))
continue;
Expand Down
Expand Up @@ -38,8 +38,9 @@ define void @interleaved_with_cond_store_0(%pair *%p, i64 %x, i64 %n) {
; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x i1> [[TMP4]], i64 0
; CHECK-NEXT: br i1 [[TMP5]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]]
; CHECK: pred.store.if:
; CHECK-NEXT: [[TMP2_1:%.*]] = getelementptr inbounds [[PAIR:%.*]], %pair* [[P:%.*]], i64 [[INDEX]], i32 1
; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x i64> [[WIDE_VEC]], i64 0
; CHECK-NEXT: store i64 [[TMP6]], i64* [[TMP2]], align 8
; CHECK-NEXT: store i64 [[TMP6]], i64* [[TMP2_1]], align 8
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE]]
; CHECK: pred.store.continue:
; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i1> [[TMP4]], i64 1
Expand Down Expand Up @@ -136,8 +137,9 @@ define void @interleaved_with_cond_store_1(%pair *%p, i64 %x, i64 %n) {
; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x i1> [[TMP7]], i64 0
; CHECK-NEXT: br i1 [[TMP8]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]]
; CHECK: pred.store.if:
; CHECK-NEXT: [[PTR0:%.*]] = getelementptr inbounds [[PAIR:%.*]], %pair* [[P:%.*]], i64 [[INDEX]], i32 0
; CHECK-NEXT: [[TMP9:%.*]] = extractelement <4 x i64> [[WIDE_VEC]], i64 0
; CHECK-NEXT: store i64 [[TMP9]], i64* [[TMP3]], align 8
; CHECK-NEXT: store i64 [[TMP9]], i64* [[PTR0]], align 8
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE]]
; CHECK: pred.store.continue:
; CHECK-NEXT: [[TMP10:%.*]] = extractelement <2 x i1> [[TMP7]], i64 1
Expand Down Expand Up @@ -246,8 +248,9 @@ define void @interleaved_with_cond_store_2(%pair *%p, i64 %x, i64 %n) {
; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x i1> [[TMP7]], i64 0
; CHECK-NEXT: br i1 [[TMP8]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]]
; CHECK: pred.store.if:
; CHECK-NEXT: [[PTR1:%.*]] = getelementptr inbounds [[PAIR]], %pair* [[P]], i64 [[INDEX]], i32 1
; CHECK-NEXT: [[TMP9:%.*]] = extractelement <4 x i64> [[WIDE_VEC]], i64 0
; CHECK-NEXT: store i64 [[TMP9]], i64* [[TMP5]], align 8
; CHECK-NEXT: store i64 [[TMP9]], i64* [[PTR1]], align 8
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE]]
; CHECK: pred.store.continue:
; CHECK-NEXT: [[TMP10:%.*]] = extractelement <2 x i1> [[TMP7]], i64 1
Expand Down

0 comments on commit 43f0f1a

Please sign in to comment.