Open sarah-quinones opened 2 days ago
because llvm thinks they're passed by pointer since the struct is large.
LLVM doesn't just think this, it knows that the struct has been passed by pointer. The rustc ABI (at least for cg_ssa) has Scalar, ScalarPair, and Aggregate ABIs (this link will probably rot but here's the ABI enum currently: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.Abi.html). Your type Good
is a ScalarPair
and your Big
is an Aggregate
, and that ABI is always by-pointer.
So there might be another solution here: Figure out how to splat types with more than 2 fields.
is there room for an opt-in attribute that tells rustc that i want to pass a struct as scalars (in the rust abi)? for example
#[repr(scalar)]
struct Matrix {
ptr: *mut f64,
nrows: usize,
ncols: usize,
row_stride: isize,
col_stride: isize,
}
Sure. But the hard part here is implementing that, not coming up with what the attribute looks like.
For arguments it would be possible to use PassMode::Cast (this is something internal to the abi computation code in rustc), but this would cause worse performance in unoptimized builds as our PassMode::Cast handling is very naive. It basically writes your entire value to the stack and then reloads the values for the individual registers to pass as arguments and does the opposite on the callee side.
https://godbolt.org/z/b8as1TxdP
i expected the functions to emit similar codegen, but the bad one doesn't get the noalias on the references themselves because llvm thinks they're passed by pointer since the struct is large.
maybe alias.scope can help with this?
Meta
rustc --version --verbose
: