Skip to content

[CIR] Extend CIR canonicalize to rewrite ptr_stride and array_to_ptrdecay to get_element when possible #1761

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

Merged
merged 4 commits into from
Jul 28, 2025

Conversation

tommymcm
Copy link
Contributor

Extended the CIRCanonicalizePass with new rewrite rules:

  • Rewrite ptr_stride (cast array_to_ptrdecay %base), %index to get_element %base[%index]
  • Rewrite ptr_stride (get_element %base[%index]), %stride to get_element %base[%index + %stride]
  • Rewrite cast array_to_ptrdecay %base, ptr<T> to get_element %base[0], ptr<T> if it is only used by load %ptr : T, store %val : T, %ptr, or get_member %ptr[field] : ptr<T> -> U

Updated CodeGen tests, and extended CIR-to-CIR test.

…o_ptrdecay` operations that can be simplified to `get_element`

Extended the `CIRCanonicalizePass` with new rewrite rules:
Rewrite `ptr_stride (cast array_to_ptrdecay %base), %index` to `get_element %base[%index]`
Rewrite `ptr_stride (get_element %base[%index]), %stride` to `get_element %base[%index + %stride]`
Rewrite `cast array_to_ptrdecay %base, ptr<T>` to `get_element %base[0], ptr<T>` if it is only used by `load %ptr : T`, `store %val : T, %ptr`, or `get_member %ptr[field] : ptr<T> -> U`
tommymcm and others added 3 commits July 28, 2025 09:32
…<T>()`

Co-authored-by: Henrich Lauko <xlauko@mail.muni.cz>
Co-authored-by: Henrich Lauko <xlauko@mail.muni.cz>
Co-authored-by: Henrich Lauko <xlauko@mail.muni.cz>
@tommymcm
Copy link
Contributor Author

Thanks for the review @xlauko, I've applied to requested changes.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already reviewed this internally, so no extra feedback. Please double check if you can also upstream this when you have the bandwidth. LGTM

@bcardosolopes bcardosolopes merged commit a42534e into llvm:main Jul 28, 2025
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants