-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[VPlan] Handle FirstActiveLane when unrolling. #145394
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
badd922
e80224d
f4e7f8a
f2d4f6c
e7a1d64
1bdc736
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 | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -856,9 +856,32 @@ Value *VPInstruction::generate(VPTransformState &State) { | |||||||||||||||||||||||||
return Builder.CreateOrReduce(Res); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
case VPInstruction::FirstActiveLane: { | ||||||||||||||||||||||||||
Value *Mask = State.get(getOperand(0)); | ||||||||||||||||||||||||||
return Builder.CreateCountTrailingZeroElems(Builder.getInt64Ty(), Mask, | ||||||||||||||||||||||||||
true, Name); | ||||||||||||||||||||||||||
if (getNumOperands() == 1) { | ||||||||||||||||||||||||||
Value *Mask = State.get(getOperand(0)); | ||||||||||||||||||||||||||
return Builder.CreateCountTrailingZeroElems(Builder.getInt64Ty(), Mask, | ||||||||||||||||||||||||||
true, Name); | ||||||||||||||||||||||||||
Comment on lines
+861
to
+862
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.
Suggested change
consistent with below. |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
// If there are multiple operands, create a chain of selects to pick the | ||||||||||||||||||||||||||
// first operand with an active lane and add the number of lanes of the | ||||||||||||||||||||||||||
// preceding operands. | ||||||||||||||||||||||||||
Comment on lines
+864
to
+866
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.
Suggested change
|
||||||||||||||||||||||||||
Value *RuntimeVF = | ||||||||||||||||||||||||||
getRuntimeVF(State.Builder, State.Builder.getInt64Ty(), State.VF); | ||||||||||||||||||||||||||
Comment on lines
+867
to
+868
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.
Suggested change
Use |
||||||||||||||||||||||||||
unsigned LastOpIdx = getNumOperands() - 1; | ||||||||||||||||||||||||||
Value *Res = nullptr; | ||||||||||||||||||||||||||
for (int Idx = LastOpIdx; Idx >= 0; --Idx) { | ||||||||||||||||||||||||||
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. Can something like this
Suggested change
work instead? |
||||||||||||||||||||||||||
Value *TrailingZeros = Builder.CreateCountTrailingZeroElems( | ||||||||||||||||||||||||||
Builder.getInt64Ty(), State.get(getOperand(Idx)), true, Name); | ||||||||||||||||||||||||||
Comment on lines
+872
to
+873
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.
Suggested change
|
||||||||||||||||||||||||||
Value *Current = Builder.CreateAdd( | ||||||||||||||||||||||||||
Builder.CreateMul(RuntimeVF, Builder.getInt64(Idx)), TrailingZeros); | ||||||||||||||||||||||||||
Comment on lines
+874
to
+875
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.
Suggested change
splitting is easier to read, as in cmp-select below? |
||||||||||||||||||||||||||
if (Res) { | ||||||||||||||||||||||||||
Value *Cmp = Builder.CreateICmpNE(TrailingZeros, RuntimeVF); | ||||||||||||||||||||||||||
Res = Builder.CreateSelect(Cmp, Current, Res); | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
Res = Current; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+876
to
+881
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.
Suggested change
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return Res; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||
llvm_unreachable("Unsupported opcode for instruction"); | ||||||||||||||||||||||||||
|
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.
to be reused in multiple cases below.