[llvm-branch-commits] [llvm] [DirectX] Lower `@llvm.dx.typedBufferLoad` to DXIL ops (PR #104252)

Justin Bogner via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 9 12:21:26 PDT 2024


================
@@ -259,6 +259,114 @@ class OpLowerer {
       lowerToBindAndAnnotateHandle(F);
   }
 
+  /// Replace uses of \c V with the values in the `dx.ResRet` of \c Op. Since we
+  /// expect to be post-scalarization, make an effort to avoid vectors.
+  Error replaceResRetUses(CallInst *Intrin, CallInst *Op) {
+    IRBuilder<> &IRB = OpBuilder.getIRB();
+
+    Type *OldRetTy = Intrin->getType();
+
+    // For scalars, we just extract the first element.
+    if (!isa<FixedVectorType>(OldRetTy)) {
+      Value *EVI = IRB.CreateExtractValue(Op, 0);
+      Intrin->replaceAllUsesWith(EVI);
+      Intrin->eraseFromParent();
+      return Error::success();
+    }
+
+    auto *VecTy = cast<FixedVectorType>(OldRetTy);
+    unsigned N = VecTy->getNumElements();
----------------
bogner wrote:

I moved them closer to the use and made them const to try to make this a bit clearer.

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


More information about the llvm-branch-commits mailing list