This is an archive of the discontinued LLVM Phabricator instance.

[SPIR-V] Fix translation of aggregate undef operands
AbandonedPublic

Authored by mpaszkowski on Jan 9 2023, 5:24 PM.

Details

Summary

This patch:

  • Extends the preprocessing of constant aggregates for undefs. Such operands are replaced with a call to llvm.spv.const.composite.
  • Adds a test undef-composite-store.ll demonstrating the issue.
  • Adjusts and fixes formatting of two other tests.

More about this patch can be found here.

Diff Detail

Event Timeline

mpaszkowski created this revision.Jan 9 2023, 5:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 5:24 PM
mpaszkowski requested review of this revision.Jan 9 2023, 5:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 5:24 PM
arsenm added inline comments.Jan 17 2023, 8:20 AM
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
179–180

this dyn_cast to constant doesn't make much sense to me, either you don't need this second cast or you should dyn_cast to UndefValue?

185

I'm guessing this doesn't handle nested structs properly

llvm/test/CodeGen/SPIRV/instructions/undef-composite-store.ll
16

Needs some tests with arrays, nested struct / array / vector combinations

Checking (by spirv-val) the backend's binary output for undef-composite-store.ll test shows this issue:

error: line 25: OpStore Pointer <id> '2[%ptr]'s type does not match Object <id> '13[%13]'s type.
  OpStore %ptr %13 Aligned 4

I would also suggest not changing the current Undef output format (implied in the two changed tests), but generating the output closer to the translator's one (despite the fact that the implemented solution looks standard-compliant). I suppose this may be implemented by introducing a new spv_undef intrinsic (similar to spv_alloca).

mpaszkowski abandoned this revision.Feb 1 2023, 1:13 PM

Thanks @arsenm and @iliya-diyachkov for your comments! I have created a new revision https://reviews.llvm.org/D143107 which provides a solution that is compatible with the Khronos SPIR-V Translator and should support nested aggregates. I will close this one.