-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Optimize fptrunc(x)>=C1 --> x>=C2 #99475
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 1 commit
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8031,6 +8031,101 @@ static Instruction *foldFCmpReciprocalAndZero(FCmpInst &I, Instruction *LHSI, | |||||||||
| return new FCmpInst(Pred, LHSI->getOperand(1), RHSC, "", &I); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| // Fold fptrunc(x) < constant --> x < constant if possible. | ||||||||||
| static Instruction *foldFCmpFpTrunc(FCmpInst &I, Instruction *LHSI, | ||||||||||
|
||||||||||
| static Instruction *foldFCmpFpTrunc(FCmpInst &I, Instruction *LHSI, | |
| static Instruction *foldFCmpFpTrunc(FCmpInst &I, const Instruction &FPTrunc, |
Outdated
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.
uge, ule cases not tested. Plus negative test for others
Outdated
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.
Seems more like a "Src" than a "Left" type
Outdated
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.
Seems more like a "Dest" than a "Right" type
Outdated
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.
Move this comment down to the loop
Outdated
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.
Move this down to where it's used before the loop
Outdated
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.
| APFloat LowBound = RoundDown ? ExtNextRValue : ExtRValue; | |
| APFloat UpBound = RoundDown ? ExtRValue : ExtNextRValue; | |
| const APFloat &LowBound = RoundDown ? ExtNextRValue : ExtRValue; | |
| const APFloat &UpBound = RoundDown ? ExtRValue : ExtNextRValue; |
Outdated
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.
Do these compares amount to the same as directly using losesInfo?
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.
I feel like this should be a directly computable constant without a binary search
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.
Yes, binary search can be replaced by average value for most cases, and I got confused before. However, it seems a little tricky to tackle the comparison with the largest value. I tried several ways to work around, but all are unsatisfactory. Might be late for the final solution.
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.
Although the absence of next(max_float) which is infinity actually, we can image its existence in wider types, and it should equal to max_float + (max_float - prev(max_float)) in most cases (if not all). A bound check can ensure its correctness.
This method balance the efficiency and correctness, and keep consistence with logics for other floats despite the fact that it might not be standard for all float types.
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 you planning on switching the patch to do this? Needs comments either way
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.
I'm trying to, but it seems that the rule can't be applied to ppc_fp128 when converted from max_float due to unknown precision loss. I want more investigation before decision
Outdated
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.
| // if 'RoudnDown' == false, 'DownBound' can't be the final round value | |
| // if 'RoundDown' == false, 'DownBound' can't be the final round value |
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.
This also covers other compare types, can you express that in the comment