Skip to content

[HLSL] implement sqrt intrinsic #86187

@farzonl

Description

@farzonl

The current sqrt intrinsic is incomplete in some cases and not correct in others.

For example there is no double support. Doubles need to cast down to floats:
https://godbolt.org/z/Pc73srEr7
Yet we added it here: https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/hlsl/hlsl_intrinsics.h#L1421

Second we should be using __builtin_elementwise_sqrt and not multiple different builtins especially since all sqrt builtins map to the same Intrinsic::sqrt
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGBuiltin.cpp#L2908

Using one builtin makes it easier to apply type check rules in sema.

Finally lowering support needs to be added. Sqrt lowering is very simple and has a one to one mapping between

Intrinsic::sqrt and dx.op.unary 24

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language Supportbackend:DirectXclang:headersHeaders provided by Clang, e.g. for intrinsics

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions