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

Đang mở
#9,053 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
54/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
3.7k
Fork
926
Merge trung bình
3 ngày 22 giờ
Pull request đã merge (30 ngày)
45

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/DirectXShaderCompiler

Tất cả issue của microsoft/DirectXShaderCompiler

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.