Skip to content

Implement loop unrolling or even jump threading #127

Open
@sgraf812

Description

... as described by Andreas here. From what I've read, it's basically the same as what the dreaded PhiBElimination did before, e.g. redirecting control flow when the result is known coming from some basic block.

Loop unrolling will probably also play nicely with CommonSubexpressionElimination, in that it will do invariant code motion if unrolled at least once! After all, the loop is still dominated by the first unroll, which computes invariant code (#126), which will be identified and removed by CommonSubexpressionElimination. E.g.:

int i = 0;
int j = System.in.read(); /* Something that isn't constant folded */
while (i < 10) {
   int k = j + 5;
   if (k < 10) {
     i++;
  }
}

/*
===
Unroll once 
===
*/

int i = 0;
int j = System.in.read();
if (i < 10) {
  int k = j + 5;
  if (k < 10) {
    i++;
  }
  while (i < 10) {
    int k2 = j + 5;
    if (k2 < 10) {
      i++;
    }
  }
}

/*
===
CSE
===
*/

int i = 0;
int j = System.in.read();
if (i < 10) {
  int k = j + 5;
  if (k < 10) {
    i++;
  }
  while (i < 10) {
    if (k < 10) {
      i++;
    }
  }
}

... Nice.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions