-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LV] Compute value of escaped induction based on the computed end value. #110576
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
8bd3691
1ef21d3
d40de1a
5f4df5e
ab37947
d84ea33
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 |
---|---|---|
|
@@ -2747,17 +2747,24 @@ void InnerLoopVectorizer::fixupIVUsers(PHINode *OrigPhi, | |
if (isa_and_nonnull<FPMathOperator>(II.getInductionBinOp())) | ||
B.setFastMathFlags(II.getInductionBinOp()->getFastMathFlags()); | ||
|
||
Value *CountMinusOne = B.CreateSub( | ||
VectorTripCount, ConstantInt::get(VectorTripCount->getType(), 1)); | ||
CountMinusOne->setName("cmo"); | ||
|
||
VPValue *StepVPV = Plan.getSCEVExpansion(II.getStep()); | ||
assert(StepVPV && "step must have been expanded during VPlan execution"); | ||
Value *Step = StepVPV->isLiveIn() ? StepVPV->getLiveInIRValue() | ||
: State.get(StepVPV, VPLane(0)); | ||
Value *Escape = | ||
emitTransformedIndex(B, CountMinusOne, II.getStartValue(), Step, | ||
II.getKind(), II.getInductionBinOp()); | ||
Value *Escape = nullptr; | ||
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. One of the things that 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.
|
||
if (EndValue->getType()->isIntegerTy()) | ||
Escape = B.CreateSub(EndValue, Step); | ||
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. Is this guaranteed to be the same value as before? For example, do we know for sure that the overflow behaviour in each scenario is the same? Basically does this statement hold true:
where I assume that 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 it should always produce the same result, except if the step is But I don't think the |
||
else if (EndValue->getType()->isPointerTy()) | ||
Escape = B.CreatePtrAdd(EndValue, B.CreateNeg(Step)); | ||
else if (EndValue->getType()->isFloatingPointTy()) { | ||
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. nit (post-commit):
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. Adjusted in 2437784, thanks! |
||
Escape = B.CreateBinOp(II.getInductionBinOp()->getOpcode() == | ||
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. nit (post-commit): is there a more consistent way to handle these three cases rather than creating sub for integer (assuming original opcode is add?), negating step for pointer, and reversing the opcode for floating point? Would negating the step work for all, with their original opcode? 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. Unfortunately I am not sure there's a way to do this more concisely overall. Negating the step would work for both integer and pointers, but then we still would need to select between Add/PtrAdd. And add(neg()) requires an additional instructions for integers. For floating points, perhaps it might be possible to normalize the representation of currently 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. Perhaps CreateBinOp() could be used for both integer and FP, as in something like:
|
||
Instruction::FAdd | ||
? Instruction::FSub | ||
: Instruction::FAdd, | ||
EndValue, Step); | ||
} else { | ||
llvm_unreachable("all possible induction types must be handled"); | ||
} | ||
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. I think there is a problem here because you have initialised 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. All possible induction types should be handled above, added an unreachable, thanks 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. Thanks! |
||
Escape->setName("ind.escape"); | ||
MissingVals[UI] = Escape; | ||
} | ||
|
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.
Above comment deserves update: