In computeLoadConstantCompareExitLimit, the addrec used to compute the
exit count should be from the loop which the exiting block belongs to.
Details
Diff Detail
Event Timeline
This is missing a test.
Please refer to llvm-project/llvm/test/Analysis/ScalarEvolution/pr48225.ll for inspiration.
@lebedev.ri Thanks, will add a test. Besides, the bug fixed in ea7ab5a42cd4 seems to have the same root cause.
Please reduce the test or give an elaborate explanation of the problem. So far it's not clear to me what was the problem and why it fixed this way.
llvm/lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
7849 | You require the IdxExpr be from a containing loop, which automatically makes IdxExpr invariant w.r.t. L. So this whole condition is just trivially false. Is that really what you want to make? | |
llvm/test/Analysis/ScalarEvolution/incorrect-exit-count.ll | ||
1 | Please commit this test separately using auto-generated checks from utils/update_analyze_test_checks.py. If you are addressing some bug from bugs.llvm.com, better name the test after this bug (like prXXXXX.ll). Then, apply your changes and re-run utils/update_analyze_test_checks.py on it. The diff will show what your patch has changed. This test is very big. You could also try to use bugpoint tool to reduce the test (see https://llvm.org/docs/Bugpoint.html), because now I cannot figure what's going on here. Both test reduction (if possible) and explanatory comments (which block/loop are causing the problem and why) would be extremely useful to understand your fix. |
llvm/lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
7849 | Sorry, the whole condition is trivially true. AddRecs from containing loops are always invariant w.r.t child loops. |
llvm/lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
7849 |
I see...Actually what I need is IdxExpr->getLoop()==L. Though in this case it won't exceed the scope L from where Idx is computed IIUC, I admit it's incorrect. Will do the change. | |
llvm/test/Analysis/ScalarEvolution/incorrect-exit-count.ll | ||
1 | I tried llvm-reduce but the output was not desirable, will add necessary comments, thanks! In short, the bug is that when computing the exit count of an outerloop's exiting block, the current computeLoadConstantCompareExitLimit method may choose an addrec of its child loop, which is incorrect. |
llvm/test/Analysis/ScalarEvolution/incorrect-exit-count.ll | ||
---|---|---|
1 | Then at least do the first step: commit this test as is with auto-generated checks, and then rebase your patch on top of that to show what has changed. |
llvm/test/Analysis/ScalarEvolution/incorrect-exit-count.ll | ||
---|---|---|
1 | Sorry, I don't understand well. Do you mean that I should separate it into two commits or only keep those changed checks? |
llvm/test/Analysis/ScalarEvolution/incorrect-exit-count.ll | ||
---|---|---|
1 | I mean two commits. First commit: this test, with no code changes, with auto-generated checks (use utils/update_analyze_test_checks.py to generate them). |
You require the IdxExpr be from a containing loop, which automatically makes IdxExpr invariant w.r.t. L. So this whole condition is just trivially false. Is that really what you want to make?