-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Enabling GVN produces a const allocation with the wrong alignment? #117761
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
Comments
This issue is a bit old but I've now minimized the reproducer, it's in the description. @cjgillot the assertion that's failing here looks to me like it is simply too picky, and it should be checking if the alignment of the allocation is |
I agree the assertion is just too picky. I expect the subtlety of needing to pass the larger alignment for the llvm constant. |
I can't figure out what you mean here. What LLVM constant? Why is there subtelty? Maybe I just don't understand what's going on with GVN here, I'm assuming that GVN has merged two constants together so that we're now loading part of a more-aligned constant to get a less-aligned one. Is that wrong? |
I mean, this is codegen code. It creates a constant for llvm. That constant has some alignment. We need to pick the right one, between the lhs and rhs of the assert. |
Where are we picking an alignment? Is it down here?
|
smaller repro: auto-reduced (treereduce-rust): struct S(i32);
struct SmallStruct(f32, Option<S>, &'static [f32]);
fn main() {
let mut s = S(1);
s.0 = 3;
const SMALL_VAL: SmallStruct = SmallStruct(4., Some(S(1)), &[]);
let SmallStruct(a, b, c) = SMALL_VAL;
}
original code
original: // skip-filecheck
// unit-test: DataflowConstProp
// EMIT_MIR_FOR_EACH_BIT_WIDTH
#[derive(Copy, Clone)]
struct S(i32);
#[derive(Copy, Clone)]
struct SmallStruct(f32, Option<S>, &'static [f32]);
#[derive(Copy, Clone)]
struct BigStruct(f32, Option<S>, &'static [f32]);
// EMIT_MIR struct.main.DataflowConstProp.diff
fn main() {
let mut s = S(1);
let a = s.0 + 2;
s.0 = 3;
let b = a + s.0;
const SMALL_VAL: SmallStruct = SmallStruct(4., Some(S(1)), &[]);
let SmallStruct(a, b, c) = SMALL_VAL;
static SMALL_STAT: &SmallStruct = &SmallStruct(9., None, &[13.]);
let SmallStruct(a, b, c) = *SMALL_STAT;
let ss = SmallStruct(a, b, c);
const BIG_VAL: BigStruct = BigStruct(25., None, &[]);
let BigStruct(a, b, c) = BIG_VAL;
static BIG_STAT: &BigStruct = &BigStruct(82., Some(S(35)), &[45., 72.]);
let BigStruct(a, b, c) = *BIG_STAT;
// We arbitrarily limit the size of synthetized values to 4 pointers.
// `BigStruct` can be read, but we will keep a MIR aggregate for this.
let bs = BigStruct(a, b, c);
} Version information
Command: Program output
|
I don't really know. TBH, the simplest solution is a codegen test, and check that the generated constant has the right over-alignment. |
I don't have confidence in my ability to do that, so I think it would unblock you faster if you took this issue. I feel like just this diff is a fix for this ICE: diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs
index e8c58f6b6f8..794cbd315b7 100644
--- a/compiler/rustc_codegen_ssa/src/mir/operand.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs
@@ -132,7 +132,7 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
offset: Size,
) -> Self {
let alloc_align = alloc.inner().align;
- assert_eq!(alloc_align, layout.align.abi);
+ assert!(alloc_align >= layout.align.abi);
let read_scalar = |start, size, s: abi::Scalar, ty| {
match alloc.0.read_scalar( But I don't understand why the assertion was exact in the first place, or what the hazard would be from over-aligning the allocation. |
Tolerate overaligned MIR constants for codegen. Fixes rust-lang/rust#117761 cc `@saethlin`
Tolerate overaligned MIR constants for codegen. Fixes rust-lang/rust#117761 cc `@saethlin`
Tolerate overaligned MIR constants for codegen. Fixes rust-lang/rust#117761 cc `@saethlin`
Error:
That's this:
rust/compiler/rustc_codegen_ssa/src/mir/operand.rs
Lines 128 to 135 in 06e02d5
The GVN MIR diff is this:
searched nightlies: from nightly-2023-06-01 to nightly-2023-11-08
regressed nightly: nightly-2023-10-30
searched commit range: e5cfc55...608e968
regressed commit: 83c9732
bisected with cargo-bisect-rustc v0.6.7
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
The text was updated successfully, but these errors were encountered: