-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[VPlan] Also duplicated scalar-steps when it enables sinking scalars. #136021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,18 +164,27 @@ static bool sinkScalarOperands(VPlan &Plan) { | |
if (UI->getParent() == SinkTo) | ||
return true; | ||
NeedsDuplicating = UI->onlyFirstLaneUsed(SinkCandidate); | ||
// We only know how to duplicate VPRecipeRecipes for now. | ||
return NeedsDuplicating && isa<VPReplicateRecipe>(SinkCandidate); | ||
// We only know how to duplicate VPReplicateRecipes and | ||
// VPScalarIVStepsRecipes for now. | ||
return NeedsDuplicating && | ||
isa<VPReplicateRecipe, VPScalarIVStepsRecipe>(SinkCandidate); | ||
}; | ||
if (!all_of(SinkCandidate->users(), CanSinkWithUser)) | ||
continue; | ||
|
||
if (NeedsDuplicating) { | ||
if (ScalarVFOnly) | ||
continue; | ||
Instruction *I = SinkCandidate->getUnderlyingInstr(); | ||
auto *Clone = new VPReplicateRecipe(I, SinkCandidate->operands(), true); | ||
// TODO: add ".cloned" suffix to name of Clone's VPValue. | ||
VPSingleDefRecipe *Clone; | ||
if (isa<VPReplicateRecipe>(SinkCandidate)) { | ||
// TODO: Handle converting to uniform recipes as separate transform, | ||
// then cloning should be sufficient here. | ||
Instruction *I = SinkCandidate->getUnderlyingInstr(); | ||
Clone = new VPReplicateRecipe(I, SinkCandidate->operands(), true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Also independent) Could SinkCandidate->clone() also work for VPReplicateRecipe?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to set Uniform = true for the clone, currently that field is immutable, hence the manual duplicatio There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right. If replicate is duplicated as is, c/would having only first lane used effectively optimize it as if set explicitly to |
||
// TODO: add ".cloned" suffix to name of Clone's VPValue. | ||
} else { | ||
Clone = SinkCandidate->clone(); | ||
} | ||
|
||
Clone->insertBefore(SinkCandidate); | ||
SinkCandidate->replaceUsesWithIf(Clone, [SinkTo](VPUser &U, unsigned) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -603,11 +603,10 @@ define void @cost_duplicate_recipe_for_sinking(ptr %A, i64 %N) #2 { | |
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] | ||
; CHECK: vector.body: | ||
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_STORE_CONTINUE37:%.*]] ] | ||
; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 0 | ||
; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[INDEX]], 4 | ||
; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[INDEX]], 8 | ||
; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 12 | ||
; CHECK-NEXT: [[TMP7:%.*]] = shl nsw i64 [[TMP3]], 2 | ||
; CHECK-NEXT: [[TMP7:%.*]] = shl nsw i64 [[INDEX]], 2 | ||
; CHECK-NEXT: [[TMP8:%.*]] = shl nsw i64 [[TMP4]], 2 | ||
; CHECK-NEXT: [[TMP9:%.*]] = shl nsw i64 [[TMP5]], 2 | ||
; CHECK-NEXT: [[TMP10:%.*]] = shl nsw i64 [[TMP6]], 2 | ||
|
@@ -630,6 +629,7 @@ define void @cost_duplicate_recipe_for_sinking(ptr %A, i64 %N) #2 { | |
; CHECK-NEXT: [[TMP23:%.*]] = extractelement <4 x i1> [[TMP19]], i32 0 | ||
; CHECK-NEXT: br i1 [[TMP23]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]] | ||
; CHECK: pred.store.if: | ||
; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 0 | ||
; CHECK-NEXT: [[TMP24:%.*]] = shl nsw i64 [[TMP3]], 2 | ||
; CHECK-NEXT: [[TMP25:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP24]] | ||
; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP25]], align 8 | ||
|
@@ -665,7 +665,8 @@ define void @cost_duplicate_recipe_for_sinking(ptr %A, i64 %N) #2 { | |
; CHECK-NEXT: [[TMP38:%.*]] = extractelement <4 x i1> [[TMP20]], i32 0 | ||
; CHECK-NEXT: br i1 [[TMP38]], label [[PRED_STORE_IF14:%.*]], label [[PRED_STORE_CONTINUE15:%.*]] | ||
; CHECK: pred.store.if14: | ||
; CHECK-NEXT: [[TMP39:%.*]] = shl nsw i64 [[TMP4]], 2 | ||
; CHECK-NEXT: [[TMP88:%.*]] = add i64 [[INDEX]], 4 | ||
; CHECK-NEXT: [[TMP39:%.*]] = shl nsw i64 [[TMP88]], 2 | ||
; CHECK-NEXT: [[TMP40:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP39]] | ||
; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP40]], align 8 | ||
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE15]] | ||
|
@@ -700,7 +701,8 @@ define void @cost_duplicate_recipe_for_sinking(ptr %A, i64 %N) #2 { | |
; CHECK-NEXT: [[TMP53:%.*]] = extractelement <4 x i1> [[TMP21]], i32 0 | ||
; CHECK-NEXT: br i1 [[TMP53]], label [[PRED_STORE_IF22:%.*]], label [[PRED_STORE_CONTINUE23:%.*]] | ||
; CHECK: pred.store.if22: | ||
; CHECK-NEXT: [[TMP54:%.*]] = shl nsw i64 [[TMP5]], 2 | ||
; CHECK-NEXT: [[TMP107:%.*]] = add i64 [[INDEX]], 8 | ||
; CHECK-NEXT: [[TMP54:%.*]] = shl nsw i64 [[TMP107]], 2 | ||
; CHECK-NEXT: [[TMP55:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP54]] | ||
; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP55]], align 8 | ||
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE23]] | ||
|
@@ -735,7 +737,8 @@ define void @cost_duplicate_recipe_for_sinking(ptr %A, i64 %N) #2 { | |
; CHECK-NEXT: [[TMP68:%.*]] = extractelement <4 x i1> [[TMP22]], i32 0 | ||
; CHECK-NEXT: br i1 [[TMP68]], label [[PRED_STORE_IF30:%.*]], label [[PRED_STORE_CONTINUE31:%.*]] | ||
; CHECK: pred.store.if30: | ||
; CHECK-NEXT: [[TMP69:%.*]] = shl nsw i64 [[TMP6]], 2 | ||
; CHECK-NEXT: [[TMP108:%.*]] = add i64 [[INDEX]], 12 | ||
; CHECK-NEXT: [[TMP69:%.*]] = shl nsw i64 [[TMP108]], 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these and other sinkings consistent with the original sinkScalarOperands? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, now we also sink for all lanes due to duplicating (VF = 4, IC = 4); |
||
; CHECK-NEXT: [[TMP70:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP69]] | ||
; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP70]], align 8 | ||
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE31]] | ||
|
@@ -785,15 +788,15 @@ define void @cost_duplicate_recipe_for_sinking(ptr %A, i64 %N) #2 { | |
; CHECK-NEXT: br label [[VEC_EPILOG_VECTOR_BODY:%.*]] | ||
; CHECK: vec.epilog.vector.body: | ||
; CHECK-NEXT: [[INDEX40:%.*]] = phi i64 [ [[VEC_EPILOG_RESUME_VAL1]], [[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT51:%.*]], [[PRED_STORE_CONTINUE50:%.*]] ] | ||
; CHECK-NEXT: [[TMP86:%.*]] = add i64 [[INDEX40]], 0 | ||
; CHECK-NEXT: [[TMP87:%.*]] = shl nsw i64 [[TMP86]], 2 | ||
; CHECK-NEXT: [[TMP87:%.*]] = shl nsw i64 [[INDEX40]], 2 | ||
; CHECK-NEXT: [[TMP89:%.*]] = getelementptr nusw double, ptr [[A]], i64 [[TMP87]] | ||
; CHECK-NEXT: [[WIDE_VEC41:%.*]] = load <16 x double>, ptr [[TMP89]], align 8 | ||
; CHECK-NEXT: [[STRIDED_VEC42:%.*]] = shufflevector <16 x double> [[WIDE_VEC41]], <16 x double> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12> | ||
; CHECK-NEXT: [[TMP90:%.*]] = fcmp oeq <4 x double> [[STRIDED_VEC42]], zeroinitializer | ||
; CHECK-NEXT: [[TMP91:%.*]] = extractelement <4 x i1> [[TMP90]], i32 0 | ||
; CHECK-NEXT: br i1 [[TMP91]], label [[PRED_STORE_IF43:%.*]], label [[PRED_STORE_CONTINUE44:%.*]] | ||
; CHECK: pred.store.if43: | ||
; CHECK-NEXT: [[TMP86:%.*]] = add i64 [[INDEX40]], 0 | ||
; CHECK-NEXT: [[TMP92:%.*]] = shl nsw i64 [[TMP86]], 2 | ||
; CHECK-NEXT: [[TMP93:%.*]] = getelementptr double, ptr [[A]], i64 [[TMP92]] | ||
; CHECK-NEXT: store double 0.000000e+00, ptr [[TMP93]], align 8 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if VPScalarIVStepsRecipes should be subject to further optimization after cloning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any optimizations in particular you are thinking about?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimizations considering only first lane is used, as in turning replicate recipe to be uniform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!