[PATCH] D122376: [IR] Support named struct result in intrinsic remangling

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 03:06:33 PDT 2022


nikic created this revision.
nikic added a reviewer: opaque-pointers.
Herald added subscribers: dexonsmith, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When an intrinsic is remangled, we currently try to replace with the canonical declaration. Unfortunately there is a quirk that makes intrinsic declarations in LLVM non-unique: For intrinsics with struct return type, the canonical declaration returns an unnamed struct, but LLVM also accepts named structs of equivalent structure. This "feature" is in active use by some target intrinsics.

As such, when we remangle an intrinsic we should use the original function type and just assign the new remangled name. matchIntrinsicSignature() has already checked that the function signature is valid.

This is not directly related to opaque pointers, but opaque pointer autoupgrade needs to remangle all intrinsics involving pointers, which is why we're hitting this issue now.


https://reviews.llvm.org/D122376

Files:
  llvm/lib/IR/Function.cpp
  llvm/test/Assembler/opaque-ptr-intrinsic-remangling.ll


Index: llvm/test/Assembler/opaque-ptr-intrinsic-remangling.ll
===================================================================
--- llvm/test/Assembler/opaque-ptr-intrinsic-remangling.ll
+++ llvm/test/Assembler/opaque-ptr-intrinsic-remangling.ll
@@ -3,6 +3,8 @@
 
 ; Make sure that opaque pointer intrinsic remangling upgrade works.
 
+%struct.__neon_int8x8x2_t = type { <8 x i8>, <8 x i8> }
+
 declare i32* @fake_personality_function()
 declare void @func()
 
@@ -43,5 +45,15 @@
   ret i8* %p2
 }
 
+define %struct.__neon_int8x8x2_t @test_named_struct_return(i8* %A) {
+; CHECK-LABEL: @test_named_struct_return(
+; CHECK-NEXT:    [[VAL:%.*]] = call [[STRUCT___NEON_INT8X8X2_T:%.*]] @llvm.aarch64.neon.ld2.v8i8.p0(ptr [[A:%.*]])
+; CHECK-NEXT:    ret [[STRUCT___NEON_INT8X8X2_T]] [[VAL]]
+;
+  %val = call %struct.__neon_int8x8x2_t @llvm.aarch64.neon.ld2.v8i8.p0i8(i8* %A)
+  ret %struct.__neon_int8x8x2_t %val
+}
+
 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
 declare i8* @llvm.ptr.annotation.p0i8(i8*, i8*, i8*, i32, i8*)
+declare %struct.__neon_int8x8x2_t @llvm.aarch64.neon.ld2.v8i8.p0i8(i8*)
Index: llvm/lib/IR/Function.cpp
===================================================================
--- llvm/lib/IR/Function.cpp
+++ llvm/lib/IR/Function.cpp
@@ -1783,7 +1783,10 @@
       // invalid and we'll get an error.
       ExistingGV->setName(WantedName + ".renamed");
     }
-    return Intrinsic::getDeclaration(F->getParent(), ID, ArgTys);
+    return cast<Function>(
+        F->getParent()
+            ->getOrInsertFunction(WantedName, F->getFunctionType())
+            .getCallee());
   }();
 
   NewDecl->setCallingConv(F->getCallingConv());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122376.417860.patch
Type: text/x-patch
Size: 1708 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220324/93113151/attachment.bin>


More information about the llvm-commits mailing list