Issue 134575
Summary [DirectX] Strip loop metadata that will trip up the validator when generating DXIL
Labels backend:DirectX
Assignees
Reporter bogner
    Compiling [particle_life](https://github.com/damyanp/dplife/blob/main/src/particle_life/particle_life.hlsl) with clang fails the validator with an error about `llvm.loop.mustprogress` being invalid. This particular metadata node is newer than the version of LLVM that DXIL is based off of, so it makes sense that it's a problem.

We need to strip metadata that the DXIL validator (and thus, potentially, DXIL drivers) isn't aware of. This may be as simple as the following:

```diff
--- a/llvm/lib/Target/DirectX/DXILPrepare.cpp
+++ b/llvm/lib/Target/DirectX/DXILPrepare.cpp
@@ -189,6 +189,26 @@ public:
 for (auto &BB : F) {
         IRBuilder<> Builder(&BB);
         for (auto &I : make_early_inc_range(BB)) {
+
+          // TODO: Audit this list - is it enough? Too much?
+          static unsigned DXILCompatibleMDs[] = {
+              LLVMContext::MD_dbg,
+ LLVMContext::MD_tbaa,
+              LLVMContext::MD_prof,
+ LLVMContext::MD_fpmath,
+              LLVMContext::MD_range,
+ LLVMContext::MD_tbaa_struct,
+ LLVMContext::MD_invariant_load,
+ LLVMContext::MD_alias_scope,
+              LLVMContext::MD_noalias,
+ LLVMContext::MD_nontemporal,
+ LLVMContext::MD_mem_parallel_loop_access,
+ LLVMContext::MD_nonnull,
+              LLVMContext::MD_dereferenceable,
+ LLVMContext::MD_dereferenceable_or_null,
+          };
+ I.dropUnknownNonDebugMetadata(DXILCompatibleMDs);
+
           if (I.getOpcode() == Instruction::FNeg) {
 Builder.SetInsertPoint(&I);
             Value *In = I.getOperand(0);
```

Here, we strip anything that isn't listed in DXC's set of pinned metadata names in `LLVMContext.h`. We need to determine if this is the right granularity.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to