Skip to content

[DirectX] Vector mad operations not being scalarized for integer types #152220

@kmpeng

Description

@kmpeng

Discovered while running the offload-test-suite.

https://godbolt.org/z/TMEKbMaYP

// RUN: %clang-dxc -T cs_6_5 -enable-16bit-types %s

StructuredBuffer<int16_t4> M0 : register(t0);
StructuredBuffer<int16_t4> A0 : register(t1);
StructuredBuffer<int16_t4> B0 : register(t2);

RWStructuredBuffer<int16_t4> Out0 : register(u3);

[numthreads(1,1,1)]
void main() {
    Out0[0] = mad(M0[0], A0[0], B0[0]);
}
# .---command stderr------------
# | error: Cannot create IMad operation: Invalid overload type
# | These should never be used!!!
# | UNREACHABLE executed at E:/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp:1025!

The llvm ir shows that the mad instruction %dx.imad.i = tail call <4 x i16> @llvm.dx.imad.v4i16(<4 x i16> %17, <4 x i16> %27, <4 x i16> %37) is not being scalarized when it should be. This is happening with all bit sizes of int and uint.

Fix is to add dx_imad and dx_umad here:

case Intrinsic::dx_wave_reduce_usum:
return true;

Metadata

Metadata

Assignees

Type

Projects

Status

Active

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions