Skip to content

Conversation

@mahmood82
Copy link
Contributor

@mahmood82 mahmood82 commented Nov 18, 2025

This patch adds support for emitting a cir.bitcast when reinterpreting
values that have the same bit-width. This enables correct handling of
vector reinterpretation in CIR and aligns with the behavior of the LLVM IR
lowering.

Previously, equal-width reinterpretations were not handled, which caused
assertions or incorrect lowering when working with vector types or other
equal-sized aggregates.

Key points:

  • Introduces cir.bitcast emission when source and destination types have
    equal width and only reinterpretation is required.
  • Avoids unnecessary intermediate casts.
  • Enables upcoming work on vector reinterpretation and fixes gaps in the
    current type conversion pipeline.

Testing:

  • Added/updated CIR tests validating equal-width reinterpretation.
  • Verified end-to-end lowering through LLVM for vector types.

Implement VisitAsTypeExpr to lower AsTypeExpr expressions.

- Emit an error when source and destination types differ in bitwidth.
- When types already match, return the source value (no-op).
- Otherwise lower to a CIR bitcast using cir::CastOp with CastKind::bitcast.
Copy link
Collaborator

@RiverDave RiverDave left a comment

Choose a reason for hiding this comment

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

I normally don't do code reviews, but you should follow the skeleton for this function from OG codegen — see. We try not to deviate too much from it unless there's a strong enough reason for that.

@bcardosolopes
Copy link
Member

I normally don't do code reviews

Please do whenever you feel like, we really appreciate it :)

@github-actions
Copy link

github-actions bot commented Nov 20, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

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.

Seems like there's some code formatting issues, but LGTM after that!

@mahmood82 mahmood82 force-pushed the users/mahmood82/vec_reinterp branch from 1b96e30 to 898b7cc Compare November 25, 2025 11:58
@mahmood82
Copy link
Contributor Author

Seems like there's some code formatting issues, but LGTM after that!

Fixed..

@bcardosolopes
Copy link
Member

@mahmood82 after your first PR lands the testing should happen automatically, I suggest you run clang-format in your commits before pushing the PR

@bcardosolopes bcardosolopes merged commit 58ac26e into llvm:main Nov 25, 2025
6 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