Skip to content

Commit a49316d

Browse files
committed
Auto merge of #56329 - eddyb:load-operand-overaligned, r=nikomatsakis
rustc_codegen_llvm: don't overalign loads of pair operands. Counterpart to #56300, but for loads instead of stores.
2 parents 5f387a6 + 51cf4e9 commit a49316d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/librustc_codegen_llvm/builder.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -589,17 +589,23 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
589589
});
590590
OperandValue::Immediate(to_immediate(self, llval, place.layout))
591591
} else if let layout::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
592-
let mut load = |i, scalar: &layout::Scalar| {
592+
let b_offset = a.value.size(self).align_to(b.value.align(self).abi);
593+
594+
let mut load = |i, scalar: &layout::Scalar, align| {
593595
let llptr = self.struct_gep(place.llval, i as u64);
594-
let load = self.load(llptr, place.align);
596+
let load = self.load(llptr, align);
595597
scalar_load_metadata(self, load, scalar);
596598
if scalar.is_bool() {
597599
self.trunc(load, self.cx().type_i1())
598600
} else {
599601
load
600602
}
601603
};
602-
OperandValue::Pair(load(0, a), load(1, b))
604+
605+
OperandValue::Pair(
606+
load(0, a, place.align),
607+
load(1, b, place.align.restrict_for_offset(b_offset)),
608+
)
603609
} else {
604610
OperandValue::Ref(place.llval, None, place.align)
605611
};

src/test/codegen/issue-56267-2.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -C no-prepopulate-passes
2+
3+
#![crate_type="rlib"]
4+
5+
#[allow(dead_code)]
6+
pub struct Foo<T> {
7+
foo: u64,
8+
bar: T,
9+
}
10+
11+
// The load from bar.1 should have alignment 4. Not checking
12+
// other loads here, as the alignment will be platform-dependent.
13+
14+
// CHECK: %{{.+}} = load i32, i32* %{{.+}}, align 4
15+
#[no_mangle]
16+
pub fn test(x: Foo<(i32, i32)>) -> (i32, i32) {
17+
x.bar
18+
}

0 commit comments

Comments
 (0)