aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/VerifierTest.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2024-04-06 15:27:45 -0400
committerGitHub <noreply@github.com>2024-04-06 15:27:45 -0400
commit4cb110a84f587d3c65b85d79ab6fc8aa5489fb86 (patch)
treedf02e1df31b98f5b2a241401d465c5ecae304a73 /llvm/unittests/IR/VerifierTest.cpp
parentbd589f5c7a079d8829fcf994b746634eaaea24ff (diff)
downloadllvm-4cb110a84f587d3c65b85d79ab6fc8aa5489fb86.zip
llvm-4cb110a84f587d3c65b85d79ab6fc8aa5489fb86.tar.gz
llvm-4cb110a84f587d3c65b85d79ab6fc8aa5489fb86.tar.bz2
[RFC] IR: Support atomicrmw FP ops with vector types (#86796)
Allow using atomicrmw fadd, fsub, fmin, and fmax with vectors of floating-point type. AMDGPU supports atomic fadd for <2 x half> and <2 x bfloat> on some targets and address spaces. Note this only supports the proper floating-point operations; float vector typed xchg is still not supported. cmpxchg still only supports integers, so this inserts bitcasts for the loop expansion. I have support for fp vector typed xchg, and vector of int/ptr separately implemented but I don't have an immediate need for those beyond feature consistency.
Diffstat (limited to 'llvm/unittests/IR/VerifierTest.cpp')
-rw-r--r--llvm/unittests/IR/VerifierTest.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/unittests/IR/VerifierTest.cpp b/llvm/unittests/IR/VerifierTest.cpp
index b2cd71e..c8db7fb 100644
--- a/llvm/unittests/IR/VerifierTest.cpp
+++ b/llvm/unittests/IR/VerifierTest.cpp
@@ -367,5 +367,33 @@ TEST(VerifierTest, CrossFunctionRef) {
Store->eraseFromParent();
}
+TEST(VerifierTest, AtomicRMW) {
+ LLVMContext C;
+ Module M("M", C);
+ FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
+ Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", M);
+ BasicBlock *Entry = BasicBlock::Create(C, "entry", F);
+ Value *Ptr = PoisonValue::get(PointerType::get(C, 0));
+
+ Type *FPTy = Type::getFloatTy(C);
+ Constant *CF = ConstantFP::getZero(FPTy);
+
+ // Invalid scalable type : atomicrmw (<vscale x 2 x float>)
+ Constant *CV = ConstantVector::getSplat(ElementCount::getScalable(2), CF);
+ new AtomicRMWInst(AtomicRMWInst::FAdd, Ptr, CV, Align(8),
+ AtomicOrdering::SequentiallyConsistent, SyncScope::System,
+ Entry);
+ ReturnInst::Create(C, Entry);
+
+ std::string Error;
+ raw_string_ostream ErrorOS(Error);
+ EXPECT_TRUE(verifyFunction(*F, &ErrorOS));
+ EXPECT_TRUE(
+ StringRef(ErrorOS.str())
+ .starts_with("atomicrmw fadd operand must have floating-point or "
+ "fixed vector of floating-point type!"))
+ << ErrorOS.str();
+}
+
} // end anonymous namespace
} // end namespace llvm