Skip to content
Snippets Groups Projects

Implement loop peeling from back

Merged Daniel Bauer requested to merge hyteg/pystencils:bauerd/peel-loop-back into backend-rework
All threads resolved!
Viewing commit 87726113
Show latest version
2 files
+ 21
6
Preferences
Compare changes
Files
2
@@ -48,7 +48,9 @@ class ReshapeLoops:
@@ -48,7 +48,9 @@ class ReshapeLoops:
peeled_ctr = self._factory.parse_index(
peeled_ctr = self._factory.parse_index(
cc.get_replacement(loop.counter.symbol)
cc.get_replacement(loop.counter.symbol)
)
)
peeled_idx = self._typify(loop.start + PsExpression.make(PsConstant(i)))
peeled_idx = self._elim_constants(
 
self._typify(loop.start + PsExpression.make(PsConstant(i)) * loop.step)
 
)
counter_decl = PsDeclaration(peeled_ctr, peeled_idx)
counter_decl = PsDeclaration(peeled_ctr, peeled_idx)
peeled_block = self._canon_clone.visit(loop.body, cc)
peeled_block = self._canon_clone.visit(loop.body, cc)
@@ -65,7 +67,9 @@ class ReshapeLoops:
@@ -65,7 +67,9 @@ class ReshapeLoops:
peeled_iters.append(peeled_block)
peeled_iters.append(peeled_block)
loop.start = self._elim_constants(
loop.start = self._elim_constants(
self._typify(loop.start + PsExpression.make(PsConstant(num_iterations)))
self._typify(
 
loop.start + PsExpression.make(PsConstant(num_iterations)) * loop.step
 
)
)
)
return peeled_iters, loop
return peeled_iters, loop
@@ -88,6 +92,13 @@ class ReshapeLoops:
@@ -88,6 +92,13 @@ class ReshapeLoops:
Tuple containing the modified loop and the peeled-off iterations (sequence of blocks).
Tuple containing the modified loop and the peeled-off iterations (sequence of blocks).
"""
"""
 
if not (
 
isinstance(loop.step, PsConstantExpr) and loop.step.constant.value == 1
 
):
 
raise NotImplementedError(
 
"Peeling iterations from the back of loops is only implemented for loops with unit step. Implementation is deferred until loop range canonicalization is available (also needed for the vectorizer)."
 
)
 
peeled_iters: list[PsBlock] = []
peeled_iters: list[PsBlock] = []
for i in range(num_iterations)[::-1]:
for i in range(num_iterations)[::-1]: