This patch fixes a bug in the existing implementation of detectAsFloorDiv,
where floordivs with numerator with non-zero constant term and floordivs with
numerator only consisting of a constant term were not being detected.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for the patch! Please fix the clang-format errors. Other than that, this seems good to me. Let's wait for one of the others to take a look as well.
mlir/lib/Analysis/AffineStructures.cpp | ||
---|---|---|
1556 | This now also allows numerators which are just zero, right? I think it makes sense to support that (and it will be needed to support subtraction on sets with divisions that happen to have numerator zero), but maybe it's worth mentioning in the commit message. |
Thanks for this enhancement!
- I tried an example, but didn't get the expected result. Can you please clarify ?
- Format the commit msg to wrap around.
- If my understanding of (1) is correct, can you also extend the doc comment of the function to use an example that has non-zero constant upper bound ?
mlir/lib/Analysis/AffineStructures.cpp | ||
---|---|---|
1561 | This would be incorrect, I think. You would need to still initialize the expr with zero. I tried the example: Finally, the dividend should be i + j + 1, but I think it would detect i + j + 2 now. On a side note, it means, testing is insufficient as it is only checking if all ids are detected, but not verifying the results. |
mlir/lib/Analysis/AffineStructures.cpp | ||
---|---|---|
1561 | The detected dividend will be i + j + 1. The upper-bound inequality is: 4q <= i + j + 1 rearranging it we get: i + j - 4q + 1 >= 0 From which, the constant term extracted is 1. Is there something I'm missing? |
Thanks for the clarification, will take another look in some time.
mlir/lib/Analysis/AffineStructures.cpp | ||
---|---|---|
1561 | I just noticed that the loop below runs 0 to cst.getNumCols() - 1; this means the constant term is not added once again. So, you are correct. I was under the impression that the loop is 0 to cst.getNumCols(), and the constant 1 in the above case would get added once again. So, this works too. |
Addressed comments.
mlir/lib/Analysis/AffineStructures.cpp | ||
---|---|---|
1561 | Regarding the verification in testing: due to how the current implementation is exposed, it is hard to test if the result matches. There is another patch (https://reviews.llvm.org/D106662) that refactors this implementation and provides better a better way to test. |
This now also allows numerators which are just zero, right? I think it makes sense to support that (and it will be needed to support subtraction on sets with divisions that happen to have numerator zero), but maybe it's worth mentioning in the commit message.