@@ -56,6 +56,20 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
56
56
// dst = phi(v0, v1)
57
57
//
58
58
59
+ ORE->emit ([&]() {
60
+ return OptimizationRemark (DEBUG_TYPE, " SqrtPartiallyInlined" ,
61
+ Call->getDebugLoc (), &CurrBB)
62
+ << " Partially inlined call to sqrt function despite having to use "
63
+ " errno for error handling: target has fast sqrt instruction" ;
64
+ });
65
+ ORE->emit ([&]() {
66
+ return OptimizationRemarkMissed (DEBUG_TYPE, " BranchInserted" ,
67
+ Call->getDebugLoc (), &CurrBB)
68
+ << " Branch to library sqrt fn had to be inserted to satisfy the "
69
+ " current target's requirement for math functions to set errno on "
70
+ " invalid inputs" ;
71
+ });
72
+
59
73
Type *Ty = Call->getType ();
60
74
IRBuilder<> Builder (Call->getNextNode ());
61
75
@@ -125,18 +139,35 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
125
139
if (!Call || !(CalledFunc = Call->getCalledFunction ()))
126
140
continue ;
127
141
128
- if (Call->isNoBuiltin () || Call->isStrictFP ())
129
- continue ;
130
-
131
- if (Call->isMustTailCall ())
132
- continue ;
133
-
134
142
// Skip if function either has local linkage or is not a known library
135
143
// function.
136
144
LibFunc LF;
137
145
if (CalledFunc->hasLocalLinkage () ||
138
146
!TLI->getLibFunc (*CalledFunc, LF) || !TLI->has (LF))
139
147
continue ;
148
+ if (Call->isNoBuiltin ())
149
+ continue ;
150
+ if (Call->isStrictFP ()) {
151
+ ORE->emit ([&]() {
152
+ return OptimizationRemarkMissed (DEBUG_TYPE, " StrictFloat" ,
153
+ Call->getDebugLoc (), &*CurrBB)
154
+ << " Could not consider library function for partial inlining:"
155
+ " strict FP exception behavior is active" ;
156
+ });
157
+ continue ;
158
+ }
159
+ // Partially inlining a libcall that has the musttail attribute leads to
160
+ // broken LLVM IR, triggering an assertion in the IR verifier.
161
+ // Work around that by forgoing this optimization for musttail calls.
162
+ if (Call->isMustTailCall ()) {
163
+ ORE->emit ([&]() {
164
+ return OptimizationRemarkMissed (DEBUG_TYPE, " MustTailCall" ,
165
+ Call->getDebugLoc (), &*CurrBB)
166
+ << " Could not consider library function for partial inlining:"
167
+ " must tail call" ;
168
+ });
169
+ continue ;
170
+ }
140
171
141
172
switch (LF) {
142
173
case LibFunc_sqrtf:
0 commit comments