This is an archive of the discontinued LLVM Phabricator instance.

[SCF] Convert scf.while to scf.for
Needs ReviewPublic

Authored by arnab-oss on Jan 19 2022, 6:09 AM.

Details

Summary

This pass transforms scf.while operations to scf.for.

Before:

 %0 = scf.while (%i = %c0) : (index) -> index {
 %1 = arith.cmpi slt, %i, %arg1 : index
 scf.condition(%1) %i : index
 } do {
 ^bb0(%i: index):  // no predecessors
 %1 = arith.addi %i, %c1 : index
 %2 = arith.addi %arg2, %arg2 : i32
 memref.store %2, %arg0[%i] : memref<?xi32>
 scf.yield %1 : index
}

After:

%0 = scf.for %iv = %c0 to %arg1 step %c1 (%i = %c0) {
 %1 = arith.addi %iv, %c1 : index
 %2 = arith.addi %arg2, %arg2 : i32
 memref.store %2, %arg0[%i] : memref<?xi32>
 scf.yield %1 : index
}

Diff Detail

Event Timeline

arnab-oss created this revision.Jan 19 2022, 6:09 AM
arnab-oss requested review of this revision.Jan 19 2022, 6:09 AM
ftynse edited the summary of this revision. (Show Details)Jan 19 2022, 6:59 AM
ftynse added a reviewer: wsmoses.
arnab-oss updated this revision to Diff 401231.Jan 19 2022, 7:18 AM

Fixed build errors.