Skip to content

[SPIR-V] -Gis flag causing invalid SPIR-V to be generated for mad for 32 bit integers #7706

Closed

Description

@kmpeng

https://godbolt.org/z/1q18evbx7

Compiling this code with the -Gis flag enabled

// RUN: %dxc -spirv -fspv-target-env=vulkan1.3 -Gis -HV 202x -T cs_6_5 %s

StructuredBuffer<int4> M1 : register(t3);
StructuredBuffer<int4> A1 : register(t4);
StructuredBuffer<int4> B1 : register(t5);
RWStructuredBuffer<int4> Out1 : register(u10);

[numthreads(1,1,1)]
void main() {
  Out1[0] = mad(M1[0], A1[0], B1[0]);
}

is producing this error:

# .---command stderr------------
# | fatal error: generated SPIR-V is invalid: ID '30' decorated with NoContraction multiple times is not allowed.
# |   %30 = OpIMul %v4int %152 %154
# | 
# `-----------------------------
# error: command failed with exit status: 0x80004005

The same error occurs when using uint as well.

-Gis should only impact floating point operations, so there's likely a bug in DXC causing it to add floating point flags to an integer operation.

Activity

  1. added
    bug
    needs-triage
    on Aug 18, 2025
  2. llvm-beanz commented on Aug 19, 2025

    @llvm-beanz
    Collaborator

    I looked briefly into this hoping it would be easy. I think the problem is a design flaw in the EmitVisitor which you can see here:
    https://github.com/microsoft/DirectXShaderCompiler/blob/main/tools/clang/lib/SPIRV/EmitVisitor.cpp#L450

    The problem is that in handling the -Gis flag it blindly sticks the NoContraction flag all over instructions without checking if the instruction is already decorated.

    Curious if Steven Perron (@s-perron) and/or Nathan Gauër (@Keenuts) have an idea of how this could be done better.

  3. added a commit that references this issue on Aug 19, 2025
  4. s-perron commented on Aug 20, 2025

    @s-perron
    Collaborator

    Off the top of my head, I don't know how to fix it. The ideal solution is that the decorations would get uniqued at some point. Individual pass should not have to avoid adding the decoration because an earlier pass did or a later pass will. We will try to look into it soon.

  5. added
    needs-triage
    and removed
    needs-triage
    on Aug 21, 2025
  6. alsepkow commented on Nov 19, 2026

    @alsepkow
    Contributor

    test/Feature/HLSLLib/mad.32.test was referencing this bug in an XFAIL

    But this fix KhronosGroup/SPIRV-Tools#6828 mitigates the issue. I'm removing the XFAIL but I think this bug still stands.

  7. joaosaffran commented on Nov 19, 2026

    @joaosaffran
    Collaborator

    This was fixed by: KhronosGroup/SPIRV-Tools#6828 and integrated in dxc when a497312 was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugspirv

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions