This is an archive of the discontinued LLVM Phabricator instance.

Assert on polymorphic pointer intrinsic param
ClosedPublic

Authored by thopre on May 17 2022, 4:03 AM.

Details

Summary

Opaque pointers cannot be polymorphic on the pointed type given their
lack thereof. However they are currently accepted by tablegen but the
intrinsic signature verifier trips when verifying any further
polymorphic type because the opaque pointer codepath for pointers will
not push the pointed type in ArgTys.

This commit adds an assert to easily catch such cases instead of having
the generic signature match failure.

Diff Detail

Event Timeline

thopre created this revision.May 17 2022, 4:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 4:03 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
thopre requested review of this revision.May 17 2022, 4:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 4:03 AM
thopre planned changes to this revision.May 17 2022, 5:21 AM

Genuine test failure on CodeGenOpenCL/builtins-fp-atomics-gfx1030.cl

thopre updated this revision to Diff 430026.May 17 2022, 6:36 AM

Exclude match arguments

nikic added a comment.May 17 2022, 7:58 AM

Could you please share an example of a problematic intrinsic signature?

Could you please share an example of a problematic intrinsic signature?

def int_colossus_ststep :
  Intrinsic<
    [LLVMPointerType<llvm_any_ty>],
    [llvm_any_ty,
     LLVMPointerType<LLVMMatchType<0>>,
     llvm_i32_ty],
    [IntrWriteMem, IntrArgMemOnly]>;
nikic added a comment.May 18 2022, 2:45 AM

Could you please share an example of a problematic intrinsic signature?

def int_colossus_ststep :
  Intrinsic<
    [LLVMPointerType<llvm_any_ty>],
    [llvm_any_ty,
     LLVMPointerType<LLVMMatchType<0>>,
     llvm_i32_ty],
    [IntrWriteMem, IntrArgMemOnly]>;

Okay, I don't think I really understand the issue you're fixing then. This kind of intrinsic declaration should work with opaque pointers. The LLVMMatchType<0> predicate inside LLVMPointerType<> should just be ignored, which is what the current code is doing (right?)

It looks like we also have some in-tree intrinsics that are using this pattern, such as int_riscv_vlm.

Could you please share an example of a problematic intrinsic signature?

def int_colossus_ststep :
  Intrinsic<
    [LLVMPointerType<llvm_any_ty>],
    [llvm_any_ty,
     LLVMPointerType<LLVMMatchType<0>>,
     llvm_i32_ty],
    [IntrWriteMem, IntrArgMemOnly]>;

Okay, I don't think I really understand the issue you're fixing then. This kind of intrinsic declaration should work with opaque pointers. The LLVMMatchType<0> predicate inside LLVMPointerType<> should just be ignored, which is what the current code is doing (right?)

It looks like we also have some in-tree intrinsics that are using this pattern, such as int_riscv_vlm.

int_riscv_vlm is different because it matches a non-pointer polymorphic type. (the return value). In our case, the polymorphic type is on the pointed type. When that happens, matchIntrinsicType will *not* recurse for the pointed type since there is no pointed type for opaque pointers and thus will *not* push the pointed type into ArgTys. When processing the first parameter (the llvm_any_ty), the function exits with a match failure during deferred checks because of:

      if (D.getArgumentNumber() > ArgTys.size() ||
          D.getArgumentKind() == IITDescriptor::AK_MatchType)
        return IsDeferredCheck || DeferCheck(Ty);

This is because the argument number is 1 but argTys.size() is 0 since the pointed to type was not pushed. Any polymorphic type after a polymorphic pointer type will fail because of that problem.
nikic accepted this revision.May 18 2022, 4:22 AM

Thanks for the explanation, I get it now. It would probably be better to enforce this directly in tablegen, but this seems like a reasonable starting point.

This revision is now accepted and ready to land.May 18 2022, 4:22 AM

Thanks for the explanation, I get it now. It would probably be better to enforce this directly in tablegen, but this seems like a reasonable starting point.

Agreed, I'll try to do a patch for that too.

This revision was landed with ongoing or failed builds.May 18 2022, 6:35 AM
This revision was automatically updated to reflect the committed changes.