================
@@ -18584,6 +18584,29 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned
BuiltinID,
CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef<Value *>{X},
nullptr, "hlsl.length");
}
+ case Builtin::BI__builtin_hlsl_normalize: {
+ Value *X = EmitScalarExpr(E->getArg(0));
+
+ assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+ "normalize operand must have a float representation");
+
+ // scalar inputs should expect a scalar return type
+ if (!E->getArg(0)->getType()->isVectorType())
+ return Builder.CreateIntrinsic(
+ /*ReturnType=*/X->getType()->getScalarType(),
+ CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef<Value *>{X},
+ nullptr, "hlsl.normalize");
+
+ // construct a vector return type for vector inputs
+ auto *XVecTy = E->getArg(0)->getType()->getAs<VectorType>();
+ llvm::Type *retType = X->getType()->getScalarType();
+ retType = llvm::VectorType::get(
+ retType, ElementCount::getFixed(XVecTy->getNumElements()));
+
+ return Builder.CreateIntrinsic(
----------------
farzonl wrote:
I don't understand why we are checking for scalars\not scalars and then
emiting the same intrinsic. seems like afree all the asserts\validity checks we
should simplify this whole case statement to one `Builder.CreateIntrinsic`
https://github.com/llvm/llvm-project/pull/102683
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits