[llvm] 26f3693 - [IR][OpaquePointers] Properly print cmpxchg with pointer operands.
Denis Antrushin via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 7 07:18:55 PDT 2022
Author: Denis Antrushin
Date: 2022-07-07T17:18:31+03:00
New Revision: 26f369393d4e60c78d872c4cafcbf3fd929b9004
URL: https://github.com/llvm/llvm-project/commit/26f369393d4e60c78d872c4cafcbf3fd929b9004
DIFF: https://github.com/llvm/llvm-project/commit/26f369393d4e60c78d872c4cafcbf3fd929b9004.diff
LOG: [IR][OpaquePointers] Properly print cmpxchg with pointer operands.
With opaque pointers address of pointer variable and its value have
same type (`ptr`). As a result, cmpxchg is printed without values
types in LLVM assembly and cannot be read back. Add AtomicCmpXchg
to the list of instructions which always have operand types printed.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D129276
Added:
Modified:
llvm/lib/IR/AsmWriter.cpp
llvm/test/Assembler/opaque-ptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index b558a5b9fa295..afcdef028c278 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -4295,9 +4295,9 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
bool PrintAllTypes = false;
Type *TheType = Operand->getType();
- // Select, Store and ShuffleVector always print all types.
- if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
- || isa<ReturnInst>(I)) {
+ // Select, Store, ShuffleVector and CmpXchg always print all types.
+ if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I) ||
+ isa<ReturnInst>(I) || isa<AtomicCmpXchgInst>(I)) {
PrintAllTypes = true;
} else {
for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) {
diff --git a/llvm/test/Assembler/opaque-ptr.ll b/llvm/test/Assembler/opaque-ptr.ll
index 9c4c738703715..7b0273380720d 100644
--- a/llvm/test/Assembler/opaque-ptr.ll
+++ b/llvm/test/Assembler/opaque-ptr.ll
@@ -107,6 +107,14 @@ define void @cmpxchg(ptr %p, i32 %a, i32 %b) {
ret void
}
+; CHECK: define void @cmpxchg_ptr(ptr %p, ptr %a, ptr %b)
+; CHECK: %val_success = cmpxchg ptr %p, ptr %a, ptr %b acq_rel monotonic
+; CHECK: ret void
+define void @cmpxchg_ptr(ptr %p, ptr %a, ptr %b) {
+ %val_success = cmpxchg ptr %p, ptr %a, ptr %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
More information about the llvm-commits
mailing list