mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
[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
This commit is contained in:
parent
2669789037
commit
ab6aef2bdd
@ -154,7 +154,7 @@ private:
|
|||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
Value *emitStrLenMemCpy(Value *Src, Value *Dst, uint64_t Len, IRBuilder<> &B);
|
Value *emitStrLenMemCpy(Value *Src, Value *Dst, uint64_t Len, IRBuilder<> &B);
|
||||||
void classifyArgUse(Value *Val, BasicBlock *BB, bool IsFloat,
|
void classifyArgUse(Value *Val, Function *F, bool IsFloat,
|
||||||
SmallVectorImpl<CallInst *> &SinCalls,
|
SmallVectorImpl<CallInst *> &SinCalls,
|
||||||
SmallVectorImpl<CallInst *> &CosCalls,
|
SmallVectorImpl<CallInst *> &CosCalls,
|
||||||
SmallVectorImpl<CallInst *> &SinCosCalls);
|
SmallVectorImpl<CallInst *> &SinCosCalls);
|
||||||
|
@ -1625,9 +1625,9 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, IRBuilder<> &B) {
|
|||||||
// Look for all compatible sinpi, cospi and sincospi calls with the same
|
// Look for all compatible sinpi, cospi and sincospi calls with the same
|
||||||
// argument. If there are enough (in some sense) we can make the
|
// argument. If there are enough (in some sense) we can make the
|
||||||
// substitution.
|
// substitution.
|
||||||
|
Function *F = CI->getFunction();
|
||||||
for (User *U : Arg->users())
|
for (User *U : Arg->users())
|
||||||
classifyArgUse(U, CI->getParent(), IsFloat, SinCalls, CosCalls,
|
classifyArgUse(U, F, IsFloat, SinCalls, CosCalls, SinCosCalls);
|
||||||
SinCosCalls);
|
|
||||||
|
|
||||||
// It's only worthwhile if both sinpi and cospi are actually used.
|
// It's only worthwhile if both sinpi and cospi are actually used.
|
||||||
if (SinCosCalls.empty() && (SinCalls.empty() || CosCalls.empty()))
|
if (SinCosCalls.empty() && (SinCalls.empty() || CosCalls.empty()))
|
||||||
@ -1643,16 +1643,20 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, IRBuilder<> &B) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void LibCallSimplifier::classifyArgUse(
|
||||||
LibCallSimplifier::classifyArgUse(Value *Val, BasicBlock *BB, bool IsFloat,
|
Value *Val, Function *F, bool IsFloat,
|
||||||
SmallVectorImpl<CallInst *> &SinCalls,
|
SmallVectorImpl<CallInst *> &SinCalls,
|
||||||
SmallVectorImpl<CallInst *> &CosCalls,
|
SmallVectorImpl<CallInst *> &CosCalls,
|
||||||
SmallVectorImpl<CallInst *> &SinCosCalls) {
|
SmallVectorImpl<CallInst *> &SinCosCalls) {
|
||||||
CallInst *CI = dyn_cast<CallInst>(Val);
|
CallInst *CI = dyn_cast<CallInst>(Val);
|
||||||
|
|
||||||
if (!CI)
|
if (!CI)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Don't consider calls in other functions.
|
||||||
|
if (CI->getFunction() != F)
|
||||||
|
return;
|
||||||
|
|
||||||
Function *Callee = CI->getCalledFunction();
|
Function *Callee = CI->getCalledFunction();
|
||||||
LibFunc::Func Func;
|
LibFunc::Func Func;
|
||||||
if (!Callee || !TLI->getLibFunc(Callee->getName(), Func) || !TLI->has(Func) ||
|
if (!Callee || !TLI->getLibFunc(Callee->getName(), Func) || !TLI->has(Func) ||
|
||||||
|
24
test/Transforms/InstCombine/pr26993.ll
Normal file
24
test/Transforms/InstCombine/pr26993.ll
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
; RUN: opt -instcombine -S < %s | FileCheck %s
|
||||||
|
|
||||||
|
define double @test1() {
|
||||||
|
%sin = call double @__sinpi(double 1.0)
|
||||||
|
ret double %sin
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: define double @test1(
|
||||||
|
; CHECK: %[[sin:.*]] = call double @__sinpi(double 1.000000e+00)
|
||||||
|
; CHECK-NEXT: ret double %[[sin]]
|
||||||
|
|
||||||
|
define double @test2() {
|
||||||
|
%cos = call double @__cospi(double 1.0)
|
||||||
|
ret double %cos
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: define double @test2(
|
||||||
|
; CHECK: %[[cos:.*]] = call double @__cospi(double 1.000000e+00)
|
||||||
|
; CHECK-NEXT: ret double %[[cos]]
|
||||||
|
|
||||||
|
declare double @__sinpi(double %x) #0
|
||||||
|
declare double @__cospi(double %x) #0
|
||||||
|
|
||||||
|
attributes #0 = { readnone nounwind }
|
Loading…
Reference in New Issue
Block a user