From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 652213858435; Mon, 4 Oct 2021 23:25:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 652213858435 From: "thiago at kde dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/102566] [i386] GCC should emit LOCK BTS for simple bit-test-and-set operations with std::atomic Date: Mon, 04 Oct 2021 23:25:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: thiago at kde dot org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2021 23:25:24 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102566 --- Comment #11 from Thiago Macieira --- $ for ((i=3D0;i<32;++i)); do ~/dev/gcc/bin/gcc "-DCONSTANT=3D(1<<$i)" -S -o= - -O2 /tmp/test.cpp | grep bts; done=20 lock btsl $0, (%rdi) lock btsl $1, (%rdi) lock btsl $2, (%rdi) lock btsl $3, (%rdi) lock btsl $4, (%rdi) lock btsl $5, (%rdi) lock btsl $6, (%rdi) lock btsl $7, (%rdi) lock btsl $8, (%rdi) lock btsl $9, (%rdi) lock btsl $10, (%rdi) lock btsl $11, (%rdi) lock btsl $12, (%rdi) lock btsl $13, (%rdi) lock btsl $14, (%rdi) lock btsl $15, (%rdi) lock btsl $16, (%rdi) lock btsl $17, (%rdi) lock btsl $18, (%rdi) lock btsl $19, (%rdi) lock btsl $20, (%rdi) lock btsl $21, (%rdi) lock btsl $22, (%rdi) lock btsl $23, (%rdi) lock btsl $24, (%rdi) lock btsl $25, (%rdi) lock btsl $26, (%rdi) lock btsl $27, (%rdi) lock btsl $28, (%rdi) lock btsl $29, (%rdi) lock btsl $30, (%rdi) lock btsl $31, (%rdi) And after changing to long: $ for ((i=3D32;i<64;++i)); do ~/dev/gcc/bin/gcc "-DCONSTANT=3D(1L<<$i)" -S = -o - -O2 /tmp/test.cpp | grep bts; done lock btsq $32, (%rdi) lock btsq $33, (%rdi) lock btsq $34, (%rdi) lock btsq $35, (%rdi) lock btsq $36, (%rdi) lock btsq $37, (%rdi) lock btsq $38, (%rdi) lock btsq $39, (%rdi) lock btsq $40, (%rdi) lock btsq $41, (%rdi) lock btsq $42, (%rdi) lock btsq $43, (%rdi) lock btsq $44, (%rdi) lock btsq $45, (%rdi) lock btsq $46, (%rdi) lock btsq $47, (%rdi) lock btsq $48, (%rdi) lock btsq $49, (%rdi) lock btsq $50, (%rdi) lock btsq $51, (%rdi) lock btsq $52, (%rdi) lock btsq $53, (%rdi) lock btsq $54, (%rdi) lock btsq $55, (%rdi) lock btsq $56, (%rdi) lock btsq $57, (%rdi) lock btsq $58, (%rdi) lock btsq $59, (%rdi) lock btsq $60, (%rdi) lock btsq $61, (%rdi) lock btsq $62, (%rdi) lock btsq $63, (%rdi) But: $ cat /tmp/test2.cpp=20 #include bool tbit(std::atomic &i) { return i.fetch_or(1, std::memory_order_relaxed) & (~1); } $ ~/dev/gcc/bin/gcc -S -o - -O2 /tmp/test2.cpp .file "test.cpp" .text /tmp/test.cpp: In function =E2=80=98bool tbit(std::atomic&)=E2=80= =99: /tmp/test.cpp:2:6: error: type mismatch in binary expression 2 | bool tbit(std::atomic &i) | ^~~~ long int long unsigned int __int_type _9 =3D _6 & -2; during GIMPLE pass: fab /tmp/test.cpp:2:6: internal compiler error: verify_gimple failed 0x119fbba verify_gimple_in_cfg(function*, bool) /home/tjmaciei/src/gcc/gcc/tree-cfg.c:5576 0x106ced7 execute_function_todo /home/tjmaciei/src/gcc/gcc/passes.c:2042 0x106d8fb execute_todo /home/tjmaciei/src/gcc/gcc/passes.c:2096 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See for instructions.=