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
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Doorriiaann on 2026-11-09T10:07:26Z.
What happens
Built with GCC 14.2 (Release),
TranslationContext::f32DenormalFlushForincore/shader/recompiler/Translation/src/VectorInstructions.cppreturns 0 forv_mul_f32with 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_flushandagc_driver_mullit_f32_denormal_modesfail (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 main3e354e2cf4(2026-11-09). First bad main commit:5d3ad2112f(merge of #10720); its first parentca82d0c022passes.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
Steps to reproduce
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
What was checked
The three GPU messages in the log are from the RTX 3070. On llvmpipe
agc_driver_divisionandagc_driver_mullit_f32_denormal_modesprint the same lines, andagc_driver_f32_denormal_flushfails earlier, atv_mul_f32 v12, v4, v5 is 0x00000001, expected 0x00000000.Same source (
main095ff72367),vector_constant_factor_tininessunless noted; "4 tests" = the four above on both the RTX 3070 and llvmpipe, with Vulkan-ValidationLayersvulkan-sdk-1.4.335.0loaded and noVUID-line in any run.-O3)-O2-O1-O0)agc_driver_present_upscale, #17179, andvideo_out_hdr_presentwith the screen locked)-O3with onlyVectorInstructions.cppat-O0-O3with onlyVectorInstructions.cppat-O3 -fno-tree-pre-O3 -D_GLIBCXX_ASSERTIONS,-ftrivial-auto-var-init=zero/=pattern,-fno-strict-aliasing,-fno-ipa-icf, or withoutNDEBUG-fsanitize=undefinedANYPS5_ENABLE_ASAN=ON(RelWithDebInfo)Which file: compiling all 442 translation units linked into the tininess test at
-O3and bisecting which ones need-O0(a compiler launcher appending-O0, no source change) leavesTranslation/src/VectorInstructions.cppalone.Which pass: with that file at
-O2and each of the 45 options-O2adds over-O1disabled one at a time, only-fno-tree-prepasses.Which commit: a first-parent bisect of
mainfrom4213dda236(passes) gives5d3ad2112f, the merge of #10720, which addsif (!ExactF32Arithmetic()) return 0u;near the end off32DenormalFlushFor. Fresh build directories confirmca82d0c022passes and5d3ad2112ffails.APS5_FAST_F32is unset (anLD_PRELOADgetenvlog showsAPS5_FAST_F32 -> (null)), and the compiledExactF32Arithmetic()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): forv_mul_f32(RdnaOpcode0x2a) with a float mode present, round mode 0 and denormal mode 0,f32DenormalFlushForreachesja 2396and the block at 2396 iscall ExactF32Arithmetic(); xor %eax,%eax; ... ret, so it returns 0 and ignores the call's result. Per the source the case setsflush = 3u; break;, and with exact arithmetic, denormal mode 0 andfloat32FlushToZerofalse it returns 3. The block at 2396 is the tail for cases that leaveflushat 0 (roundsProductSeparately), where returning 0 is right whateverExactF32Arithmetic()returns. In GCC 13.3's code for the same function, the corresponding tail tests the call's result and thenfloat32FlushToZerobefore 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,addressand 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) != 0gets the constant 1 on an edge where that is not known (Created phi prephitmp_24 = PHI <1(16), 0(14)>), apparently from a range ofm & 48that only holds in another block.repro.c
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.cppitself 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-preonVectorInstructions.cppwhen 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)