Created attachment 20770 [details] IR that reproduces the bug I found a case in which SROA replaces an aligned access to an alloca with an access to a new alloca that is differently aligned, which e.g. causes crashes on SPARC (this appears to be the root cause of https://github.com/rust-lang/rust/issues/53181). In the attached IR, %_587 is an aligned alloca, and the pre-SROA code goes as follows ``` %CrateLint = type { [0 x i8], i8, [11 x i8] } ... %_587 = alloca %CrateLint, align 4 ... bb10.i: ; %26 is 4 bytes offset into the alloca, and therefore dword-aligned %19 = getelementptr inbounds %CrateLint, %CrateLint* %_587, i64 0, i32 2, i64 3 br label %bb13.i bb13.i: %_14.sroa.0.0.in.in.i = phi i8* [ %21, %bb12.i ], [ %20, %bb11.i ], [ %19, %bb10.i ] %_14.sroa.0.0.in.i = bitcast i8* %_14.sroa.0.0.in.in.i to i32* %_14.sroa.0.0.i = load i32, i32* %_14.sroa.0.0.in.i, align 4 ... ``` This loads `%_14.sroa.0.0.i` from a 4-aligned address. However, SROA generates the following code: ``` %_587.sroa.3 = alloca [7 x i8] bb10.i: ; preds = %start %_587.sroa.3.3..sroa_idx = getelementptr inbounds [7 x i8], [7 x i8]* %_587.sroa.3, i64 0, i64 3 br label %bb13.i bb13.i: ; preds = %bb12.i, %bb11.i, %bb10.i %_14.sroa.0.0.in.in.i = phi i8* [ %_587.sroa.6.0..sroa_cast7, %bb12.i ], [ %_587.sroa.6.0..sroa_cast6, %bb11.i ], [ %_587.sroa.3.3..sroa_idx, %bb10.i ] ... %_14.sroa.0.0.in.i = bitcast i8* %_14.sroa.0.0.in.in.i to i32* %_14.sroa.0.0.i = load i32, i32* %_14.sroa.0.0.in.i, align 4 ... ``` This performs the dword-aligned load out of `%_587.sroa.3.3..sroa_idx`, which is aligned 3 (mod 4), and therefore definitely not dword-aligned. Attached the minified reproducing IR (I hope that it doesn't have UB - I can send the fuller IR if you want, but it is much larger).
cc
cc @chandlerc & @davide - I think you know SROA well?
Looking.
https://reviews.llvm.org/D51335 .
Testing whether this patch fixes: https://github.com/rust-lang/rust/issues/53181
(In reply to John Paul Adrian Glaubitz from comment #5) > Testing whether this patch fixes: > https://github.com/rust-lang/rust/issues/53181 I can confirm that the patch fixes the Rust issue on sparc64 above.
Hans, we probably want to backport this one to 7 too.
r341094
(In reply to Eli Friedman from comment #8) > r341094 Thanks! Merged in r341220.