https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126257
--- Comment #5 from Kael Franco <kaelfandrew at gmail dot com> --- (In reply to Jakub Jelinek from comment #4) > Created attachment 65040 [details] > gcc17-pr1262257.patch > > Untested fix. Shouldn't x+x for integral types be x << 1? Clang does it but GCC misses it. GCC optimize this with -O2: https://godbolt.org/z/rozG6W779 ``` _BitInt(2) src (_BitInt(2) n) { return n + n; } ``` to ``` _BitInt(2) src (_BitInt(2) n) { _BitInt(2) _2; <bb 2> [local count: 1073741824]: # DEBUG BEGIN_STMT _2 = n_1(D) * -2; return _2; } ``` which is wrong when n = -1 as (-1 + -1) != (-1) * (-2). src () should be a simpler testcase than your testcase. Applying your patch fixes GCC to make src () keep n + n instead. This is similar to (1 << (_Bool)a) -> (1 + a) when a is _BitInt(2) in https://gcc.gnu.org/pipermail/gcc-patches/2026-July/722643.html
