[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; // m((fpext X), (fpext Y)) -> fpext (m(X, Y))
Value *ExtSrc1; if (match(Arg0, m_OneUse(m_FPExt(m_Value(X)))) &&
match(Arg1, m_OneUse(m_FPExt(m_Value(Y)))) &&
// minnum (fpext x), (fpext y) -> minnum x, y X->getType() == Y->getType()) {
// maxnum (fpext x), (fpext y) -> maxnum x, y Value *NewCall =
if (match(II->getArgOperand(0), m_OneUse(m_FPExt(m_Value(ExtSrc0)))) && Builder.CreateBinaryIntrinsic(IID, X, Y, II, II->getName());
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);
return new FPExtInst(NewCall, II->getType()); return new FPExtInst(NewCall, II->getType());
} }