DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

HLSL 2021 abandoned SELECT

Open SevenIsSeven opened this issue 2 years ago • 2 comments

Description HLSL2021 added short circuit feature but it accidently(or on purpose?) abandoned SELECT. Instead it will use BR to simulate which dropped the performance a lot if there're multiple this kind of call. see DirectXShaderCompiler\tools\clang\lib\CodeGen\CGExprScalar.cpp, function VisitAbstractConditionalOperator() image

Steps to Reproduce HLSL like: result = inputW > 0 ? data_ptr[inputIdx - 1] * kernel_ptr[kernelIdx] : 0;

Actual Behavior we should still have chance to use SELECT.

Environment

SevenIsSeven avatar May 30 '24 08:05 SevenIsSeven

Can you generate a repro on godbolt please? This trivial case generates select: https://godbolt.org/z/EMvqxaWeh

damyanp avatar May 30 '24 16:05 damyanp

You can generate select by using the select intrinsic. See https://devblogs.microsoft.com/directx/hlsl-2021-migration-guide/ for more details.

damyanp avatar May 30 '24 17:05 damyanp