Skip to content

Commit a33f1a3

Browse files
authoredDec 13, 2023
Rollup merge of #118864 - farnoy:masked-load-store-fixes, r=workingjubilee
Fix alignment passed down to LLVM for simd_masked_load Follow up to #117953 The alignment for a masked load operation should be that of the element/lane, not the vector as a whole It can produce miscompilations after the LLVM optimizer notices the higher alignment and promotes this to an unmasked, aligned load followed up by blend/select - https://rust.godbolt.org/z/KEeGbevbb
2 parents 2d1d443 + 95b5a80 commit a33f1a3

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed
 

‎compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15681568

15691569
// Alignment of T, must be a constant integer value:
15701570
let alignment_ty = bx.type_i32();
1571-
let alignment = bx.const_i32(bx.align_of(values_ty).bytes() as i32);
1571+
let alignment = bx.const_i32(bx.align_of(values_elem).bytes() as i32);
15721572

15731573
// Truncate the mask vector to a vector of i1s:
15741574
let (mask, mask_ty) = {

‎tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern "platform-intrinsic" {
2121
#[no_mangle]
2222
pub unsafe fn load_f32x2(mask: Vec2<i32>, pointer: *const f32,
2323
values: Vec2<f32>) -> Vec2<f32> {
24-
// CHECK: call <2 x float> @llvm.masked.load.v2f32.p0(ptr {{.*}}, i32 {{.*}}, <2 x i1> {{.*}}, <2 x float> {{.*}})
24+
// CHECK: call <2 x float> @llvm.masked.load.v2f32.p0(ptr {{.*}}, i32 4, <2 x i1> {{.*}}, <2 x float> {{.*}})
2525
simd_masked_load(mask, pointer, values)
2626
}
2727

‎tests/codegen/simd-intrinsic/simd-intrinsic-generic-masked-store.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "platform-intrinsic" {
2020
// CHECK-LABEL: @store_f32x2
2121
#[no_mangle]
2222
pub unsafe fn store_f32x2(mask: Vec2<i32>, pointer: *mut f32, values: Vec2<f32>) {
23-
// CHECK: call void @llvm.masked.store.v2f32.p0(<2 x float> {{.*}}, ptr {{.*}}, i32 {{.*}}, <2 x i1> {{.*}})
23+
// CHECK: call void @llvm.masked.store.v2f32.p0(<2 x float> {{.*}}, ptr {{.*}}, i32 4, <2 x i1> {{.*}})
2424
simd_masked_store(mask, pointer, values)
2525
}
2626

0 commit comments

Comments
 (0)
Please sign in to comment.