-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Description
Clang is supposed to support target multi-versioning where applying the target
attribute multiple times will result in several functions that are overloaded on the callers target type. This unfortunately generates functions that contain the set of all targets enabled for that function, which results in only the most permissive use to be inlined. I am trying to use this to create generic SIMD heplers https://godbolt.org/z/7f3aPfeeW.
The calling AVX2 target will have these attributes set.
attributes #2 = { mustprogress nounwind uwtable "min-legal-vector-width"="256" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+cmov,+crc32,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
While the callee will have these attributes. Because it contains avx512f
it's considered incompatible and cannot be inlined.
attributes #3 = { mustprogress nounwind uwtable "min-legal-vector-width"="256" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+avx512f,+cmov,+crc32,+cx8,+evex512,+f16c,+fma,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
Is this intentional behavior? If I manually eliminate the offending attributes the code words as expected and gives me optimal code no matter which target is calling. It seems bizarre that we would multi-version the functions but still create them with incorrect attributes for the target.