@@ -2754,27 +2754,28 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
2754
2754
((Mask & fcPosInf) && Op1V.isPosInfinity ());
2755
2755
return ConstantInt::get (Ty, Result);
2756
2756
}
2757
+ case Intrinsic::powi: {
2758
+ int Exp = static_cast <int >(Op2C->getSExtValue ());
2759
+ switch (Ty->getTypeID ()) {
2760
+ case Type::HalfTyID:
2761
+ case Type::FloatTyID: {
2762
+ APFloat Res (std::pow (Op1V.convertToFloat (), Exp));
2763
+ if (Ty->isHalfTy ()) {
2764
+ bool Unused;
2765
+ Res.convert (APFloat::IEEEhalf (), APFloat::rmNearestTiesToEven,
2766
+ &Unused);
2767
+ }
2768
+ return ConstantFP::get (Ty->getContext (), Res);
2769
+ }
2770
+ case Type::DoubleTyID:
2771
+ return ConstantFP::get (Ty, std::pow (Op1V.convertToDouble (), Exp));
2772
+ default :
2773
+ return nullptr ;
2774
+ }
2775
+ }
2757
2776
default :
2758
2777
break ;
2759
2778
}
2760
-
2761
- if (!Ty->isHalfTy () && !Ty->isFloatTy () && !Ty->isDoubleTy ())
2762
- return nullptr ;
2763
- if (IntrinsicID == Intrinsic::powi && Ty->isHalfTy ())
2764
- return ConstantFP::get (
2765
- Ty->getContext (),
2766
- APFloat ((float )std::pow ((float )Op1V.convertToDouble (),
2767
- (int )Op2C->getZExtValue ())));
2768
- if (IntrinsicID == Intrinsic::powi && Ty->isFloatTy ())
2769
- return ConstantFP::get (
2770
- Ty->getContext (),
2771
- APFloat ((float )std::pow ((float )Op1V.convertToDouble (),
2772
- (int )Op2C->getZExtValue ())));
2773
- if (IntrinsicID == Intrinsic::powi && Ty->isDoubleTy ())
2774
- return ConstantFP::get (
2775
- Ty->getContext (),
2776
- APFloat ((double )std::pow (Op1V.convertToDouble (),
2777
- (int )Op2C->getZExtValue ())));
2778
2779
}
2779
2780
return nullptr ;
2780
2781
}
0 commit comments