`-Od`/`-O0` miscompile: branch condition folded to false
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 54/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 926
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 45
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/DirectXShaderCompiler
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainers usually reply within 2 days
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
microsoft/DirectXShaderCompiler#9155 · 4 comments ·
Maintainers usually reply within 2 days
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9135 ·
Maintainers usually reply within 2 days
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLPossibly taken @rj123-nv claimed this 18 days ago. Openbug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/DirectXShaderCompiler#9087 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/DirectXShaderCompiler#9086 ·
Maintainers usually reply within 2 days
All issues in microsoft/DirectXShaderCompiler
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
table_translator 当一个 Prism 键映射到多个原码时,首个候选未按权重排序Possibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
arch-based bug niri
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
noctalia-dev/noctalia#5552 ·
Maintainers usually reply within 1 day