Skip to content

Optimize constant casts to avoid unnecessary capabilities #302

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LegNeato
Copy link
Collaborator

Add constant folding for widening casts (u8->u32, f32->f64) to avoid creating intermediate types. Remove capability checks during type creation and add bidirectional validation in linker to remove unused type capabilities.

Fixes #300

@LegNeato
Copy link
Collaborator Author

LegNeato commented Jun 27, 2025

I think this is safe to do...everywhere we widen a const, just replace with a wider const, after everything is done look to see what types we use and match the capabilities used. But I haven't really thought through all the cases. One thing that can happen if there are a ton of constant casts we could be creating a ton of constants rather than a ton of cast instructions...not sure if that is better or worse from a perf perspective.

Add constant folding for widening casts (u8->u32, f32->f64) to avoid creating
intermediate types. Remove capability checks during type creation and add
bidirectional validation in linker to remove unused type capabilities.

Fixes Rust-GPU#300
@nazar-pc
Copy link
Contributor

Will this handle a case like u32::from(K)? To rustc/LLVM it is basically the same thing, but likely requires inlining to happen first.

@LegNeato
Copy link
Collaborator Author

LegNeato commented Jun 28, 2025

No, this only does as casts.

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.

Capability is required unexpectedly for constant cast
2 participants