https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107895
Bug ID: 107895 Summary: mt19937 bad performance on LP64 Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jengelh at inai dot de Target Milestone: --- Input ===== #include <random> #include <unistd.h> static std::mt19937 rng; int main() { for (size_t j = 0; j < 0x8000; ++j) { uint32_t numbers[65536]; for (size_t i = 0; i < std::size(numbers); ++i) numbers[i] = rng(); // ensure number generation is not all optimized away write(STDOUT_FILENO, numbers, sizeof(numbers)); } } Observed ======== Target: x86_64-suse-linux gcc version 12.2.1 20221020 [revision 0aaef83351473e8f4eb774f8f999bbe87a4866d7] (SUSE Linux) $ g++ x.cpp -O2 && time ./a.out >/dev/zero -m32 -m64 =============== ===== ====== std::mt19937 3.9s 11.5s std::mt19937_64 14.0s 11.6s =============== ===== ====== error ±0.1s With -ftree-loop-if-convert [Bug #80520], but still not at -m32 levels: +-ftree- -m32 -m64 =============== ===== ====== std::mt19937 3.9s 5.2s std::mt19937_64 14.0s 5.4s =============== ===== ====== error ±0.1s Expected ======== Expected to see <= 4.7s on -m64 at all times. (3.9 + ~20% margin for wider transfers CPU<->caches/RAM) The -m64 versions should have somewhat equal runtime or faster runtime (because more registers, more opportunities); concerns like https://gmplib.org/32vs64 apply to old CPUs, but I do not think it's indicative of how contemporary x86_64 systems perform. Additional information ====================== CPUs: "11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz" [fam 6 model 140 stepping 1 microcode 0xa4] and "AMD Ryzen 7 3700X 8-Core Processor" [fam 23 model 113 stepping 0 microcode 0x8701013] (about 3.0 and 10.2 seconds runtime, respectively)