Skip to content

[Xtensa] Enable ESP32-S3 QR registers in inline asm (LLVM-608) - #145

Open
Dominaezzz wants to merge 1 commit into
espressif:release/esp_23.xfrom
Dominaezzz:qreg-upstream
Open

Dominaezzz wants to merge 1 commit into
espressif:release/esp_23.xfrom
Dominaezzz:qreg-upstream

Conversation

@Dominaezzz

Copy link
Copy Markdown

Description

The Xtensa backend defines the ESP32-S3 PIE instructions and QR registers, but keeps the QR registers reserved and unavailable to LLVM’s register allocator. This change enables the QR register class on ESP32-S3 and adds the q inline-assembly constraint for 128-bit vectors with <16 x i8>, <8 x i16>, and <4 x i32> lanes.

It also adds QR register copies, spill handling, and vector load/store lowering so vector values can move between memory and Q registers and remain usable under register pressure. The change is gated on ESP32-S3 operations, leaving other Xtensa targets unchanged.

This provides the LLVM backend support required by the Rust inline-assembly change.

Related

Testing

Configured a fresh Release build with the Xtensa target and built llc and FileCheck. Ran the new qr-inline-asm.ll regression with -mtriple=xtensa -mcpu=esp32s3 -verify-machineinstrs. It passed, covering all three vector shapes, vector memory operations, constants, and Q-register spill pressure.


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@github-actions github-actions Bot changed the title [Xtensa] Enable ESP32-S3 QR registers in inline asm [Xtensa] Enable ESP32-S3 QR registers in inline asm (LLVM-608) Nov 21, 2026
@cakgok

cakgok commented Nov 21, 2026

Copy link
Copy Markdown

Hi!

I'm not Espressif, so take it with a grain of salt.

So, there is a bit of a problem with unreserving the registers here. QRs are on the coprocessor. And the coprocessor is a little peculiar. This is partly documented on ESP-IDF and a (very good) explanation of its restrictions was mentioned here. Basically, if we enable them unconditionally, we can panic or incur big context switch costs.

This is not to say it can't be done. We just have to be more surgical instead of letting the compiler take control everywhere.

At a glance there seem to be some legalization issues. This would make vector ops without selection patterns legal, which would crash. Spill logic also might need some refinement.

I've also been working on QRs for a while, before I got derailed myself with register scavenger. I was meaning to get SLP/Loop vectorization working, and it does - albeit with a very primitive TTI. For me it was mainly academic, just to learn the plumbing of LLVM. And Xtensa felt like a good place given its (relative) simplicity. Nice to see there is some actual interest.

If you're interested, I think we could combine with your q constraints and it should fit seamlessly.(considering the limitations of course)

I have to ask whether the Espressif team would be willing (or have capacity) to review, though. I meant to wait until we could sort out the scavenger PRs, but might as well ask now and save us the potential double work.

@Dominaezzz

Copy link
Copy Markdown
Author

Basically, if we enable them unconditionally, we can panic or incur big context switch costs.

Thanks for the link. I kinda had this at the back of my mind but didn't know others had thought of it.
I'm going to be using this with Rust and esp-hal so multiple tasks on a core weren't a concern to me.
If we could do this in a very opt-in manner that would be ideal, I strictly just want auto load/store in asm blocks and nothing more.

If you're interested, I think we could combine with your q constraints and it should fit seamlessly.(considering the limitations of course)

I have to ask whether the Espressif team would be willing (or have capacity) to review, though. I meant to wait until we could sort out the scavenger PRs, but might as well ask now and save us the potential double work.

I would be interested in saving us the double work. I'm am very new to LLVM here and I made heavy use of Codex do this.

This is not to say it can't be done. We just have to be more surgical instead of letting the compiler take control everywhere.

I think I understand what you're saying here but don't know how to go about it.

At a glance there seem to be some legalization issues. This would make vector ops without selection patterns legal, which would crash. Spill logic also might need some refinement.

Ah got it

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants