Add opportunity to fold any icmp instruction.
Diff Detail
Event Timeline
I think the patch description should also include the added poison check. (and also remove the extra semicolon)
@eopXD , please, review this change.
File formatted correctly, tests for icmp and poison value have been added
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | ||
---|---|---|
6935 | This change *does not* address this FIXME. Please restore the comment. No comment on the review otherwise. |
Thank you for review!
- I disabled checking for poison value.
*dyn_cast to poison* / use *isGuaranteedNotToBeUndefOrPoison* / use *containsUndefOrPoisonElement* are not correct way to check.
Please, offer your solution how to process it - so, I will not add it to this patch.
- @nikic , thank you for finding my mistake.
I added 4 tests. The solution is to process using one scheme:
%cmp = icmp eq ptr %iv, %iv_end br i1 %cmp, label %for.end, label %for.body
We create *iv_end* using SE.getBackedgeTakenCount, thus when we get *iv* equals to *iv_end* then we have to jump to if.end. Finally, we have to be confident that the second successors is equal to LoopLatch.
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | ||
---|---|---|
6941 | I don't think comparing with loop latch is the right condition here: You need to check for the loop header. In test current test cases these just happen to be the same. Can you add a test where the loop has more than one block? Probably even just inserting a dummy unconditional br to split the block would be enough. | |
llvm/test/Transforms/LoopStrengthReduce/lsr-term-fold.ll | ||
1 | Can you please rerun this script? The check line formatting looks a bit off. |
- Fix checking branch swap successors.
- Tests are formatted accroding to clang-format and passed.
For tests, the relevant script is llvm/utils/update_test_checks.py. You can run it as llvm/utils/update_test_checks.py --opt-bin build/bin/opt llvm/test/Transforms/LoopStrengthReduce/lsr-term-fold.ll.
Please make sure to update the commit message; it looks like the latest version doesn't address the poison issue IIUC
Last week, someone rewrote lit-tests style.
I use ./llvm/utils/update_test_checks.py to make correct style.
After passing build, will push changes.
I think this is change un-related to the topic of this patch.