gcc-15 bugs, pile 1

August 25, 2024

About 4 months have passed since gcc-14.1.0 release. Around the same time gcc-15 development has started and a few major changes were merged into the master development branch.

summary

This time I waited to collect about 20 bug reports I encountered:

fun bug

The zlib bug is probably the most unusual one. Due to a typo in newly introduced set of optimizations gcc managed to convert a > b ? b : a type of expressions into an equivalent of b > a ? b : a. But it only does it for b = INT_MAX type of arguments (case of saturation).

As a result it only broke zlib test suite as it specifically tests for out of range access to cause SIGSEGVs. For well-behaved inputs it never caused any problems. The gcc fix was trivial:

--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -9990,7 +9990,7 @@
   rtx sat = force_reg (DImode, GEN_INT (GET_MODE_MASK (<MODE>mode)));
   rtx dst;

-  emit_insn (gen_cmpdi_1 (op1, sat));
+  emit_insn (gen_cmpdi_1 (sat, op1));

   if (TARGET_CMOVE)
     {
@@ -10026,7 +10026,7 @@
   rtx sat = force_reg (SImode, GEN_INT (GET_MODE_MASK (<MODE>mode)));
   rtx dst;

-  emit_insn (gen_cmpsi_1 (op1, sat));
+  emit_insn (gen_cmpsi_1 (sat, op1));

   if (TARGET_CMOVE)
     {
@@ -10062,7 +10062,7 @@
   rtx sat = force_reg (HImode, GEN_INT (GET_MODE_MASK (QImode)));
   rtx dst;

-  emit_insn (gen_cmphi_1 (op1, sat));
+  emit_insn (gen_cmphi_1 (sat, op1));

   if (TARGET_CMOVE)
     {

We swap argument order to restore original intent.

histograms

Where did most gcc bugs come from?

As usual tree-optimization is at the top of subsystem causing troubles. But this time rtl-optimization got close to it as well.

highway managed to yield us 4 new bugs while llvm got us just one new bug.

parting words

gcc-15 got a few very nice optimizations (and bugs) related to saturated truncation, zero/sign-extension elimination, constant folding in RTL.

I saw at least 5 bugs related to wrong code generation (and also slowly reducing another one in the background). middl-end ones were easy to reduce and explore, RTL ones were very elusive.

The most disruptive change is probably a removal of #include <cstdint> from one of libstdc++ headers. That requires quite a few upstream fixes to add missing headers (cppdap, woff2, graphite, glslang, widelands, wesnoth and many others).

Have fun!