Skip to content

Commit

Permalink
[SimplifyLibCalls] Skip unused calls in sincos transform
Browse files Browse the repository at this point in the history
If the call result is unused, we should let it get DCEd rather
than replacing it. Also, don't try to replace an existing sincos
with another one (unless it's as part of combining sin and cos).

This avoids an infinite combine loop if the calls are not DCEd
as expected, which can happen with D94106 and lack of willreturn
annotation in hand-crafted IR.
  • Loading branch information
nikic committed Jan 22, 2021
1 parent faa4407 commit 45b259f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2187,7 +2187,7 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, IRBuilderBase &B) {
classifyArgUse(U, F, IsFloat, SinCalls, CosCalls, SinCosCalls);

// It's only worthwhile if both sinpi and cospi are actually used.
if (SinCosCalls.empty() && (SinCalls.empty() || CosCalls.empty()))
if (SinCalls.empty() || CosCalls.empty())
return nullptr;

Value *Sin, *Cos, *SinCos;
Expand All @@ -2213,7 +2213,7 @@ void LibCallSimplifier::classifyArgUse(
SmallVectorImpl<CallInst *> &SinCosCalls) {
CallInst *CI = dyn_cast<CallInst>(Val);

if (!CI)
if (!CI || CI->use_empty())
return;

// Don't consider calls in other functions.
Expand Down

0 comments on commit 45b259f

Please sign in to comment.