From abae6b588beb31864570c4c09c7335bfd7dd8ae5 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 19 Mar 2016 04:53:02 +0000 Subject: [SimplifyLibCalls] Only consider sinpi/cospi functions within the same function The sinpi/cospi can be replaced with sincospi to remove unnecessary computations. However, we need to make sure that the calls are within the same function! This fixes PR26993. llvm-svn: 263875 --- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp') diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 08db7ef3caa..4252cf58fef 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1625,9 +1625,9 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, IRBuilder<> &B) { // Look for all compatible sinpi, cospi and sincospi calls with the same // argument. If there are enough (in some sense) we can make the // substitution. + Function *F = CI->getFunction(); for (User *U : Arg->users()) - classifyArgUse(U, CI->getParent(), IsFloat, SinCalls, CosCalls, - SinCosCalls); + 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())) @@ -1643,16 +1643,20 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, IRBuilder<> &B) { return nullptr; } -void -LibCallSimplifier::classifyArgUse(Value *Val, BasicBlock *BB, bool IsFloat, - SmallVectorImpl &SinCalls, - SmallVectorImpl &CosCalls, - SmallVectorImpl &SinCosCalls) { +void LibCallSimplifier::classifyArgUse( + Value *Val, Function *F, bool IsFloat, + SmallVectorImpl &SinCalls, + SmallVectorImpl &CosCalls, + SmallVectorImpl &SinCosCalls) { CallInst *CI = dyn_cast(Val); if (!CI) return; + // Don't consider calls in other functions. + if (CI->getFunction() != F) + return; + Function *Callee = CI->getCalledFunction(); LibFunc::Func Func; if (!Callee || !TLI->getLibFunc(Callee->getName(), Func) || !TLI->has(Func) || -- cgit v1.2.3