================
@@ -20440,6 +20442,26 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   }
 }
 
+Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned BuiltinID,
+                                             const CallExpr *E) {
+  switch (BuiltinID) {
+  case SPIRV::BI__builtin_spirv_distance: {
+    Value *X = EmitScalarExpr(E->getArg(0));
+    Value *Y = EmitScalarExpr(E->getArg(1));
+    assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+           E->getArg(1)->getType()->hasFloatingRepresentation() &&
+           "Distance operands must have a float representation");
+    assert(E->getArg(0)->getType()->isVectorType() &&
+           E->getArg(1)->getType()->isVectorType() &&
+           "Distance operands must be a vector");
+    return Builder.CreateIntrinsic(
+        /*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_distance,
+        ArrayRef<Value *>{X, Y}, nullptr, "spv.distance");
+  }
+  }
+  return nullptr;
----------------
farzonl wrote:

No see `EmitAMDGPUBuiltinExpr` and `EmitTargetArchBuiltinExpr` if a target 
builtin is not found the expected behavior is to return nullptr. All we know is 
that the builtin is not a targetArch builtin. Then when `EmitTargetBuiltinExpr` 
is used in `if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E, ReturnValue))` 
we can safely avoid a null deref. We need this to be a nullptr  and not 
`llvm_unreachable()` at this point so that their is a fall through to 
eventually check for lang builtins like `if (Value *V = 
EmitHLSLBuiltinExpr(BuiltinID, E, ReturnValue))`

https://github.com/llvm/llvm-project/pull/121598
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to