This is an archive of the discontinued LLVM Phabricator instance.

[SPIRV] Implement support for SPV_KHR_expect_assume
AbandonedPublic

Authored by pmatos on Aug 11 2023, 3:02 AM.

Details

Summary

Adds new extension SPV_KHR_expect_assume, new capability
ExpectAssumeKHR as well as the new instructions:

  • OpExpectKHR
  • OpAssumeTrueKHR

These are lowered from respectively llvm.expect.<ty> and llvm.assume
intrinsics.

Diff Detail

Event Timeline

pmatos created this revision.Aug 11 2023, 3:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2023, 3:02 AM
pmatos requested review of this revision.Aug 11 2023, 3:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2023, 3:02 AM
pmatos added inline comments.Aug 11 2023, 3:08 AM
llvm/include/llvm/IR/IntrinsicsSPIRV.td
40

I will make sure to add a new line in the next revision of the patch.

llvm/lib/Target/SPIRV/SPIRVBuiltins.td
57

I have a question here... We have these instruction groups. I added these to builtins but I feel it's not the right thing to do. I get a warning during compilation because I didn't handle these instructions:

/home/pmatos/dev/llvm-project/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp:1933:11: warning: enumeration value 'ExpectAssume' not handled in switch [-Wswitch]
  switch (Call->Builtin->Group) {
          ^~~~~~~~~~~~~~~~~~~~
1 warning generated.

Should I create a group just for these instructions instead?

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
860

Other cases don't addExtensions here, just capabilities but if I don't then there's really no good place to add extensions. Would it make sense to have a loop to add extensions based on capabilities required? Or is it possible that two different extensions provide the same capability?

llvm/test/CodeGen/SPIRV/assume.ll
2

I added testing on spirv64, I assume this makes sense.

16

I will make sure to add a new line in the next revision of the patch.

llvm/lib/Target/SPIRV/SPIRVBuiltins.td
57

I'm not sure where this new ExpectAssume is actually used. If you are going to use ExpectAssume builtin in later version of the patch (or in the next patch), please add it later.

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
860

The place looks good but we need to check ST.canUseExtension().

Or is it possible that two different extensions provide the same capability?

I'm not sure but Reqs should work as a set and do not duplicate items.