@@ -353,23 +353,20 @@ bool GCNTTIImpl::canSimplifyLegacyMulToMul(const Instruction &I,
353
353
}
354
354
355
355
// / 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))) {
362
363
bool LosesInfo;
363
364
APFloat Val (CFP->getValueAPF ());
364
365
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);
370
368
}
371
-
372
- return false ;
369
+ return nullptr ;
373
370
}
374
371
375
372
// 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 {
839
836
if (!ST->hasMed3_16 ())
840
837
break ;
841
838
842
- Value *X, *Y, *Z;
843
-
844
839
// Repeat floating-point width reduction done for minnum/maxnum.
845
840
// 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
+ }
851
849
}
852
850
853
851
break ;
0 commit comments