[llvm] [SPIR-V] Implement sample and sample_clamp intrinsics for HLSL resources (PR #177234)

Steven Perron via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 22 08:27:10 PST 2026


================
@@ -3019,6 +3023,45 @@ Register SPIRVInstructionSelector::buildZerosVal(const SPIRVType *ResType,
   return GR.getOrCreateConstInt(0, I, ResType, TII, ZeroAsNull);
 }
 
+bool SPIRVInstructionSelector::isConstantZero(Register Reg) const {
+  auto IsZero = [this](Register Reg) {
+    Register R = Reg;
+    MachineInstr *Def = getDefInstrMaybeConstant(R, MRI);
+    if (!Def)
+      return false;
+
+    if (Def->getOpcode() == SPIRV::OpConstantNull)
+      return true;
+
+    if (Def->getOpcode() == TargetOpcode::G_CONSTANT ||
+        Def->getOpcode() == SPIRV::OpConstantI)
+      return getIConstVal(R, MRI) == 0;
+
+    return false;
+  };
+
+  if (IsZero(Reg))
+    return true;
+
+  MachineInstr *Def = MRI->getVRegDef(Reg);
+  if (!Def)
+    return false;
+
+  if (Def->getOpcode() == TargetOpcode::G_BUILD_VECTOR ||
+      (Def->getOpcode() == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS &&
----------------
s-perron wrote:

I guess so. I want only thinking of vector and scalars. I can limit it to just those. I don't want to cover all possible structs and arrays.

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


More information about the llvm-commits mailing list