[llvm] [InstCombine] Optimize `sinh` and `cosh` divivsions (PR #81433)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 05:21:48 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 4fb7b3301bfbd439eb3d30d6a36c7cdb26941a0d 7c352a0d20331a5f138c7cdf8c63fdfeaf455db0 -- llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 333c9368a4..7b498d5c8a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -224,7 +224,8 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
Value *NewOp;
Constant *C1, *C2;
const APInt *IVal;
- if (match(&I, m_Mul(m_Shl(m_Value(NewOp), m_Constant(C2)), m_Constant(C1))) &&
+ if (match(&I,
+ m_Mul(m_Shl(m_Value(NewOp), m_Constant(C2)), m_Constant(C1))) &&
match(C1, m_APInt(IVal))) {
// ((X << C2)*C1) == (X * (C1 << C2))
Constant *Shl = ConstantExpr::getShl(C1, C2);
@@ -410,9 +411,8 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
// 2) X * Y --> X & Y, iff X, Y can be only {0,1}.
// Note: We could use known bits to generalize this and related patterns with
// shifts/truncs
- if (Ty->isIntOrIntVectorTy(1) ||
- (match(Op0, m_And(m_Value(), m_One())) &&
- match(Op1, m_And(m_Value(), m_One()))))
+ if (Ty->isIntOrIntVectorTy(1) || (match(Op0, m_And(m_Value(), m_One())) &&
+ match(Op1, m_And(m_Value(), m_One()))))
return BinaryOperator::CreateAnd(Op0, Op1);
if (Value *R = foldMulShl1(I, /* CommuteOperands */ false, Builder))
@@ -748,8 +748,7 @@ Instruction *InstCombinerImpl::foldFMulReassoc(BinaryOperator &I) {
Instruction *InstCombinerImpl::visitFMul(BinaryOperator &I) {
if (Value *V =
simplifyFMulInst(I.getOperand(0), I.getOperand(1),
- I.getFastMathFlags(),
- SQ.getWithInstruction(&I)))
+ I.getFastMathFlags(), SQ.getWithInstruction(&I)))
return replaceInstUsesWith(I, V);
if (SimplifyAssociativeOrCommutative(I))
@@ -1305,8 +1304,8 @@ static Value *takeLog2(IRBuilderBase &Builder, Value *Op, unsigned Depth,
// FIXME: can both hands contain undef?
// FIXME: Require one use?
if (SelectInst *SI = dyn_cast<SelectInst>(Op))
- if (Value *LogX = takeLog2(Builder, SI->getOperand(1), Depth,
- AssumeNonZero, DoFold))
+ if (Value *LogX =
+ takeLog2(Builder, SI->getOperand(1), Depth, AssumeNonZero, DoFold))
if (Value *LogY = takeLog2(Builder, SI->getOperand(2), Depth,
AssumeNonZero, DoFold))
return IfFold([&]() {
@@ -1713,9 +1712,9 @@ static Instruction *foldFDivPowDivisor(BinaryOperator &I,
Instruction *InstCombinerImpl::visitFDiv(BinaryOperator &I) {
Module *M = I.getModule();
- if (Value *V = simplifyFDivInst(I.getOperand(0), I.getOperand(1),
- I.getFastMathFlags(),
- SQ.getWithInstruction(&I)))
+ if (Value *V =
+ simplifyFDivInst(I.getOperand(0), I.getOperand(1),
+ I.getFastMathFlags(), SQ.getWithInstruction(&I)))
return replaceInstUsesWith(I, V);
if (Instruction *X = foldVectorBinop(I))
@@ -1819,15 +1818,17 @@ Instruction *InstCombinerImpl::visitFDiv(BinaryOperator &I) {
bool ArgsMatch = match(Op0AsCallBase->getArgOperand(0), m_Value(Y)) &&
match(Op1AsCallBase->getArgOperand(0), m_Specific(Y));
- bool IsTanH = ArgsMatch &&
- ((Op0LibFunc == LibFunc_sinh && Op1LibFunc == LibFunc_cosh) ||
- (Op0LibFunc == LibFunc_sinhf && Op1LibFunc == LibFunc_coshf) ||
- (Op0LibFunc == LibFunc_sinhl && Op1LibFunc == LibFunc_coshl));
+ bool IsTanH =
+ ArgsMatch &&
+ ((Op0LibFunc == LibFunc_sinh && Op1LibFunc == LibFunc_cosh) ||
+ (Op0LibFunc == LibFunc_sinhf && Op1LibFunc == LibFunc_coshf) ||
+ (Op0LibFunc == LibFunc_sinhl && Op1LibFunc == LibFunc_coshl));
- bool IsCotH = !IsTanH && ArgsMatch &&
- ((Op1LibFunc == LibFunc_sinh && Op0LibFunc == LibFunc_cosh) ||
- (Op1LibFunc == LibFunc_sinhf && Op0LibFunc == LibFunc_coshf) ||
- (Op1LibFunc == LibFunc_sinhl && Op0LibFunc == LibFunc_coshl));
+ bool IsCotH =
+ !IsTanH && ArgsMatch &&
+ ((Op1LibFunc == LibFunc_sinh && Op0LibFunc == LibFunc_cosh) ||
+ (Op1LibFunc == LibFunc_sinhf && Op0LibFunc == LibFunc_coshf) ||
+ (Op1LibFunc == LibFunc_sinhl && Op0LibFunc == LibFunc_coshl));
if ((IsTanH || IsCotH) && hasFloatFn(M, &TLI, I.getType(), LibFunc_tanh,
LibFunc_tanhf, LibFunc_tanhl)) {
@@ -1835,7 +1836,7 @@ Instruction *InstCombinerImpl::visitFDiv(BinaryOperator &I) {
Value *Res =
GetReplacement(Y, IsCotH, LibFunc_tanh, LibFunc_tanf, LibFunc_tanl);
- Instruction *Replacement = replaceInstUsesWith(I,Res);
+ Instruction *Replacement = replaceInstUsesWith(I, Res);
// Call instructions of sinh and cosh need to be erased seperatly
if (!Op0AsCallBase->use_empty())
@@ -1879,9 +1880,8 @@ Instruction *InstCombinerImpl::visitFDiv(BinaryOperator &I) {
return Mul;
// pow(X, Y) / X --> pow(X, Y-1)
- if (I.hasAllowReassoc() &&
- match(Op0, m_OneUse(m_Intrinsic<Intrinsic::pow>(
- m_Specific(Op1), m_Value(Y))))) {
+ if (I.hasAllowReassoc() && match(Op0, m_OneUse(m_Intrinsic<Intrinsic::pow>(
+ m_Specific(Op1), m_Value(Y))))) {
Value *Y1 =
Builder.CreateFAddFMF(Y, ConstantFP::get(I.getType(), -1.0), &I);
Value *Pow = Builder.CreateBinaryIntrinsic(Intrinsic::pow, Op1, Y1, &I);
@@ -2210,8 +2210,7 @@ Instruction *InstCombinerImpl::visitSRem(BinaryOperator &I) {
Instruction *InstCombinerImpl::visitFRem(BinaryOperator &I) {
if (Value *V =
simplifyFRemInst(I.getOperand(0), I.getOperand(1),
- I.getFastMathFlags(),
- SQ.getWithInstruction(&I)))
+ I.getFastMathFlags(), SQ.getWithInstruction(&I)))
return replaceInstUsesWith(I, V);
if (Instruction *X = foldVectorBinop(I))
``````````
</details>
https://github.com/llvm/llvm-project/pull/81433
More information about the llvm-commits
mailing list