diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-08-07 14:36:27 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-08-07 14:36:27 +0000 |
commit | 948ff87d7de80ba0e959c322f19aa928c4ae7ad4 (patch) | |
tree | 29bd3710c8bdb0e242c201412a78ce7eabf487d3 /llvm/lib | |
parent | e03993e6c73d8992f7d9c435ccd25a69f259316f (diff) | |
download | bcm5719-llvm-948ff87d7de80ba0e959c322f19aa928c4ae7ad4.tar.gz bcm5719-llvm-948ff87d7de80ba0e959c322f19aa928c4ae7ad4.zip |
[InstSimplify] move minnum/maxnum with common op fold from instcombine
llvm-svn: 339144
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 30 |
2 files changed, 11 insertions, 30 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 494ca656dba..02137a51844 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4805,6 +4805,17 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1, if (match(Op0, m_CombineOr(m_NaN(), m_Undef()))) return Op1; if (match(Op1, m_CombineOr(m_NaN(), m_Undef()))) return Op0; + // Min/max of the same operation with common operand: + // m(m(X, Y)), X --> m(X, Y) (4 commuted variants) + if (auto *M0 = dyn_cast<IntrinsicInst>(Op0)) + if (M0->getIntrinsicID() == IID && + (M0->getOperand(0) == Op1 || M0->getOperand(1) == Op1)) + return Op0; + if (auto *M1 = dyn_cast<IntrinsicInst>(Op1)) + if (M1->getIntrinsicID() == IID && + (M1->getOperand(0) == Op0 || M1->getOperand(1) == Op0)) + return Op1; + break; default: break; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 748cb97d9b5..dcd080e3305 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1143,23 +1143,7 @@ static Value *simplifyMinnumMaxnum(const IntrinsicInst &II) { if (C1 && C1->isNaN()) return Arg0; - Value *X = nullptr; - Value *Y = nullptr; if (II.getIntrinsicID() == Intrinsic::minnum) { - // fmin(x, fmin(x, y)) -> fmin(x, y) - // fmin(y, fmin(x, y)) -> fmin(x, y) - if (match(Arg1, m_FMin(m_Value(X), m_Value(Y)))) { - if (Arg0 == X || Arg0 == Y) - return Arg1; - } - - // fmin(fmin(x, y), x) -> fmin(x, y) - // fmin(fmin(x, y), y) -> fmin(x, y) - if (match(Arg0, m_FMin(m_Value(X), m_Value(Y)))) { - if (Arg1 == X || Arg1 == Y) - return Arg0; - } - // TODO: fmin(nnan x, inf) -> x // TODO: fmin(nnan ninf x, flt_max) -> x if (C1 && C1->isInfinity()) { @@ -1169,20 +1153,6 @@ static Value *simplifyMinnumMaxnum(const IntrinsicInst &II) { } } else { assert(II.getIntrinsicID() == Intrinsic::maxnum); - // fmax(x, fmax(x, y)) -> fmax(x, y) - // fmax(y, fmax(x, y)) -> fmax(x, y) - if (match(Arg1, m_FMax(m_Value(X), m_Value(Y)))) { - if (Arg0 == X || Arg0 == Y) - return Arg1; - } - - // fmax(fmax(x, y), x) -> fmax(x, y) - // fmax(fmax(x, y), y) -> fmax(x, y) - if (match(Arg0, m_FMax(m_Value(X), m_Value(Y)))) { - if (Arg1 == X || Arg1 == Y) - return Arg0; - } - // TODO: fmax(nnan x, -inf) -> x // TODO: fmax(nnan ninf x, -flt_max) -> x if (C1 && C1->isInfinity()) { |