Open Quuxplusone opened 10 years ago
Attached test.c
(129 bytes, text/x-csrc): Test case
Attached pr18890.cpp
(119 bytes, text/x-c++src): C++ test-case
Attached pr18890.s
(632 bytes, application/octet-stream): Assembly generated by the C++ testcase
I don't think the problem here is specific to __sync builtins or to C++11 atomics. The issue appears to be that the backend works on a SelectionDAG at a time, and in particular does not see that a constant (here 0) has already been materialized in a register that is still available. I don't know exactly how to fix this, and I suspect it may be rather hard.
I don't think it is that simple, the backend normally catches things like this,
two possible problems are:
1. xorl is marked 'as cheap as move', and thus does not trigger coalescing/CSE logic
2. xorl x, x is not recognized as a constant materialization
As a first step, you might want to figure out why MachineCSE does not get this.
test.c
(129 bytes, text/x-csrc)pr18890.cpp
(119 bytes, text/x-c++src)pr18890.s
(632 bytes, application/octet-stream)