Skip to content

Commit cb05b56

Browse files
committed
[SROA] Prevent load atomic vector from being generated
These are illegal, and they can be formed from SROA via indirect volatile loads in the AllocaSliceRewriter.
1 parent 6e86496 commit cb05b56

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,11 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
28532853

28542854
bool visitLoadInst(LoadInst &LI) {
28552855
LLVM_DEBUG(dbgs() << " original: " << LI << "\n");
2856+
2857+
// load atomic vector would be generated, which is illegal
2858+
if (LI.isAtomic() && NewAI.getAllocatedType()->isVectorTy())
2859+
return false;
2860+
28562861
Value *OldOp = LI.getOperand(0);
28572862
assert(OldOp == OldPtr);
28582863

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: opt < %s -passes='sroa' -S 2>&1 | FileCheck %s --check-prefix=ERR
2+
; RUN: opt < %s -passes='sroa' -S | FileCheck %s
3+
4+
define float @atomic_vector() {
5+
; ERR-NOT: atomic load operand must have integer, pointer, or floating point type!
6+
; ERR-NOT: <1 x float> {{%.*}} = load atomic volatile <1 x float>, ptr {{%.*}} acquire, align 4
7+
; CHECK: %1 = alloca <1 x float>, align 4
8+
; CHECK-NEXT: store <1 x float> undef, ptr %1, align 4
9+
; CHECK-NEXT: %2 = load atomic volatile float, ptr %1 acquire, align 4
10+
; CHECK-NEXT: ret float %2
11+
%1 = alloca <1 x float>
12+
%2 = alloca <1 x float>
13+
%3 = alloca ptr
14+
call void @llvm.memcpy.p0.p0.i64(ptr %2, ptr %1, i64 4, i1 false)
15+
store ptr %2, ptr %3
16+
%4 = load ptr, ptr %3
17+
%5 = load atomic volatile float, ptr %4 acquire, align 4
18+
ret float %5
19+
}

0 commit comments

Comments
 (0)