Skip to content

Commit 57a5548

Browse files
committed
[SROA] Don't shrink volatile load past end
For volatile atomic, this may result in a verifier errors, if the new alloca type is not legal for atomic accesses. I've opted to disable this special case for volatile accesses in general, as changing the size of the volatile access seems dubious in any case. Fixes #64721.
1 parent 24f437f commit 57a5548

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@ class llvm::sroa::AllocaSliceRewriter
27132713
NewEndOffset == NewAllocaEndOffset &&
27142714
(canConvertValue(DL, NewAllocaTy, TargetTy) ||
27152715
(IsLoadPastEnd && NewAllocaTy->isIntegerTy() &&
2716-
TargetTy->isIntegerTy()))) {
2716+
TargetTy->isIntegerTy() && !LI.isVolatile()))) {
27172717
Value *NewPtr =
27182718
getPtrToNewAI(LI.getPointerAddressSpace(), LI.isVolatile());
27192719
LoadInst *NewLI = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), NewPtr,

llvm/test/Transforms/SROA/basictest.ll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,38 @@ bb7:
19681968
ret void
19691969
}
19701970

1971+
define i32 @load_atomic_volatile_past_end() {
1972+
; CHECK-LABEL: @load_atomic_volatile_past_end(
1973+
; CHECK-NEXT: [[A:%.*]] = alloca i1, align 1
1974+
; CHECK-NEXT: [[A_0_V:%.*]] = load atomic volatile i32, ptr [[A]] seq_cst, align 1
1975+
; CHECK-NEXT: ret i32 [[A_0_V]]
1976+
;
1977+
%a = alloca i1, align 1
1978+
%v = load atomic volatile i32, ptr %a seq_cst, align 4
1979+
ret i32 %v
1980+
}
1981+
1982+
define i32 @load_volatile_past_end() {
1983+
; CHECK-LABEL: @load_volatile_past_end(
1984+
; CHECK-NEXT: [[A:%.*]] = alloca i1, align 1
1985+
; CHECK-NEXT: [[A_0_V:%.*]] = load volatile i32, ptr [[A]], align 1
1986+
; CHECK-NEXT: ret i32 [[A_0_V]]
1987+
;
1988+
%a = alloca i1, align 1
1989+
%v = load volatile i32, ptr %a, align 4
1990+
ret i32 %v
1991+
}
1992+
1993+
define i32 @load_atomic_past_end() {
1994+
; CHECK-LABEL: @load_atomic_past_end(
1995+
; CHECK-NEXT: [[A_0_LOAD_EXT:%.*]] = zext i1 undef to i32
1996+
; CHECK-NEXT: ret i32 [[A_0_LOAD_EXT]]
1997+
;
1998+
%a = alloca i1, align 1
1999+
%v = load atomic i32, ptr %a seq_cst, align 4
2000+
ret i32 %v
2001+
}
2002+
19712003
!0 = !{!1, !1, i64 0, i64 200}
19722004
!1 = !{!2, i64 1, !"type_0"}
19732005
!2 = !{!"root"}

0 commit comments

Comments
 (0)