[llvm] [SPIRV] Implement lowering for HLSL Texture2D sampling intrinsics (PR #179312)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 5 02:33:32 PST 2026


================
@@ -3122,6 +3148,47 @@ bool SPIRVInstructionSelector::isScalarOrVectorIntConstantZero(
   return false;
 }
 
+bool SPIRVInstructionSelector::isScalarOrVectorConstant(Register Reg) const {
+  auto IsConstant = [this](Register Reg) {
+    MachineInstr *Def = getDefInstrMaybeConstant(Reg, MRI);
+    if (!Def)
+      return false;
+
+    if (TII.isConstantInstr(*Def))
+      return true;
+
+    if (Def->getOpcode() == TargetOpcode::G_CONSTANT ||
+        Def->getOpcode() == TargetOpcode::G_FCONSTANT)
+      return true;
+
+    if (Def->getOpcode() == SPIRV::OpConstantNull)
+      return true;
+
+    return false;
+  };
----------------
Keenuts wrote:

If you can fold `G_CONSTANT` into the `isConstantInstr`, then this becomes:
```cpp
auto IsConstant = [this](Register Reg) {
    MachineInstr *Def = getDefInstrMaybeConstant(Reg, MRI);
    return Def && TII.isConstantInstr(*Def);
}
```

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


More information about the llvm-commits mailing list