-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[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 2 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 |
---|---|---|
|
@@ -2853,6 +2853,11 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> { | |
|
||
bool visitLoadInst(LoadInst &LI) { | ||
LLVM_DEBUG(dbgs() << " original: " << LI << "\n"); | ||
|
||
// load atomic vector would be generated, which is illegal | ||
if (LI.isAtomic() && NewAI.getAllocatedType()->isVectorTy()) | ||
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. Is it illegal from LangRef's perspective? 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. It is at least illegal from the perspective of IR/Verifier. 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. It looks like this is written here. 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. The restriction is dumb and we should relax it. Instead of just hardcoding isVectorTy here, should have some kind of LoadInst::isValidAtomicType or something 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. The verifier check should be moved into a LoadInst helper 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. No alloca reference, just the type. The implementation should match Verifier::visitLoadInst, the isIntOrIntPtrTy || isFloatingPointTy and checkAtomicMemAccessSize (also add some non-atomic size tests?) 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. We need to ensure an atomic does not have a vector type. If the load is atomic and the alloca that will lend its type over has a vector type, then we will generate an atomic vector, which are illegal. We need to ensure that this doesn't occur. 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. No, you need to ensure the atomic is a valid type for an atomic load. Alternatively you can do the load with the equivalent sized type and then bitcast (which is why this restriction is dumb in the first place, the lowering can always do the same) 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. We are ensuring it is a valid type in the case under question, by checking the alloca's type. The invalid load will not be generated if the alloca has a vector type as that type will overwrite the load's type. 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. We don't want any loads that are atomic to have a vector type, regardless of whether the atomic itself is already valid; so checking if the atomic is more valid before translating it in AllocaSliceRewriter will miss cases where we form an invalid atomic during SROA (and then later form a vector type with it in visitLoadInst). Even though it is not likely as SROA probably won't form these, it illustrates why we don't need the extra checks here. |
||
return false; | ||
|
||
Value *OldOp = LI.getOperand(0); | ||
assert(OldOp == OldPtr); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
; 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]] | ||
; | ||
%1 = alloca <1 x float> | ||
|
||
%2 = alloca <1 x float> | ||
|
||
%3 = alloca ptr | ||
call void @llvm.memcpy.p0.p0.i64(ptr %2, ptr %1, i64 4, i1 false) | ||
store ptr %2, ptr %3 | ||
%4 = load ptr, ptr %3 | ||
%5 = load atomic volatile float, ptr %4 acquire, align 4 | ||
ret float %5 | ||
} | ||
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 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.