Skip to content

Commit 35af1a9

Browse files
committed
[Transforms] Add cos(fabs(x)) -> cos(x) to SimplifyLibCalls
We have this for InstCombine, but forgot to add it for SimplifyLibCalls.
1 parent e976053 commit 35af1a9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,8 +2491,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
24912491
Value *X;
24922492
Value *Src = II->getArgOperand(0);
24932493
if (match(Src, m_FNeg(m_Value(X))) || match(Src, m_FAbs(m_Value(X)))) {
2494-
// cos(-x) -> cos(x)
2495-
// cos(fabs(x)) -> cos(x)
2494+
// cos(-x) --> cos(x)
2495+
// cos(fabs(x)) --> cos(x)
24962496
return replaceOperand(*II, 0, X);
24972497
}
24982498
break;

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,8 +1934,10 @@ static Value *optimizeTrigReflections(CallInst *Call, LibFunc Func,
19341934
case LibFunc_cos:
19351935
case LibFunc_cosf:
19361936
case LibFunc_cosl:
1937-
// cos(-X) --> cos(X)
1938-
if (match(Call->getArgOperand(0), m_FNeg(m_Value(X))))
1937+
// cos(-x) --> cos(x)
1938+
// cos(fabs(x)) --> cos(x)
1939+
if (match(Call->getArgOperand(0), m_FNeg(m_Value(X))) ||
1940+
match(Call->getArgOperand(0), m_FAbs(m_Value(X))))
19391941
return copyFlags(*Call,
19401942
B.CreateCall(Call->getCalledFunction(), X, "cos"));
19411943
break;

0 commit comments

Comments
 (0)