neldredge wrote:

Note there are some missed optimizations here.  For instance, `atomic_bool b; b 
+= 1;` compiles to a compare-exchange loop ([try on 
Godbolt](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:12,endLineNumber:4,positionColumn:12,positionLineNumber:4,selectionStartColumn:12,selectionStartLineNumber:4,startColumn:12,startLineNumber:4),source:'%23include+%3Cstdatomic.h%3E%0Aatomic_bool+b%3B%0Avoid+foo(void)+%7B%0A++++b+%2B%3D+1%3B%0A%7D%0A'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:47.71438104771438,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:cclang_trunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'-O3+-pedantic+-std%3Dc23',overrides:!(),selection:(endColumn:18,endLineNumber:11,positionColumn:18,positionLineNumber:11,selectionStartColumn:18,selectionStartLineNumber:11,startColumn:18,startLineNumber:11),source:1),l:'5',n:'0',o:'+x86-64+clang+(trunk)+(Editor+%231)',t:'0')),k:52.28561895228561,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4))
 when it could simply do `mov byte ptr [b], 1`.  

Likewise for `b ^= 1`, which might actually be useful; it could be `lock xor` 
and derive its return value from the zero flag.

https://github.com/llvm/llvm-project/pull/178220
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to