Recompiler: GCC 14.2 at -O2 and above miscompiles f32DenormalFlushFor (tree-pre), so f32 tiny-product and denormal flushes are dropped and four tests fail #17685

Closed
opened 2026-11-09 10:07:26 +00:00 by Doorriiaann · 0 comments
Doorriiaann commented 2026-11-09 10:07:26 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Doorriiaann on 2026-11-09T10:07:26Z.


What happens

Built with GCC 14.2 (Release), TranslationContext::f32DenormalFlushFor in core/shader/recompiler/Translation/src/VectorInstructions.cpp returns 0 for v_mul_f32 with round mode 0 and f32 denormal mode 0 where the source returns 3, so the tiny-product flush is not emitted; vector_constant_factor_tininess, agc_driver_division, agc_driver_f32_denormal_flush and agc_driver_mullit_f32_denormal_modes fail (the first runs on the CPU only; the others fail on both GPUs tried, an RTX 3070 and llvmpipe).

Title, test or build step

ctest: vector_constant_factor_tininess, agc_driver_division, agc_driver_f32_denormal_flush, agc_driver_mullit_f32_denormal_modes

AnyPS5 commit

main 095ff72367 (no PRs on top), and the same four failures on main 3e354e2cf4 (2026-11-09). First bad main commit: 5d3ad2112f (merge of #10720); its first parent ca82d0c022 passes.

System

Debian 13, kernel 6.12.115, gcc (Debian 14.2.0-19) 14.2.0 (a gcc-14 branch snapshot of 2025-03-15 per Debian's changelog), CMAKE_BUILD_TYPE=Release (-O3 -DNDEBUG), CI's Linux configure flags; NVIDIA GeForce RTX 3070 (610.57.04) and llvmpipe (Mesa 25.0.7, LLVM 19.1.7). For comparison: g++-13 (Debian 13.3.0-16) 13.3.0.

Host report

n/a (ctest only, no title)

Steps to reproduce

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build --target vector_constant_factor_tininess_tests
build/tests/vector_constant_factor_tininess_tests

The GPU tests: ANYPS5_GPU=<NVIDIA|llvmpipe> ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R '^(agc_driver_division|agc_driver_f32_denormal_flush|agc_driver_mullit_f32_denormal_modes)$' -V. Every run fails the same way; under a second.

Log

f32 constant factor: v_mul_f32 v5, v6, v7 emits 0 rounded tiny product checks, expected 1
AGC graphics: division scale denormals: lane 0 mode 0x000000c0: v_div_scale_f32 is 0x00000001 vcc 0, expected 0x00000000 vcc 0
AGC graphics: f32 denormal flush: lane 0 IEEE=0 f32 denormals flushed v_frexp_mant_f32 v21, v4 is 0x3f000000, expected 0x00000000
AGC graphics: v_mullit_f32 denorm32 0 no ieee inputs 0x00000000 0x00000000 0x00000001 is 0x00000000, expected 0xff7fffff

What was checked

The three GPU messages in the log are from the RTX 3070. On llvmpipe agc_driver_division and agc_driver_mullit_f32_denormal_modes print the same lines, and agc_driver_f32_denormal_flush fails earlier, at v_mul_f32 v12, v4, v5 is 0x00000001, expected 0x00000000.

Same source (main 095ff72367), vector_constant_factor_tininess unless noted; "4 tests" = the four above on both the RTX 3070 and llvmpipe, with Vulkan-ValidationLayers vulkan-sdk-1.4.335.0 loaded and no VUID- line in any run.

Build Result
GCC 14.2 Release (-O3) 4 tests fail, every run (30 of 30 runs of the tininess test, with and without ASLR, also with an empty environment)
GCC 14.2 -O2 fails
GCC 14.2 -O1 passes
GCC 14.2 Debug (-O0) 4 tests pass
GCC 13.3 Release 4 tests pass (full ctest on the RTX 3070: 4590 of 4592 pass, the other two are agc_driver_present_upscale, #17179, and video_out_hdr_present with the screen locked)
GCC 14.2 -O3 with only VectorInstructions.cpp at -O0 4 tests pass
GCC 14.2 -O3 with only VectorInstructions.cpp at -O3 -fno-tree-pre 4 tests pass
GCC 14.2 -O3 -D_GLIBCXX_ASSERTIONS, -ftrivial-auto-var-init=zero / =pattern, -fno-strict-aliasing, -fno-ipa-icf, or without NDEBUG fails, no assertion
GCC 14.2 with -fsanitize=undefined passes, no UBSan report
GCC 14.2 ANYPS5_ENABLE_ASAN=ON (RelWithDebInfo) fails, no ASan report
  • Which file: compiling all 442 translation units linked into the tininess test at -O3 and bisecting which ones need -O0 (a compiler launcher appending -O0, no source change) leaves Translation/src/VectorInstructions.cpp alone.

  • Which pass: with that file at -O2 and each of the 45 options -O2 adds over -O1 disabled one at a time, only -fno-tree-pre passes.

  • Which commit: a first-parent bisect of main from 4213dda236 (passes) gives 5d3ad2112f, the merge of #10720, which adds if (!ExactF32Arithmetic()) return 0u; near the end of f32DenormalFlushFor. Fresh build directories confirm ca82d0c022 passes and 5d3ad2112f fails. APS5_FAST_F32 is unset (an LD_PRELOAD getenv log shows APS5_FAST_F32 -> (null)), and the compiled ExactF32Arithmetic() returns 1 for that, so the change is a no-op at run time and only changes what GCC does with the function.

  • The generated code (VectorInstructions.cpp.o, GCC 14.2 -O3): for v_mul_f32 (RdnaOpcode 0x2a) with a float mode present, round mode 0 and denormal mode 0, f32DenormalFlushFor reaches ja 2396 and the block at 2396 is call ExactF32Arithmetic(); xor %eax,%eax; ... ret, so it returns 0 and ignores the call's result. Per the source the case sets flush = 3u; break;, and with exact arithmetic, denormal mode 0 and float32FlushToZero false it returns 3. The block at 2396 is the tail for cases that leave flush at 0 (roundsProductSeparately), where returning 0 is right whatever ExactF32Arithmetic() returns. In GCC 13.3's code for the same function, the corresponding tail tests the call's result and then float32FlushToZero before returning 3 (5 call sites against GCC 14.2's 3), and the test passes.

  • A standalone reduction (32 lines, no AnyPS5 code, no UB: clean under -Wall -Wextra -Werror, -fsanitize=undefined,address and clang's -fsanitize=memory) shows the same wrong code: f(0, 1, 3, 1) returns 0 instead of 3 with gcc 14 at -O2/-O3, and 3 with -fno-tree-pre, -fno-tree-vrp, -O1, -O0, gcc 13.3 and clang 19. In GCC's PRE dump the comparison ((m >> 4) & 3) != 0 gets the constant 1 on an edge where that is not known (Created phi prephitmp_24 = PHI <1(16), 0(14)>), apparently from a range of m & 48 that only holds in another block.

    repro.c
    #include <stdio.h>
    #include <stdlib.h>
    
    __attribute__((noipa)) int g(void) { return 1; }
    
    static int hw(int m, int op, int family) {
        if ((m & 3) || op != 2) return 0;
        return family;
    }
    
    __attribute__((noipa)) int f(int m, int has, int op, int family) {
        int flush = 3;
        if (!op) {
            flush = 0;
            if (!(m & 16)) return 0;
            if ((m & 48) == 16) return 0;
        }
        int d = has ? (m >> 4) & 3 : 0;
        if (op == 1 && d) return 0;
        if (!g()) return 0;
        if (d) return 0;
        if (flush && hw(m, op, family)) return 0;
        return flush;
    }
    
    int main(void) {
        int r = f(0, 1, 3, 1);
        printf("f(0, 1, 3, 1) = %d (expected 3)\n", r);
        fflush(stdout);
        if (r != 3) abort();
        return 0;
    }
    
  • I found no matching GCC report. The closest, PR 115494 ("PRE PHI translation and ranges"), is fixed on the gcc-14 branch and that fix is already in this compiler (Debian 14.2.0-18 changelog).

  • Other GCC versions, with the reduction built by C compilers from the release tarballs: still wrong with 14.4.0 (the latest 14.x), correct with 15.3.0 and 16.2.0. I did not build VectorInstructions.cpp itself with them. Windows CI uses GCC 15.2 and #16967 was tested with GCC 16.2.1, so this looks specific to GCC 14. Debian 13's default compiler is GCC 14.2, so a Release build there translates these instructions without the flushes.

  • Possible workarounds, for whoever picks this up: -fno-tree-pre on VectorInstructions.cpp when building with GCC 14, or documenting GCC 14 as unsupported for Release builds. Either way the code itself looks correct.

AI-assisted: yes (run and drafted with an AI agent, checked by me)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6284025128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/17685). Originally posted by [Doorriiaann](https://github.com/Doorriiaann) on 2026-11-09T10:07:26Z. --- ### What happens Built with GCC 14.2 (Release), `TranslationContext::f32DenormalFlushFor` in `core/shader/recompiler/Translation/src/VectorInstructions.cpp` returns 0 for `v_mul_f32` with round mode 0 and f32 denormal mode 0 where the source returns 3, so the tiny-product flush is not emitted; `vector_constant_factor_tininess`, `agc_driver_division`, `agc_driver_f32_denormal_flush` and `agc_driver_mullit_f32_denormal_modes` fail (the first runs on the CPU only; the others fail on both GPUs tried, an RTX 3070 and llvmpipe). ### Title, test or build step ctest: vector_constant_factor_tininess, agc_driver_division, agc_driver_f32_denormal_flush, agc_driver_mullit_f32_denormal_modes ### AnyPS5 commit main 095ff72367 (no PRs on top), and the same four failures on main 3e354e2cf4 (2026-11-09). First bad main commit: 5d3ad2112f (merge of #10720); its first parent ca82d0c022 passes. ### System Debian 13, kernel 6.12.115, gcc (Debian 14.2.0-19) 14.2.0 (a gcc-14 branch snapshot of 2025-03-15 per Debian's changelog), `CMAKE_BUILD_TYPE=Release` (`-O3 -DNDEBUG`), CI's Linux configure flags; NVIDIA GeForce RTX 3070 (610.57.04) and llvmpipe (Mesa 25.0.7, LLVM 19.1.7). For comparison: g++-13 (Debian 13.3.0-16) 13.3.0. ### Host report ```text n/a (ctest only, no title) ``` ### Steps to reproduce ``` cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DANYPS5_ENABLE_SPIRV_TOOLS=ON cmake --build build --target vector_constant_factor_tininess_tests build/tests/vector_constant_factor_tininess_tests ``` The GPU tests: `ANYPS5_GPU=<NVIDIA|llvmpipe> ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R '^(agc_driver_division|agc_driver_f32_denormal_flush|agc_driver_mullit_f32_denormal_modes)$' -V`. Every run fails the same way; under a second. ### Log ```text f32 constant factor: v_mul_f32 v5, v6, v7 emits 0 rounded tiny product checks, expected 1 AGC graphics: division scale denormals: lane 0 mode 0x000000c0: v_div_scale_f32 is 0x00000001 vcc 0, expected 0x00000000 vcc 0 AGC graphics: f32 denormal flush: lane 0 IEEE=0 f32 denormals flushed v_frexp_mant_f32 v21, v4 is 0x3f000000, expected 0x00000000 AGC graphics: v_mullit_f32 denorm32 0 no ieee inputs 0x00000000 0x00000000 0x00000001 is 0x00000000, expected 0xff7fffff ``` ### What was checked The three GPU messages in the log are from the RTX 3070. On llvmpipe `agc_driver_division` and `agc_driver_mullit_f32_denormal_modes` print the same lines, and `agc_driver_f32_denormal_flush` fails earlier, at `v_mul_f32 v12, v4, v5 is 0x00000001, expected 0x00000000`. Same source (`main` 095ff72367), `vector_constant_factor_tininess` unless noted; "4 tests" = the four above on both the RTX 3070 and llvmpipe, with Vulkan-ValidationLayers `vulkan-sdk-1.4.335.0` loaded and no `VUID-` line in any run. | Build | Result | |---|---| | GCC 14.2 Release (`-O3`) | 4 tests fail, every run (30 of 30 runs of the tininess test, with and without ASLR, also with an empty environment) | | GCC 14.2 `-O2` | fails | | GCC 14.2 `-O1` | passes | | GCC 14.2 Debug (`-O0`) | 4 tests pass | | GCC 13.3 Release | 4 tests pass (full ctest on the RTX 3070: 4590 of 4592 pass, the other two are `agc_driver_present_upscale`, #17179, and `video_out_hdr_present` with the screen locked) | | GCC 14.2 `-O3` with only `VectorInstructions.cpp` at `-O0` | 4 tests pass | | GCC 14.2 `-O3` with only `VectorInstructions.cpp` at `-O3 -fno-tree-pre` | 4 tests pass | | GCC 14.2 `-O3 -D_GLIBCXX_ASSERTIONS`, `-ftrivial-auto-var-init=zero` / `=pattern`, `-fno-strict-aliasing`, `-fno-ipa-icf`, or without `NDEBUG` | fails, no assertion | | GCC 14.2 with `-fsanitize=undefined` | passes, no UBSan report | | GCC 14.2 `ANYPS5_ENABLE_ASAN=ON` (RelWithDebInfo) | fails, no ASan report | - **Which file:** compiling all 442 translation units linked into the tininess test at `-O3` and bisecting which ones need `-O0` (a compiler launcher appending `-O0`, no source change) leaves `Translation/src/VectorInstructions.cpp` alone. - **Which pass:** with that file at `-O2` and each of the 45 options `-O2` adds over `-O1` disabled one at a time, only `-fno-tree-pre` passes. - **Which commit:** a first-parent bisect of `main` from 4213dda236 (passes) gives 5d3ad2112f, the merge of #10720, which adds `if (!ExactF32Arithmetic()) return 0u;` near the end of `f32DenormalFlushFor`. Fresh build directories confirm ca82d0c022 passes and 5d3ad2112f fails. `APS5_FAST_F32` is unset (an `LD_PRELOAD` `getenv` log shows `APS5_FAST_F32 -> (null)`), and the compiled `ExactF32Arithmetic()` returns 1 for that, so the change is a no-op at run time and only changes what GCC does with the function. - **The generated code** (`VectorInstructions.cpp.o`, GCC 14.2 `-O3`): for `v_mul_f32` (`RdnaOpcode` 0x2a) with a float mode present, round mode 0 and denormal mode 0, `f32DenormalFlushFor` reaches `ja 2396` and the block at 2396 is `call ExactF32Arithmetic(); xor %eax,%eax; ... ret`, so it returns 0 and ignores the call's result. Per the source the case sets `flush = 3u; break;`, and with exact arithmetic, denormal mode 0 and `float32FlushToZero` false it returns 3. The block at 2396 is the tail for cases that leave `flush` at 0 (`roundsProductSeparately`), where returning 0 is right whatever `ExactF32Arithmetic()` returns. In GCC 13.3's code for the same function, the corresponding tail tests the call's result and then `float32FlushToZero` before returning 3 (5 call sites against GCC 14.2's 3), and the test passes. - A standalone reduction (32 lines, no AnyPS5 code, no UB: clean under `-Wall -Wextra -Werror`, `-fsanitize=undefined,address` and clang's `-fsanitize=memory`) shows the same wrong code: `f(0, 1, 3, 1)` returns 0 instead of 3 with gcc 14 at `-O2`/`-O3`, and 3 with `-fno-tree-pre`, `-fno-tree-vrp`, `-O1`, `-O0`, gcc 13.3 and clang 19. In GCC's PRE dump the comparison `((m >> 4) & 3) != 0` gets the constant 1 on an edge where that is not known (`Created phi prephitmp_24 = PHI <1(16), 0(14)>`), apparently from a range of `m & 48` that only holds in another block. <details><summary>repro.c</summary> ```c #include <stdio.h> #include <stdlib.h> __attribute__((noipa)) int g(void) { return 1; } static int hw(int m, int op, int family) { if ((m & 3) || op != 2) return 0; return family; } __attribute__((noipa)) int f(int m, int has, int op, int family) { int flush = 3; if (!op) { flush = 0; if (!(m & 16)) return 0; if ((m & 48) == 16) return 0; } int d = has ? (m >> 4) & 3 : 0; if (op == 1 && d) return 0; if (!g()) return 0; if (d) return 0; if (flush && hw(m, op, family)) return 0; return flush; } int main(void) { int r = f(0, 1, 3, 1); printf("f(0, 1, 3, 1) = %d (expected 3)\n", r); fflush(stdout); if (r != 3) abort(); return 0; } ``` </details> - I found no matching GCC report. The closest, PR 115494 ("PRE PHI translation and ranges"), is fixed on the gcc-14 branch and that fix is already in this compiler (Debian 14.2.0-18 changelog). - Other GCC versions, with the reduction built by C compilers from the release tarballs: still wrong with 14.4.0 (the latest 14.x), correct with 15.3.0 and 16.2.0. I did not build `VectorInstructions.cpp` itself with them. Windows CI uses GCC 15.2 and #16967 was tested with GCC 16.2.1, so this looks specific to GCC 14. Debian 13's default compiler is GCC 14.2, so a Release build there translates these instructions without the flushes. - Possible workarounds, for whoever picks this up: `-fno-tree-pre` on `VectorInstructions.cpp` when building with GCC 14, or documenting GCC 14 as unsupported for Release builds. Either way the code itself looks correct. AI-assisted: yes (run and drafted with an AI agent, checked by me)
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#17685
No description provided.