Improved Branch Elimination
pystencils 2.0 already features a branch-elimination pass (backend.transformations.EliminateBranches) that evaluates integer conditions based on known values and ranges from enclosing loops or conditionals. At this time, that pass still has a few limitations:
-
EliminateBranchesis currently unable to perform its analysis inside loops with non-unit strides, and throws an exception if one is encountered. -
EliminateBranchesonly takes symbols into account that occur directly within loop or conditional nodes, but ignores symbols that affinely depend on loop counters or restricted symbols. To illustrate, in the following IR, theifis eliminated:
for(j: int64 = 4; j < 12; j += 1)
{
if(j < 3)
{
k: int64 = 3 * j;
}
}
but here, it is not:
for(i: int64 = 4; i < 12; i += 1)
{
j: int64 = -1 + i;
if(j < 3)
{
k: int64 = 3 * j;
}
}
At least these two deficiencies should be corrected; in particular the second one leads to a lot of missed optimization opportunities.