[llvm] [SimplifyIndVar] ICMP predicate conversion to EQ/NE (PR #144945)
Sergey Shcherbinin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 08:11:07 PDT 2025
SergeyShch01 wrote:
> This looks like this is duplicates large parts of LFTR without the safety checks. Please explain why LFTR doesn't handle the cases you care about.
This patch and LFTR have intersection - but it's not a duplicate. They together cover all reasonable target cases, while each of them alone addresses ony some part.
LFTR:
- works w/ loop exits only
- Supports a single case when a 'unique condition' is produced by icmp: at last loop iteration
- works w/ any kind of loop exit for which trip count can be calculated w/o high cost expansion
- reuses existing IV suitable for loop counter - if it's missing then LFTR isn't applied
This patch:
- works w/ any icmp (not necessarily writing to exit branch) - so they can be analigned w/ loop exits
- Supports three cases when a 'unique condition' is produced by icmp: at first iteration, at last iteration, when IV value is equal to second argument of icmp
- works only w/ icmp reading IV
- keep icmp using its original IV
The original motivation for this patch was the following loop where two loop exits were if-converted and CFGSimplify and then LFTR failed to calculate loop trip count. And also I generalized the idea and supported two other cases when EQ/NE predicate can be used.
// motivation example
void test(int* data) {
for (unsigned i = 1, j = 2; (data[i] & 8) && (i < 300); i++, j+=2)
data[j] = data[j - 1];
}
https://github.com/llvm/llvm-project/pull/144945
More information about the llvm-commits
mailing list