Skip to content

Commit 67e0560

Browse files
committed
Add <2 x i32> test. Add DL as optional to isValidAtomicTy
1 parent 1c1aae7 commit 67e0560

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ class LoadInst : public UnaryInstruction {
252252

253253
/// Returns false if this type would be invalid in the
254254
/// creation of a load atomic instruction.
255-
static bool isValidAtomicTy(Type *Ty);
255+
static bool isValidAtomicTy(Type *Ty, const DataLayout *DL = nullptr,
256+
AtomicOrdering AO = AtomicOrdering::NotAtomic);
256257

257258
Value *getPointerOperand() { return getOperand(0); }
258259
const Value *getPointerOperand() const { return getOperand(0); }

llvm/lib/IR/Instructions.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,9 +1247,17 @@ void LoadInst::AssertOK() {
12471247
"Ptr must have pointer type.");
12481248
}
12491249

1250-
bool LoadInst::isValidAtomicTy(Type *Ty) {
1250+
bool LoadInst::isValidAtomicTy(Type *Ty, const DataLayout *DL,
1251+
AtomicOrdering AO) {
1252+
// TODO: Share methods with IR/Verifier.
12511253
if (!Ty->isIntOrPtrTy() && !Ty->isFloatingPointTy())
12521254
return false;
1255+
if (AO == AtomicOrdering::Release || AO == AtomicOrdering::AcquireRelease)
1256+
return false;
1257+
if (DL) {
1258+
unsigned Size = DL->getTypeSizeInBits(Ty);
1259+
return Size >= 8 && !(Size & (Size - 1));
1260+
}
12531261
return true;
12541262
}
12551263

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2854,7 +2854,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
28542854
bool visitLoadInst(LoadInst &LI) {
28552855
LLVM_DEBUG(dbgs() << " original: " << LI << "\n");
28562856

2857-
// load atomic vector would be generated, which is illegal
2857+
// Load atomic vector would be generated, which is illegal.
2858+
// TODO: Generate a generic bitcast in machine codegen instead.
28582859
if (LI.isAtomic() && !LoadInst::isValidAtomicTy(NewAI.getAllocatedType()))
28592860
return false;
28602861

llvm/test/Transforms/SROA/atomic-vector.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,20 @@ define ptr @atomic_vector_ptr() {
5151
%ret = load atomic volatile ptr, ptr %indirect acquire, align 4
5252
ret ptr %ret
5353
}
54+
55+
define i32 @atomic_2vector_int() {
56+
; CHECK-LABEL: define i32 @atomic_2vector_int() {
57+
; CHECK-NEXT: [[VAL_SROA_0:%.*]] = alloca i32, align 8
58+
; CHECK-NEXT: store i32 undef, ptr [[VAL_SROA_0]], align 8
59+
; CHECK-NEXT: [[VAL_SROA_0_0_VAL_SROA_0_0_RET:%.*]] = load atomic volatile i32, ptr [[VAL_SROA_0]] acquire, align 4
60+
; CHECK-NEXT: ret i32 [[VAL_SROA_0_0_VAL_SROA_0_0_RET]]
61+
;
62+
%src = alloca <2 x i32>
63+
%val = alloca <2 x i32>
64+
%direct = alloca ptr
65+
call void @llvm.memcpy.p0.p0.i64(ptr %val, ptr %src, i64 4, i1 false)
66+
store ptr %val, ptr %direct
67+
%indirect = load ptr, ptr %direct
68+
%ret = load atomic volatile i32, ptr %indirect acquire, align 4
69+
ret i32 %ret
70+
}

0 commit comments

Comments
 (0)