Skip to content

Commit 05bbb94

Browse files
authored
[X86] Relax AVX ABI warning on internal functions (#157570)
Summary: The vector target should be able to handle vector sizes that are multiples of the native size, this is useful for implementing math routines that want to temporarily use a high precision for example. However, currently this will emit a warning on x86 if any function calls are involved. https://godbolt.org/z/dK7hGndYh. I believe that we should be able to relax the ABI restriction if the functions are completely internal and there were no explicitly states attributes to conflict. Because the ABI is not exported outside the TU we should be safe to assume that it won't bite us. In the case that one call has no features and other does, that will still cause an error. I may be wrong on this assumption however. Fixes: #128361
1 parent 5437d90 commit 05bbb94

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,12 +1513,18 @@ static void initFeatureMaps(const ASTContext &Ctx,
15131513

15141514
static bool checkAVXParamFeature(DiagnosticsEngine &Diag,
15151515
SourceLocation CallLoc,
1516+
const FunctionDecl &Callee,
15161517
const llvm::StringMap<bool> &CallerMap,
15171518
const llvm::StringMap<bool> &CalleeMap,
15181519
QualType Ty, StringRef Feature,
15191520
bool IsArgument) {
15201521
bool CallerHasFeat = CallerMap.lookup(Feature);
15211522
bool CalleeHasFeat = CalleeMap.lookup(Feature);
1523+
// No explicit features and the function is internal, be permissive.
1524+
if (!CallerHasFeat && !CalleeHasFeat &&
1525+
(!Callee.isExternallyVisible() || Callee.hasAttr<AlwaysInlineAttr>()))
1526+
return false;
1527+
15221528
if (!CallerHasFeat && !CalleeHasFeat)
15231529
return Diag.Report(CallLoc, diag::warn_avx_calling_convention)
15241530
<< IsArgument << Ty << Feature;
@@ -1534,18 +1540,18 @@ static bool checkAVXParamFeature(DiagnosticsEngine &Diag,
15341540
}
15351541

15361542
static bool checkAVXParam(DiagnosticsEngine &Diag, ASTContext &Ctx,
1537-
SourceLocation CallLoc,
1543+
SourceLocation CallLoc, const FunctionDecl &Callee,
15381544
const llvm::StringMap<bool> &CallerMap,
15391545
const llvm::StringMap<bool> &CalleeMap, QualType Ty,
15401546
bool IsArgument) {
15411547
uint64_t Size = Ctx.getTypeSize(Ty);
15421548
if (Size > 256)
1543-
return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty,
1549+
return checkAVXParamFeature(Diag, CallLoc, Callee, CallerMap, CalleeMap, Ty,
15441550
"avx512f", IsArgument);
15451551

15461552
if (Size > 128)
1547-
return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, "avx",
1548-
IsArgument);
1553+
return checkAVXParamFeature(Diag, CallLoc, Callee, CallerMap, CalleeMap, Ty,
1554+
"avx", IsArgument);
15491555

15501556
return false;
15511557
}
@@ -1582,8 +1588,8 @@ void X86_64TargetCodeGenInfo::checkFunctionCallABI(CodeGenModule &CGM,
15821588
if (ArgIndex < Callee->getNumParams())
15831589
Ty = Callee->getParamDecl(ArgIndex)->getType();
15841590

1585-
if (checkAVXParam(CGM.getDiags(), CGM.getContext(), CallLoc, CallerMap,
1586-
CalleeMap, Ty, /*IsArgument*/ true))
1591+
if (checkAVXParam(CGM.getDiags(), CGM.getContext(), CallLoc, *Callee,
1592+
CallerMap, CalleeMap, Ty, /*IsArgument*/ true))
15871593
return;
15881594
}
15891595
++ArgIndex;
@@ -1594,7 +1600,7 @@ void X86_64TargetCodeGenInfo::checkFunctionCallABI(CodeGenModule &CGM,
15941600
if (Callee->getReturnType()->isVectorType() &&
15951601
CGM.getContext().getTypeSize(Callee->getReturnType()) > 128) {
15961602
initFeatureMaps(CGM.getContext(), CallerMap, Caller, CalleeMap, Callee);
1597-
checkAVXParam(CGM.getDiags(), CGM.getContext(), CallLoc, CallerMap,
1603+
checkAVXParam(CGM.getDiags(), CGM.getContext(), CallLoc, *Callee, CallerMap,
15981604
CalleeMap, Callee->getReturnType(),
15991605
/*IsArgument*/ false);
16001606
}

clang/test/CodeGen/target-builtin-error-3.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ static inline half16 __attribute__((__overloadable__)) convert_half( float16 a )
2424
}
2525
void avx_test( uint16_t *destData, float16 argbF)
2626
{
27-
// expected-warning@+1{{AVX vector argument of type 'float16' (vector of 16 'float' values) without 'avx512f' enabled changes the ABI}}
2827
((half16U *)destData)[0] = convert_half(argbF);
2928
}
29+
30+
half16 test( float16 a ) {
31+
half16 r;
32+
r.lo = convert_half(a.lo);
33+
return r;
34+
}
35+
void avx_test2( uint16_t *destData, float16 argbF)
36+
{
37+
// expected-warning@+1{{AVX vector argument of type 'float16' (vector of 16 'float' values) without 'avx512f' enabled changes the ABI}}
38+
((half16U *)destData)[0] = test(argbF);
39+
}
40+
41+
__attribute__((always_inline)) half16 test2( float16 a ) {
42+
half16 r;
43+
r.lo = convert_half(a.lo);
44+
return r;
45+
}
46+
void avx_test3( uint16_t *destData, float16 argbF)
47+
{
48+
((half16U *)destData)[0] = test2(argbF);
49+
}

0 commit comments

Comments
 (0)