llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Refactor alignment attributes to use `llvm::MaybeAlign` and the `IntValidAlignment` constraint

Open amd-eochoalo opened this issue 1 year ago • 9 comments

The IntValidAlignment constraint is currently being used in the vector dialect to verify that the alignment is a positive integer power of two. The memref and SPIR-V dialects also contain operations which denote the alignment of memory operations, however they do not yet use the IntValidAlignment constraint.

After modifying the memory operations in the memref and SPIR-V dialects to use the IntValidAlignment constraint, one can also create constructors for these operations which take an instance of llvm::MaybeAlign as an optional parameter similar to how constructors in the vector dialect are defined here:

https://github.com/llvm/llvm-project/blob/a3eb311ad3769789ced18cc4f0fba31f04293045/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td#L1726-L1734

Finally, one improvement that can be made to all three dialects is to create an interface which returns an llvm::MaybeAlign as opposed to an std::optional<uint64_t>. It could be named getMaybeAlign.

amd-eochoalo avatar Aug 27 '25 18:08 amd-eochoalo

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
  2. Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

llvmbot avatar Aug 27 '25 18:08 llvmbot

@llvm/issue-subscribers-good-first-issue

Author: Erick Ochoa Lopez (amd-eochoalo)

[The `IntValidAlignment` constraint](https://github.com/llvm/llvm-project/pull/155259) is currently being used in the vector dialect to verify that the alignment is a positive integer power of two. The memref and SPIR-V dialects also contain operations which denote the alignment of memory operations, however they do not yet use the `IntValidAlignment` constraint.

After modifying the memory operations in the memref and SPIR-V dialects to use the IntValidAlignment constraint, one can also create constructors for these operations which take an instance of llvm::MaybeAlign as an optional parameter similar to how constructors in the vector dialect are defined here:

https://github.com/llvm/llvm-project/blob/a3eb311ad3769789ced18cc4f0fba31f04293045/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td#L1726-L1734

Finally, one improvement that can be made to all three dialects is to create an interface which returns an llvm::MaybeAlign as opposed to an std::optional&lt;uint64_t&gt;. It could be named getMaybeAlign.

llvmbot avatar Aug 27 '25 18:08 llvmbot

@llvm/issue-subscribers-mlir

Author: Erick Ochoa Lopez (amd-eochoalo)

[The `IntValidAlignment` constraint](https://github.com/llvm/llvm-project/pull/155259) is currently being used in the vector dialect to verify that the alignment is a positive integer power of two. The memref and SPIR-V dialects also contain operations which denote the alignment of memory operations, however they do not yet use the `IntValidAlignment` constraint.

After modifying the memory operations in the memref and SPIR-V dialects to use the IntValidAlignment constraint, one can also create constructors for these operations which take an instance of llvm::MaybeAlign as an optional parameter similar to how constructors in the vector dialect are defined here:

https://github.com/llvm/llvm-project/blob/a3eb311ad3769789ced18cc4f0fba31f04293045/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td#L1726-L1734

Finally, one improvement that can be made to all three dialects is to create an interface which returns an llvm::MaybeAlign as opposed to an std::optional&lt;uint64_t&gt;. It could be named getMaybeAlign.

llvmbot avatar Aug 27 '25 20:08 llvmbot

Can I please volunteer for this issue? Thank you!

nimit25 avatar Aug 27 '25 22:08 nimit25

@nimit25 , sure! Please feel free to ask questions. It may be better to split this ticket into two PRs. One where the alignment attributes are constraint by IntValidConstraint and the other one with the interface and constructors.

amd-eochoalo avatar Aug 28 '25 12:08 amd-eochoalo

@nimit25, are you still working on this task? It seems there hasn't been any progress for two weeks.

jiang1997 avatar Sep 12 '25 06:09 jiang1997

Haven't had a chance to start on it. Looks you beat me to the PR. You can go ahead with the implementation :)

nimit25 avatar Sep 12 '25 20:09 nimit25

Hi,

Is this issue still available to work on?

MDerazNasr avatar Mar 30 '26 20:03 MDerazNasr

@MDerazNasr, thanks for your interesting. This ticket was worked on and partially completed. I'll close it and reopen another one once there is a clear direction on the missing item. Thanks!

amd-eochoalo avatar Apr 01 '26 13:04 amd-eochoalo