Skip to content

Commit ff7eb1d

Browse files
authored
[AMDGPU] Simplify API of matchFPExtFromF16. NFC. (#108223)
1 parent 970e2c1 commit ff7eb1d

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -353,23 +353,20 @@ bool GCNTTIImpl::canSimplifyLegacyMulToMul(const Instruction &I,
353353
}
354354

355355
/// Match an fpext from half to float, or a constant we can convert.
356-
static bool matchFPExtFromF16(Value *Arg, Value *&FPExtSrc) {
357-
if (match(Arg, m_OneUse(m_FPExt(m_Value(FPExtSrc)))))
358-
return FPExtSrc->getType()->isHalfTy();
359-
360-
ConstantFP *CFP;
361-
if (match(Arg, m_ConstantFP(CFP))) {
356+
static Value *matchFPExtFromF16(Value *Arg) {
357+
Value *Src = nullptr;
358+
ConstantFP *CFP = nullptr;
359+
if (match(Arg, m_OneUse(m_FPExt(m_Value(Src))))) {
360+
if (Src->getType()->isHalfTy())
361+
return Src;
362+
} else if (match(Arg, m_ConstantFP(CFP))) {
362363
bool LosesInfo;
363364
APFloat Val(CFP->getValueAPF());
364365
Val.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &LosesInfo);
365-
if (LosesInfo)
366-
return false;
367-
368-
FPExtSrc = ConstantFP::get(Type::getHalfTy(Arg->getContext()), Val);
369-
return true;
366+
if (!LosesInfo)
367+
return ConstantFP::get(Type::getHalfTy(Arg->getContext()), Val);
370368
}
371-
372-
return false;
369+
return nullptr;
373370
}
374371

375372
// Trim all zero components from the end of the vector \p UseV and return
@@ -839,15 +836,16 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
839836
if (!ST->hasMed3_16())
840837
break;
841838

842-
Value *X, *Y, *Z;
843-
844839
// Repeat floating-point width reduction done for minnum/maxnum.
845840
// fmed3((fpext X), (fpext Y), (fpext Z)) -> fpext (fmed3(X, Y, Z))
846-
if (matchFPExtFromF16(Src0, X) && matchFPExtFromF16(Src1, Y) &&
847-
matchFPExtFromF16(Src2, Z)) {
848-
Value *NewCall = IC.Builder.CreateIntrinsic(IID, {X->getType()},
849-
{X, Y, Z}, &II, II.getName());
850-
return new FPExtInst(NewCall, II.getType());
841+
if (Value *X = matchFPExtFromF16(Src0)) {
842+
if (Value *Y = matchFPExtFromF16(Src1)) {
843+
if (Value *Z = matchFPExtFromF16(Src2)) {
844+
Value *NewCall = IC.Builder.CreateIntrinsic(
845+
IID, {X->getType()}, {X, Y, Z}, &II, II.getName());
846+
return new FPExtInst(NewCall, II.getType());
847+
}
848+
}
851849
}
852850

853851
break;

0 commit comments

Comments
 (0)