[AsmWriter] Fix printing of atomicrmw xchg with pointer op
authorNikita Popov <npopov@redhat.com>
Tue, 13 Dec 2022 11:46:09 +0000 (12:46 +0100)
committerNikita Popov <npopov@redhat.com>
Tue, 13 Dec 2022 11:49:36 +0000 (12:49 +0100)
atomicrmw always needs to print all types, even if the xchg value
type happens to be the same as the pointer operand type. This
couldn't occur prior to opaque pointers.

llvm/lib/IR/AsmWriter.cpp
llvm/test/Assembler/opaque-ptr.ll

index c2ad095..1b555f0 100644 (file)
@@ -4383,9 +4383,11 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
     bool PrintAllTypes = false;
     Type *TheType = Operand->getType();
 
-    // Select, Store, ShuffleVector and CmpXchg always print all types.
+    // Select, Store, ShuffleVector, CmpXchg and AtomicRMW always print all
+    // types.
     if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I) ||
-        isa<ReturnInst>(I) || isa<AtomicCmpXchgInst>(I)) {
+        isa<ReturnInst>(I) || isa<AtomicCmpXchgInst>(I) ||
+        isa<AtomicRMWInst>(I)) {
       PrintAllTypes = true;
     } else {
       for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) {
index 7b02733..dd22d54 100644 (file)
@@ -123,6 +123,14 @@ define void @atomicrmw(ptr %a, i32 %i) {
     ret void
 }
 
+; CHECK: define void @atomicrmw_ptr(ptr %a, ptr %b)
+; CHECK:     %c = atomicrmw xchg ptr %a, ptr %b acquire
+; CHECK:     ret void
+define void @atomicrmw_ptr(ptr %a, ptr %b) {
+    %c = atomicrmw xchg ptr %a, ptr %b acquire
+    ret void
+}
+
 ; CHECK: define void @call(ptr %p)
 ; CHECK:     call void %p()
 ; CHECK:     ret void