[Verifier] Relieve intrinsics parameter alignment size constrain
authorLuo, Yuanke <yuanke.luo@intel.com>
Thu, 20 Oct 2022 09:49:47 +0000 (17:49 +0800)
committerLuo, Yuanke <yuanke.luo@intel.com>
Fri, 21 Oct 2022 09:01:20 +0000 (17:01 +0800)
In D121898 we restrict parameter alignment size in IR since DAGISel
only have 4 bits to hold the alignment value. However intrinsics
won't be lowered to call instruction, so we can remove the constrain
for intrinsics.

Differential Revision: https://reviews.llvm.org/D136330

llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/param-align.ll
llvm/test/Verifier/param-ret-align.ll

index de04256..06f0316 100644 (file)
@@ -3222,6 +3222,13 @@ void Verifier::visitCallBase(CallBase &Call) {
   Check(verifyAttributeCount(Attrs, Call.arg_size()),
         "Attribute after last parameter!", Call);
 
+  Function *Callee =
+      dyn_cast<Function>(Call.getCalledOperand()->stripPointerCasts());
+  bool IsIntrinsic = Callee && Callee->isIntrinsic();
+  if (IsIntrinsic)
+    Check(Callee->getValueType() == FTy,
+          "Intrinsic called with incompatible signature", Call);
+
   auto VerifyTypeAlign = [&](Type *Ty, const Twine &Message) {
     if (!Ty->isSized())
       return;
@@ -3231,19 +3238,14 @@ void Verifier::visitCallBase(CallBase &Call) {
           "Incorrect alignment of " + Message + " to called function!", Call);
   };
 
-  VerifyTypeAlign(FTy->getReturnType(), "return type");
-  for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
-    Type *Ty = FTy->getParamType(i);
-    VerifyTypeAlign(Ty, "argument passed");
+  if (!IsIntrinsic) {
+    VerifyTypeAlign(FTy->getReturnType(), "return type");
+    for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
+      Type *Ty = FTy->getParamType(i);
+      VerifyTypeAlign(Ty, "argument passed");
+    }
   }
 
-  Function *Callee =
-      dyn_cast<Function>(Call.getCalledOperand()->stripPointerCasts());
-  bool IsIntrinsic = Callee && Callee->isIntrinsic();
-  if (IsIntrinsic)
-    Check(Callee->getValueType() == FTy,
-          "Intrinsic called with incompatible signature", Call);
-
   if (Attrs.hasFnAttr(Attribute::Speculatable)) {
     // Don't allow speculatable on call sites, unless the underlying function
     // declaration is also speculatable.
index 7217e47..bfd01cb 100644 (file)
@@ -1,6 +1,16 @@
 ; RUN: not llvm-as < %s 2>&1 | FileCheck %s
 
+; Large vector for intrinsics is valid
+; CHECK-NOT: llvm.fshr
+define dso_local <8192 x i32> @test_intrin(<8192 x i32> %l, <8192 x i32> %r, <8192 x i32> %amt) {
+entry:
+  %b = call <8192 x i32> @llvm.fshr.v8192i32(<8192 x i32> %l, <8192 x i32> %r, <8192 x i32> %amt)
+  ret <8192 x i32> %b
+}
+declare <8192 x i32> @llvm.fshr.v8192i32 (<8192 x i32> %l, <8192 x i32> %r, <8192 x i32> %amt)
+
 ; CHECK: Incorrect alignment of argument passed to called function!
+; CHECK: bar
 define dso_local void @foo(<8192 x float> noundef %vec) {
 entry:
   call void @bar(<8192 x float> %vec)
index d551656..dd302c3 100644 (file)
@@ -1,6 +1,16 @@
 ; RUN: not llvm-as < %s 2>&1 | FileCheck %s
 
+; Large vector for intrinsics is valid
+; CHECK-NOT: llvm.fshr
+define dso_local <8192 x i32> @test_intrin(<8192 x i32> %l, <8192 x i32> %r, <8192 x i32> %amt) {
+entry:
+  %b = call <8192 x i32> @llvm.fshr.v8192i32(<8192 x i32> %l, <8192 x i32> %r, <8192 x i32> %amt)
+  ret <8192 x i32> %b
+}
+declare <8192 x i32> @llvm.fshr.v8192i32 (<8192 x i32> %l, <8192 x i32> %r, <8192 x i32> %amt)
+
 ; CHECK: Incorrect alignment of return type to called function!
+; CHECK: bar
 define dso_local void @foo() {
 entry:
   call <8192 x float> @bar()