[compiler-rt] [compiler-rt] Stop using x86 builtin on AArch64 with GCC (PR #93890)

Alan Wu via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 07:25:45 PDT 2024


XrXr wrote:

Yes, there are other similar cases. Maybe instead of sprinkling the conditions backfilling for `__has_builtin` ad-hoc at each usage site, we should centralize the backfills with something like:

```c
#ifndef __has_builtin
// Simulate __has_builtin using version detection for older compilers
#define __has_builtin(x) COMPILER_RT_HAS_BUILTIN_ ##x

#if defined(__GNUC__) && __GNUC__ >= 7
#define COMPILER_RT_HAS_BUILTIN___builtin_copysignf128 1
#else
#define COMPILER_RT_HAS_BUILTIN___builtin_copysignf128 0
#endif

#endif
```

([Compiler Explorer link](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:2,lang:___c,selection:(endColumn:13,endLineNumber:14,positionColumn:13,positionLineNumber:14,selectionStartColumn:13,selectionStartLineNumber:14,startColumn:13,startLineNumber:14),source:'static+int+square(int+num)%3B%0A%0A%23ifndef+__has_builtin%0A//+Simulate+__has_builtin+using+version+detection+for+older+compilers%0A%23define+__has_builtin(x)+COMPILER_RT_HAS_BUILTIN_+%23%23x%0A%0A%23if+defined(__GNUC__)+%26%26+__GNUC__+%3E%3D+7%0A%23define+COMPILER_RT_HAS_BUILTIN___builtin_copysignf128+1%0A%23else%0A%23define+COMPILER_RT_HAS_BUILTIN___builtin_copysignf128+0%0A%23endif%0A%23endif%0A%0Aint+has(void)+%7B%0A++++return+__has_builtin(__builtin_copysignf128)%3B%0A%7D%0A'),l:'5',n:'1',o:'C+source+%232',t:'0')),header:(),k:29.740378234903787,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:cg6,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:2,lang:___c,libs:!(),options:'-E',overrides:!(),selection:(endColumn:2,endLineNumber:13,positionColumn:2,positionLineNumber:13,selectionStartColumn:2,selectionStartLineNumber:13,startColumn:2,startLineNumber:13),source:2),l:'5',n:'0',o:'+x86-64+gcc+6.1+(Editor+%232)',t:'0')),header:(),k:29.740378234903787,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:cg75,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:'-E',overrides:!(),selection:(endColumn:2,endLineNumber:13,positionColumn:2,positionLineNumber:13,selectionStartColumn:2,selectionStartLineNumber:13,startColumn:2,startLineNumber:13),source:2),l:'5',n:'0',o:'+x86-64+gcc+7.5+(Editor+%232)',t:'0')),header:(),k:40.51924353019244,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4))

This way usages can simply check `__has_builtin(x)` and look nicer.

The downside of this approach is that all the checked attributes need to be backfilled in the simulated definition.

I could also backfill and comment at each site. What do you think? @statham-arm 

https://github.com/llvm/llvm-project/pull/93890


More information about the llvm-commits mailing list