[OpaquePtr] Make atomicrmw work with opaque pointers

FullTy is only necessary when we need to figure out what type an
instruction works with given a pointer's pointee type. However, we just
end up using the value operand's type, so FullTy isn't necessary.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102788
This commit is contained in:
Arthur Eubanks 2021-05-19 10:37:17 -07:00
parent 1b25fce404
commit 0bebda17be
6 changed files with 27 additions and 10 deletions

View File

@ -7668,7 +7668,8 @@ int LLParser::parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS) {
return tokError("atomicrmw cannot be unordered");
if (!Ptr->getType()->isPointerTy())
return error(PtrLoc, "atomicrmw operand must be a pointer");
if (cast<PointerType>(Ptr->getType())->getElementType() != Val->getType())
if (!cast<PointerType>(Ptr->getType())
->isOpaqueOrPointeeTypeMatches(Val->getType()))
return error(ValLoc, "atomicrmw value and pointer type do not match");
if (Operation == AtomicRMWInst::Xchg) {

View File

@ -5231,15 +5231,18 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
unsigned OpNum = 0;
Value *Ptr = nullptr;
if (getValueTypePair(Record, OpNum, NextValueNo, Ptr, &FullTy))
if (getValueTypePair(Record, OpNum, NextValueNo, Ptr))
return error("Invalid record");
if (!isa<PointerType>(Ptr->getType()))
return error("Invalid record");
Value *Val = nullptr;
if (popValue(Record, OpNum, NextValueNo,
getPointerElementFlatType(FullTy), Val))
if (popValue(Record, OpNum, NextValueNo, nullptr, Val))
return error("Invalid record");
if (!cast<PointerType>(Ptr->getType())
->isOpaqueOrPointeeTypeMatches(Val->getType()))
return error("Invalid record");
if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
@ -5272,7 +5275,6 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
Align(TheModule->getDataLayout().getTypeStoreSize(Val->getType()));
I = new AtomicRMWInst(Operation, Ptr, Val, *Alignment, Ordering, SSID);
FullTy = getPointerElementFlatType(FullTy);
cast<AtomicRMWInst>(I)->setVolatile(IsVol);
InstructionList.push_back(I);

View File

@ -1609,9 +1609,9 @@ void AtomicRMWInst::Init(BinOp Operation, Value *Ptr, Value *Val,
"All operands must be non-null!");
assert(getOperand(0)->getType()->isPointerTy() &&
"Ptr must have pointer type!");
assert(getOperand(1)->getType() ==
cast<PointerType>(getOperand(0)->getType())->getElementType()
&& "Ptr must be a pointer to Val type!");
assert(cast<PointerType>(getOperand(0)->getType())
->isOpaqueOrPointeeTypeMatches(getOperand(1)->getType()) &&
"Ptr must be a pointer to Val type!");
assert(Ordering != AtomicOrdering::NotAtomic &&
"AtomicRMW instructions must be atomic!");
}

View File

@ -3868,7 +3868,7 @@ void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
auto Op = RMWI.getOperation();
PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType());
Assert(PTy, "First atomicrmw operand must be a pointer.", &RMWI);
Type *ElTy = PTy->getElementType();
Type *ElTy = RMWI.getOperand(1)->getType();
if (Op == AtomicRMWInst::Xchg) {
Assert(ElTy->isIntegerTy() || ElTy->isFloatingPointTy(), "atomicrmw " +
AtomicRMWInst::getOperationName(Op) +
@ -3886,7 +3886,7 @@ void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
&RMWI, ElTy);
}
checkAtomicMemAccessSize(ElTy, &RMWI);
Assert(ElTy == RMWI.getOperand(1)->getType(),
Assert(PTy->isOpaqueOrPointeeTypeMatches(ElTy),
"Argument value type does not match pointer operand type!", &RMWI,
ElTy);
Assert(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP,

View File

@ -56,3 +56,11 @@ define void @cmpxchg(ptr %p, i32 %a, i32 %b) {
%val_success = cmpxchg ptr %p, i32 %a, i32 %b acq_rel monotonic
ret void
}
; CHECK: define void @atomicrmw(ptr %a, i32 %i)
; CHECK: %b = atomicrmw add ptr %a, i32 %i acquire
; CHECK: ret void
define void @atomicrmw(ptr %a, i32 %i) {
%b = atomicrmw add ptr %a, i32 %i acquire
ret void
}

View File

@ -17,3 +17,9 @@ define void @cmpxchg(ptr %p, i32 %a, i32 %b) {
%val_success = cmpxchg ptr %p, i32 %a, i32 %b acq_rel monotonic
ret void
}
; CHECK: @atomicrmw
define void @atomicrmw(ptr %a, i32 %i) {
%b = atomicrmw add ptr %a, i32 %i acquire
ret void
}