[llvm-branch-commits] [llvm] 45b259f - [SimplifyLibCalls] Skip unused calls in sincos transform

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 22 12:02:01 PST 2021


Author: Nikita Popov
Date: 2021-01-22T20:57:13+01:00
New Revision: 45b259f99509dda6820e09369d84c21d4ea33bcd

URL: https://github.com/llvm/llvm-project/commit/45b259f99509dda6820e09369d84c21d4ea33bcd
DIFF: https://github.com/llvm/llvm-project/commit/45b259f99509dda6820e09369d84c21d4ea33bcd.diff

LOG: [SimplifyLibCalls] Skip unused calls in sincos transform

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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index b68e45363811..4cb4e8848523 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -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;
@@ -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.


        


More information about the llvm-branch-commits mailing list