Skip to content

Conversation

@tommymcm
Copy link
Collaborator

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
Copy link
Collaborator 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
terapines-osc-cir pushed a commit to Terapines/clangir that referenced this pull request Sep 2, 2025
…trdecay` to `get_element` when possible (llvm#1761)

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.

---------

Co-authored-by: Henrich Lauko <[email protected]>
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