`-Od`/`-O0` miscompile: branch condition folded to false

Abierto
#9,053 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
54/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
compilers

Línea de trabajo

Start by compiling the provided HLSL reproducer with dxc -T cs_6_0 -E main -Od repro.hlsl -Fc out.txt, then compare its output with -O1 and -O3. Trace how the branch condition is handled in the compiler and find why the mark.Store path and binding disappear at -Od; done means the mark write is retained for nonzero x at -Od.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug needs-triage

Description
At -Od and -O0 DXC deletes a reachable branch: if (zero < y) is compiled as if it were always false. -O1 and -O3 produce correct code.

Steps to Reproduce

// For any x != 0 the mark branch runs (0 < x), but at -Od DXC removes it.
ByteAddressBuffer inp : register(t0);
RWByteAddressBuffer mark : register(u1);
RWByteAddressBuffer unmark : register(u2);

uint f(uint a, uint b) { return b == 0u ? a : 0u; }   // f(0, 1) == 0

[numthreads(1, 1, 1)]
void main()
{
    uint x = inp.Load(0);
    uint zero = f(0u, 1u);
    uint y = x != 0u ? x : 0u;                         // == x
    if (zero < y) {
        mark.Store(0, 1u);
    } else {
        unmark.Store(0, 1u);
    }

    uint2 c = uint2(0u, 0u);                           // never iterates, but needed
    while (c.x != 0u) { c.x -= 1u; }
}

Compile with dxc -T cs_6_0 -E main -Od repro.hlsl -Fc out.txt

Godbolt of -Od: https://godbolt.org/z/aY85vcY33
Godbolt of -O3: https://godbolt.org/z/osoP7qGhK

Actual Behavior
For any input x != 0, mark should be written. However, at -Od the output contains no store to mark, and mark is missing from the resource bindings.

Environment

  • DXC version: (libdxcompiler.so: 1.9(5512-01b62ad4)(1.9.2609.5)) and trunk (via godbolt)
  • Host Operating System: Linux x86_64 release binaries.

AI Discolosure
Opus 5.5 was used for test-case minimization.

Lenguaje dominante
C++
Estrellas
3.7k
Forks
926
Merge medio
3 d 22 h
PR fusionados (30 d)
45

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/DirectXShaderCompiler

Todos los issues de microsoft/DirectXShaderCompiler

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.