-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[SROA] Prevent load atomic vector from being generated #112432
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
cb05b56
0c61505
083346d
cf47505
ef4fe92
bdebaa8
d68d923
1c1aae7
67e0560
e2e58ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1247,6 +1247,20 @@ void LoadInst::AssertOK() { | |
"Ptr must have pointer type."); | ||
} | ||
|
||
bool LoadInst::isValidAtomicTy(Type *Ty, const DataLayout *DL, | ||
AtomicOrdering AO) { | ||
// TODO: Share methods with IR/Verifier. | ||
if (!Ty->isIntOrPtrTy() && !Ty->isFloatingPointTy()) | ||
return false; | ||
if (AO == AtomicOrdering::Release || AO == AtomicOrdering::AcquireRelease) | ||
return false; | ||
if (DL) { | ||
|
||
unsigned Size = DL->getTypeSizeInBits(Ty); | ||
return Size >= 8 && !(Size & (Size - 1)); | ||
} | ||
return true; | ||
} | ||
|
||
static Align computeLoadStoreDefaultAlign(Type *Ty, InsertPosition Pos) { | ||
assert(Pos.isValid() && | ||
"Insertion position cannot be null when alignment not provided!"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -passes='sroa' -S | FileCheck %s | ||
|
||
define float @atomic_vector() { | ||
; CHECK-LABEL: define float @atomic_vector() { | ||
; CHECK-NEXT: [[TMP1:%.*]] = alloca <1 x float>, align 4 | ||
; CHECK-NEXT: store <1 x float> undef, ptr [[TMP1]], align 4 | ||
; CHECK-NEXT: [[TMP2:%.*]] = load atomic volatile float, ptr [[TMP1]] acquire, align 4 | ||
; CHECK-NEXT: ret float [[TMP2]] | ||
; | ||
%src = alloca <1 x float> | ||
%val = alloca <1 x float> | ||
%direct = alloca ptr | ||
call void @llvm.memcpy.p0.p0.i64(ptr %val, ptr %src, i64 4, i1 false) | ||
store ptr %val, ptr %direct | ||
%indirect = load ptr, ptr %direct | ||
%ret = load atomic volatile float, ptr %indirect acquire, align 4 | ||
ret float %ret | ||
} | ||
|
||
define i32 @atomic_vector_int() { | ||
; CHECK-LABEL: define i32 @atomic_vector_int() { | ||
; CHECK-NEXT: [[VAL:%.*]] = alloca <1 x i32>, align 4 | ||
; CHECK-NEXT: store <1 x i32> undef, ptr [[VAL]], align 4 | ||
; CHECK-NEXT: [[RET:%.*]] = load atomic volatile i32, ptr [[VAL]] acquire, align 4 | ||
; CHECK-NEXT: ret i32 [[RET]] | ||
; | ||
%src = alloca <1 x i32> | ||
%val = alloca <1 x i32> | ||
%direct = alloca ptr | ||
call void @llvm.memcpy.p0.p0.i64(ptr %val, ptr %src, i64 4, i1 false) | ||
store ptr %val, ptr %direct | ||
%indirect = load ptr, ptr %direct | ||
%ret = load atomic volatile i32, ptr %indirect acquire, align 4 | ||
ret i32 %ret | ||
} | ||
|
||
define ptr @atomic_vector_ptr() { | ||
; CHECK-LABEL: define ptr @atomic_vector_ptr() { | ||
; CHECK-NEXT: [[VAL_SROA_0:%.*]] = alloca <1 x ptr>, align 8 | ||
; CHECK-NEXT: store <1 x ptr> undef, ptr [[VAL_SROA_0]], align 8 | ||
; CHECK-NEXT: [[VAL_SROA_0_0_VAL_SROA_0_0_RET:%.*]] = load atomic volatile ptr, ptr [[VAL_SROA_0]] acquire, align 4 | ||
; CHECK-NEXT: ret ptr [[VAL_SROA_0_0_VAL_SROA_0_0_RET]] | ||
; | ||
%src = alloca <1 x ptr> | ||
%val = alloca <1 x ptr> | ||
%direct = alloca ptr | ||
call void @llvm.memcpy.p0.p0.i64(ptr %val, ptr %src, i64 8, i1 false) | ||
store ptr %val, ptr %direct | ||
%indirect = load ptr, ptr %direct | ||
%ret = load atomic volatile ptr, ptr %indirect acquire, align 4 | ||
ret ptr %ret | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test a <2 x i16> or some other real vector. 1 x is a degenerate case |
||
|
||
define i32 @atomic_2vector_int() { | ||
; CHECK-LABEL: define i32 @atomic_2vector_int() { | ||
; CHECK-NEXT: [[VAL_SROA_0:%.*]] = alloca i32, align 8 | ||
; CHECK-NEXT: store i32 undef, ptr [[VAL_SROA_0]], align 8 | ||
; CHECK-NEXT: [[VAL_SROA_0_0_VAL_SROA_0_0_RET:%.*]] = load atomic volatile i32, ptr [[VAL_SROA_0]] acquire, align 4 | ||
; CHECK-NEXT: ret i32 [[VAL_SROA_0_0_VAL_SROA_0_0_RET]] | ||
; | ||
%src = alloca <2 x i32> | ||
%val = alloca <2 x i32> | ||
%direct = alloca ptr | ||
call void @llvm.memcpy.p0.p0.i64(ptr %val, ptr %src, i64 4, i1 false) | ||
store ptr %val, ptr %direct | ||
%indirect = load ptr, ptr %direct | ||
%ret = load atomic volatile i32, ptr %indirect acquire, align 4 | ||
ret i32 %ret | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add test for the non-byte illegal case? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DataLayout must be mandatory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we need to omit it entirely because otherwise we will be checking the type size of the alloca, which we want to avoid if to optimize
basictest.ll
.