Args.push_back(II->getArgOperand(0));
Args.push_back(Builder.CreateFNegFMF(II->getArgOperand(1), &I));
break;
+ case Intrinsic::powi:
+ // Require 'ninf' assuming that makes powi(X, -INT_MIN) acceptable.
+ // That is, X ** (huge negative number) is 0.0, ~1.0, or INF and so
+ // dividing by that is INF, ~1.0, or 0.0. Code that uses powi allows
+ // non-standard results, so this corner case should be acceptable if the
+ // code rules out INF values.
+ if (!I.hasNoInfs())
+ return nullptr;
+ Args.push_back(II->getArgOperand(0));
+ Args.push_back(Builder.CreateNeg(II->getArgOperand(1)));
+ break;
case Intrinsic::exp:
case Intrinsic::exp2:
Args.push_back(Builder.CreateFNegFMF(II->getArgOperand(0), &I));
define float @powi_divisor(float %x, i32 %y, float %z) {
; CHECK-LABEL: @powi_divisor(
-; CHECK-NEXT: [[P:%.*]] = call float @llvm.powi.f32(float [[X:%.*]], i32 [[Y:%.*]])
-; CHECK-NEXT: [[R:%.*]] = fdiv reassoc ninf arcp float [[Z:%.*]], [[P]]
+; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[Y:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = call reassoc ninf arcp float @llvm.powi.f32(float [[X:%.*]], i32 [[TMP1]])
+; CHECK-NEXT: [[R:%.*]] = fmul reassoc ninf arcp float [[TMP2]], [[Z:%.*]]
; CHECK-NEXT: ret float [[R]]
;
%p = call float @llvm.powi.f32(float %x, i32 %y)
define <2 x half> @powi_recip(<2 x half> %x, i32 %y) {
; CHECK-LABEL: @powi_recip(
-; CHECK-NEXT: [[P:%.*]] = call <2 x half> @llvm.powi.v2f16(<2 x half> [[X:%.*]], i32 [[Y:%.*]])
-; CHECK-NEXT: [[R:%.*]] = fdiv reassoc nnan ninf arcp <2 x half> <half 0xH3C00, half 0xH3C00>, [[P]]
-; CHECK-NEXT: ret <2 x half> [[R]]
+; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[Y:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = call reassoc nnan ninf arcp <2 x half> @llvm.powi.v2f16(<2 x half> [[X:%.*]], i32 [[TMP1]])
+; CHECK-NEXT: ret <2 x half> [[TMP2]]
;
%p = call <2 x half> @llvm.powi.v2f16(<2 x half> %x, i32 %y)
%r = fdiv reassoc arcp nnan ninf <2 x half> <half 1.0, half 1.0>, %p