-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Move icmp ult
before mul nuw
by a constant
#56563
Comments
icmp ult
before wide mul nuw
by a constanticmp ult
before mul nuw
by a constant
I think it is the other way around, though I don't have a mathematical proof for it. In any case, using the rounding mode you have suggested is incorrect for x=5, B=2, C=11 or C=9; but using the opposite rounding mode does work: |
Thanks, @ekatz; you're right. Apparently I rounded up in making the I suppose it could also be |
I've prepared a patch, planning to send it for review ~soon. |
This diff adds folds for patterns like X * A < B where A, B are constants and "mul" has either "nsw" or "nuw". (to address #56563). Test plan: 1/ ninja check-llvm check-clang 2/ Bootstrapped LLVM/Clang pass tests Differential revision: https://reviews.llvm.org/D130039
This diff adds folds for patterns like X * A < B where A, B are constants and "mul" has either "nsw" or "nuw". (to address llvm/llvm-project#56563). Test plan: 1/ ninja check-llvm check-clang 2/ Bootstrapped LLVM/Clang pass tests Differential revision: https://reviews.llvm.org/D130039
This diff adds folds for patterns like X * A < B where A, B are constants and "mul" has either "nsw" or "nuw". (to address llvm/llvm-project#56563). Test plan: 1/ ninja check-llvm check-clang 2/ Bootstrapped LLVM/Clang pass tests Differential revision: https://reviews.llvm.org/D130039
Overview: When the multiplication is
nuw
andB
&C
are constants, transformx * B < C
→a < ⌈C / B⌉
x * B ≤ C
→a ≤ ⌊C / B⌋
Validity proof for a specific example, as a demonstration: https://alive2.llvm.org/ce/z/H-W9Zb
This is particularly worth doing in that example, since other existing transformations can then remove the
zext
+trunc
:And that means much tidier output overall:
(This is a sibling issue to #56562, which discusses a similar thing for
umul.with.overflow
)EDIT: Updated to not have this need to care about the
zext
-- other existing things will handle that already.The text was updated successfully, but these errors were encountered: