Skip to content

Commit

Permalink
[OMPIRBuilder] Remove the support for floating point values for atomi…
Browse files Browse the repository at this point in the history
…c compare operation

This patch removes the type punning in atomic compare operation for
floating point values because the direct comparison doesn't make too much sense
for floating point values.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D119378
  • Loading branch information
shiltian committed Feb 10, 2022
1 parent 8c930ce commit 0148b58
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Expand Up @@ -3481,26 +3481,16 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createAtomicCompare(

assert(X.Var->getType()->isPointerTy() &&
"OMP atomic expects a pointer to target memory");
assert((X.ElemTy->isFloatingPointTy() || X.ElemTy->isIntegerTy() ||
X.ElemTy->isPointerTy()) &&
"OMP atomic compare expected a scalar type");
assert((X.ElemTy->isIntegerTy() || X.ElemTy->isPointerTy()) &&
"OMP atomic compare expected a integer scalar type");

if (Op == OMPAtomicCompareOp::EQ) {
unsigned Addrspace = cast<PointerType>(X.Var->getType())->getAddressSpace();
IntegerType *IntCastTy =
IntegerType::get(M.getContext(), X.ElemTy->getScalarSizeInBits());
Value *XAddr =
X.ElemTy->isIntegerTy()
? X.Var
: Builder.CreateBitCast(X.Var, IntCastTy->getPointerTo(Addrspace));
AtomicOrdering Failure = AtomicCmpXchgInst::getStrongestFailureOrdering(AO);
// We don't need the result for now.
(void)Builder.CreateAtomicCmpXchg(XAddr, E, D, MaybeAlign(), AO, Failure);
(void)Builder.CreateAtomicCmpXchg(X.Var, E, D, MaybeAlign(), AO, Failure);
} else {
assert((Op == OMPAtomicCompareOp::MAX || Op == OMPAtomicCompareOp::MIN) &&
"Op should be either max or min at this point");
assert(X.ElemTy->isIntegerTy() &&
"max and min operators only support integer type");

// Reverse the ordop as the OpenMP forms are different from LLVM forms.
// Let's take max as example.
Expand Down

0 comments on commit 0148b58

Please sign in to comment.