[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 7 08:58:00 PDT 2024


================
@@ -264,6 +265,31 @@ class OpLowerer {
     return lowerToBindAndAnnotateHandle(F);
   }
 
+  Error replaceSplitDoubleCallUsages(CallInst *Intrin, CallInst *Op) {
+    IRBuilder<> &IRB = OpBuilder.getIRB();
+
+    for (Use &U : make_early_inc_range(Intrin->uses())) {
+      if (auto *EVI = dyn_cast<ExtractValueInst>(U.getUser())) {
+
+        assert(EVI->getNumIndices() == 1 &&
+               "splitdouble result should be indexed individually.");
+        if (EVI->getNumIndices() != 1)
+          return make_error<StringError>(
+              "splitdouble result should be indexed individually.",
+              inconvertibleErrorCode());
+
+        unsigned int IndexVal = EVI->getIndices()[0];
+
+        auto *OpEVI = IRB.CreateExtractValue(Op, IndexVal);
----------------
joaosaffran wrote:

This code here is responsible to replace the return type of DXIL splitdouble OP, with the correct named type. So it replaces this:
```
  %hlsl.splitdouble = call { i32, i32 } @llvm.dx.splitdouble.i32(double %D)
  %0 = extractvalue { i32, i32 } %hlsl.splitdouble, 0
  %1 = extractvalue { i32, i32 } %hlsl.splitdouble, 1
```

With this:
```
  %hlsl.splitdouble = call %dx.types.splitdouble @dx.op.splitDouble.f64(i32 102, double %D)
  %0 = extractvalue %dx.types.splitdouble %hlsl.splitdouble, 0
  %1 = extractvalue %dx.types.splitdouble %hlsl.splitdouble, 1
```

This is required to keep the Op code call compatible with DXC. @farzonl not sure if this lowering should be done in `CGBuiltin`. Let me know if you have a better place to make this change @farzonl 

https://github.com/llvm/llvm-project/pull/109331


More information about the cfe-commits mailing list