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

Aperta
#9,053 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
3.7k
Fork
926
Merge medio
3g 22h
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/DirectXShaderCompiler

Tutte le issue di microsoft/DirectXShaderCompiler

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.