[InstCombine] reduce code duplication for FP min/max with casts fold; NFC

This commit is contained in:
Sanjay Patel 2021-06-22 13:42:44 -04:00
parent bfd172999b
commit b1f6ef92ec
1 changed files with 6 additions and 13 deletions

View File

@ -1367,19 +1367,12 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
}
}
Value *ExtSrc0;
Value *ExtSrc1;
// minnum (fpext x), (fpext y) -> minnum x, y
// maxnum (fpext x), (fpext y) -> maxnum x, y
if (match(II->getArgOperand(0), m_OneUse(m_FPExt(m_Value(ExtSrc0)))) &&
match(II->getArgOperand(1), m_OneUse(m_FPExt(m_Value(ExtSrc1)))) &&
ExtSrc0->getType() == ExtSrc1->getType()) {
Function *F = Intrinsic::getDeclaration(
II->getModule(), II->getIntrinsicID(), {ExtSrc0->getType()});
CallInst *NewCall = Builder.CreateCall(F, { ExtSrc0, ExtSrc1 });
NewCall->copyFastMathFlags(II);
NewCall->takeName(II);
// m((fpext X), (fpext Y)) -> fpext (m(X, Y))
if (match(Arg0, m_OneUse(m_FPExt(m_Value(X)))) &&
match(Arg1, m_OneUse(m_FPExt(m_Value(Y)))) &&
X->getType() == Y->getType()) {
Value *NewCall =
Builder.CreateBinaryIntrinsic(IID, X, Y, II, II->getName());
return new FPExtInst(NewCall, II->getType());
}