[clang] [HLSL] Implement support for HLSL intrinsic - select (PR #107129)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 11:06:19 PDT 2024


================
@@ -18695,6 +18695,48 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
         CGM.getHLSLRuntime().getSaturateIntrinsic(), ArrayRef<Value *>{Op0},
         nullptr, "hlsl.saturate");
   }
+  case Builtin::BI__builtin_hlsl_select: {
+    Value *OpCond = EmitScalarExpr(E->getArg(0));
+    Value *OpTrue = EmitScalarExpr(E->getArg(1));
+    Value *OpFalse = EmitScalarExpr(E->getArg(2));
+    llvm::Type *TCond = OpCond->getType();
+
+    // if cond is a bool emit a select instruction
+    if (TCond->isIntegerTy(1))
----------------
farzonl wrote:

NIT: Stylistically in `EmitHLSLBuiltinExpr`  we have been checking error cases upfront and ending the case statements with a return.  If it isn't a ton of trouble change this to
```cpp
 if (!TCond->isIntegerTy(1))
   llvm_unreachable("Select requires a bool or vector of bools as its first operand.");
...
return Result;
```

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


More information about the cfe-commits mailing list