This is an archive of the discontinued LLVM Phabricator instance.

[LoopBoundSplit] Delete redundant loop guard
AbandonedPublic

Authored by Allen on Feb 10 2023, 12:37 AM.

Details

Summary

This changes try to remove the redundant loop guard,

For example, it transforms left code to right code:
```
    newbound = min(n, c)                    newbound = min(n, c)
    while(iv < newbound) {                  while(iv < newbound) {
       A                                      A
       B                                      B
       C                                      C
     }                                      }
     if (iv != n) {
        while (iv < n) {                    while (iv < n) {
           A                                  A
           C                                  C
         }                                  }
     }
```

Depand on D102234

Diff Detail

Event Timeline

Allen created this revision.Feb 10 2023, 12:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 12:37 AM
Allen requested review of this revision.Feb 10 2023, 12:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 12:37 AM
mkazantsev added a comment.EditedFeb 12 2023, 10:46 PM

The loops in form that are depicted here are not while (cond) {...} loops. They are do - while loops, and for them what you are doing is wrong.

What you are actually proposing is turn

newbound = min(n, c)
if (iv < newbound) {
  do {
    A
    B
    C
  } while (iv < newbound)
}
if (iv != n) {
  do {
    A
    B
    C
  } while (iv < n)
}

into

newbound = min(n, c)
if (iv < newbound) {
  do {
    A
    B
    C
  } while (iv < newbound)
}
do {
  A
  B
  C
} while (iv < n)

which is wrong when newbound = n.

mkazantsev requested changes to this revision.Feb 12 2023, 11:00 PM

This is wrong when new bound = original bound.

This revision now requires changes to proceed.Feb 12 2023, 11:00 PM
Allen abandoned this revision.Feb 13 2023, 12:41 AM

Thanks @mkazantsev for correcting