Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PASS] Loop bound hoisting/Demote bound to if #33

Merged
merged 3 commits into from
Oct 13, 2021
Merged

Conversation

kumasento
Copy link
Owner

@kumasento kumasento commented Oct 11, 2021

Two passes are added -

  • -loop-bound-hoisting: move the bound calculation between two nested scf.for out of the outermost loop.
  • -demote-bound-to-if: move the bound conditions that involve outer loop indvars into an inner affine.if.

These two together can turn an example code like

// phism-opt -demote-bound-to-if -fold-if -lower-affine -loop-bound-hoisting -loop-coalescing
#map0 = affine_map<()[s0, s1, s2] -> (0, (-s0 + s1 * 32 + 1) ceildiv 2, s1 * 8 + s2 * 8)>
#map1 = affine_map<()[s0, s1, s2, s3] -> ((s0 + s2 * 32 + 29) floordiv 2 + 1, s1, s2 * 8 + s3 * 8 + 16)>
#map2 = affine_map<(d0)[s0, s1] -> (s0 * 32, s1 * 32 + 2, d0 * 2 + 1, d0 * 4 - s1 * 32 - 31)>
#map3 = affine_map<(d0)[s0, s1, s2] -> (s1 * 32 + 32, d0 * 4 - s2 * 32 + 3, s0 * 2 + s2 * 32 + 28, d0 * 2 + s0)>

func @jacobi(%arg0: index, %arg1: index, %arg2: index, %arg3: index, %arg4: memref<32x32xf32>) attributes {scop.pe} {
  affine.for %arg5 = max #map0()[%arg1, %arg3, %arg2] to min #map1()[%arg1, %arg0, %arg2, %arg3] {
    affine.for %arg6 = max #map2(%arg5)[%arg3, %arg2] to min #map3(%arg5)[%arg1, %arg3, %arg2] {
      %0 = affine.load %arg4[%arg5, %arg6] : memref<32x32xf32>
      %1 = mulf %0, %0 : f32
      affine.store %1, %arg4[%arg5, %arg6] : memref<32x32xf32>
    }
  }
  return
}

into a version that contains a single scf.for

@kumasento kumasento self-assigned this Oct 11, 2021
@kumasento kumasento added the enhancement New feature or request label Oct 11, 2021
@kumasento kumasento changed the title [PASS] Loop bound hoisting [PASS] Loop bound hoisting/Demote bound to if Oct 12, 2021
@kumasento kumasento merged commit 60ea6e0 into main Oct 13, 2021
@kumasento kumasento deleted the loop-coalescing branch October 13, 2021 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant