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

Damyan Pepper via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 9 11:51:49 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();
----------------
damyanp wrote:

`VecTy` and `N` don't seem to be used until after the line 298, IMO it'd be clearer to have these closer to where they're used.

(And while I'm trying to read this, I'd really like to know if these values are mutated at all by the subsequent code)

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


More information about the llvm-branch-commits mailing list