Skip to content

Commit 5a9000b

Browse files
committed
Merging r345826:
------------------------------------------------------------------------ r345826 | erichkeane | 2018-11-01 05:50:37 -0700 (Thu, 01 Nov 2018) | 15 lines CPU-Dispatch-- Fix conflict between 'generic' and 'pentium' When a dispatch function was being emitted that had both a generic and a pentium configuration listed, we would assert. This is because neither configuration has any 'features' associated with it so they were both considered the 'default' version. 'pentium' lacks any features because we implement it in terms of __builtin_cpu_supports (instead of Intel proprietary checks), which is unable to decern between the two. The fix for this is to omit the 'generic' version from the dispatcher if both are present. This permits existing code to compile, and still will choose the 'best' version available (since 'pentium' is technically better than 'generic'). Change-Id: I4b69f3e0344e74cbdbb04497845d5895dd05fda0 ------------------------------------------------------------------------ llvm-svn: 348682
1 parent f98e746 commit 5a9000b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,6 +2505,22 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
25052505
return CodeGenFunction::GetX86CpuSupportsMask(LHS.Conditions.Features) >
25062506
CodeGenFunction::GetX86CpuSupportsMask(RHS.Conditions.Features);
25072507
});
2508+
2509+
// If the list contains multiple 'default' versions, such as when it contains
2510+
// 'pentium' and 'generic', don't emit the call to the generic one (since we
2511+
// always run on at least a 'pentium'). We do this by deleting the 'least
2512+
// advanced' (read, lowest mangling letter).
2513+
while (Options.size() > 1 &&
2514+
CodeGenFunction::GetX86CpuSupportsMask(
2515+
(Options.end() - 2)->Conditions.Features) == 0) {
2516+
StringRef LHSName = (Options.end() - 2)->Function->getName();
2517+
StringRef RHSName = (Options.end() - 1)->Function->getName();
2518+
if (LHSName.compare(RHSName) < 0)
2519+
Options.erase(Options.end() - 2);
2520+
else
2521+
Options.erase(Options.end() - 1);
2522+
}
2523+
25082524
CodeGenFunction CGF(*this);
25092525
CGF.EmitMultiVersionResolver(ResolverFunc, Options);
25102526
}

clang/test/CodeGen/attr-cpuspecific.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ void HasGeneric(void);
9696
// CHECK: ret void ()* @HasGeneric.A
9797
// CHECK-NOT: call void @llvm.trap
9898

99+
__attribute__((cpu_dispatch(atom, generic, pentium)))
100+
int GenericAndPentium(int i, double d);
101+
// CHECK: define i32 (i32, double)* @GenericAndPentium.resolver()
102+
// CHECK: call void @__cpu_indicator_init
103+
// CHECK: ret i32 (i32, double)* @GenericAndPentium.O
104+
// CHECK: ret i32 (i32, double)* @GenericAndPentium.B
105+
// CHECK-NOT: ret i32 (i32, double)* @GenericAndPentium.A
106+
// CHECK-NOT: call void @llvm.trap
107+
99108
// CHECK: attributes #[[S]] = {{.*}}"target-features"="+avx,+cmov,+f16c,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave"
100109
// CHECK: attributes #[[K]] = {{.*}}"target-features"="+adx,+avx,+avx2,+avx512cd,+avx512er,+avx512f,+avx512pf,+bmi,+cmov,+f16c,+fma,+lzcnt,+mmx,+movbe,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave"
101110
// CHECK: attributes #[[O]] = {{.*}}"target-features"="+cmov,+mmx,+movbe,+sse,+sse2,+sse3,+ssse3,+x87"

0 commit comments

Comments
 (0)