Rollup merge of #128537 - Jamesbarford:118980-const-vector, r=RalfJung,nikic

const vector passed through to codegen

This allows constant vectors using a repr(simd) type to be propagated
through to the backend by reusing the functionality used to do a similar
thing for the simd_shuffle intrinsic

#118209

r​? RalfJung
This commit is contained in:
Guillaume Gomez 2024-08-12 17:09:15 +02:00 committed by GitHub
commit aea5087964
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 170 additions and 17 deletions

View file

@ -97,11 +97,6 @@ impl<'ll> CodegenCx<'ll, '_> {
unsafe { llvm::LLVMConstArray2(ty, elts.as_ptr(), len) }
}
pub fn const_vector(&self, elts: &[&'ll Value]) -> &'ll Value {
let len = c_uint::try_from(elts.len()).expect("LLVMConstVector elements len overflow");
unsafe { llvm::LLVMConstVector(elts.as_ptr(), len) }
}
pub fn const_bytes(&self, bytes: &[u8]) -> &'ll Value {
bytes_in_context(self.llcx, bytes)
}
@ -221,6 +216,11 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
struct_in_context(self.llcx, elts, packed)
}
fn const_vector(&self, elts: &[&'ll Value]) -> &'ll Value {
let len = c_uint::try_from(elts.len()).expect("LLVMConstVector elements len overflow");
unsafe { llvm::LLVMConstVector(elts.as_ptr(), len) }
}
fn const_to_opt_uint(&self, v: &'ll Value) -> Option<u64> {
try_as_const_integral(v).and_then(|v| unsafe {
let mut i = 0u64;