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

Cooper Partin via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 14:09:14 PDT 2024


================
@@ -18695,6 +18695,50 @@ 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))
+      return Builder.CreateSelect(OpCond, OpTrue, OpFalse, "hlsl.select");
+
+    // if cond is a vector of bools lower to a shufflevector
+    // todo check if that true and false are vectors
----------------
coopp wrote:

There are some 'todo' comments here.  Are these just for your own bookkeeping while working on this?  Or are they stil something you need to do?  The code below looks like you addressed them.  I could be missing something.

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


More information about the cfe-commits mailing list