[llvm] 3475159 - [InstCombine] add tests for fdiv+powi; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 12:08:07 PST 2021


Author: Sanjay Patel
Date: 2021-02-24T15:08:00-05:00
New Revision: 3475159122b656ff098e2f44af32dc56f3beb610

URL: https://github.com/llvm/llvm-project/commit/3475159122b656ff098e2f44af32dc56f3beb610
DIFF: https://github.com/llvm/llvm-project/commit/3475159122b656ff098e2f44af32dc56f3beb610.diff

LOG: [InstCombine] add tests for fdiv+powi; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/fdiv.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/fdiv.ll b/llvm/test/Transforms/InstCombine/fdiv.ll
index 6ccbefaf8202..0028bf60b842 100644
--- a/llvm/test/Transforms/InstCombine/fdiv.ll
+++ b/llvm/test/Transforms/InstCombine/fdiv.ll
@@ -8,6 +8,8 @@ declare float @llvm.exp.f32(float) nounwind readnone
 declare <2 x half> @llvm.exp.v2f16(<2 x half>) nounwind readnone
 declare float @llvm.exp2.f32(float) nounwind readnone
 declare <2 x half> @llvm.exp2.v2f16(<2 x half>) nounwind readnone
+declare float @llvm.powi.f32(float, i32) nounwind readnone
+declare <2 x half> @llvm.powi.v2f16(<2 x half>, i32) nounwind readnone
 
 define float @exact_inverse(float %x) {
 ; CHECK-LABEL: @exact_inverse(
@@ -860,3 +862,68 @@ define <2 x half> @exp2_recip(<2 x half> %x, <2 x half> %y) {
   %r = fdiv reassoc arcp ninf <2 x half> <half 1.0, half 1.0>, %p
   ret <2 x half> %r
 }
+
+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:    ret float [[R]]
+;
+  %p = call float @llvm.powi.f32(float %x, i32 %y)
+  %r = fdiv reassoc arcp ninf float %z, %p
+  ret float %r
+}
+
+; Negative test - don't create an extra pow
+
+define float @powi_divisor_extra_use(float %x, i32 %y, float %z) {
+; CHECK-LABEL: @powi_divisor_extra_use(
+; CHECK-NEXT:    [[P:%.*]] = call float @llvm.powi.f32(float [[X:%.*]], i32 [[Y:%.*]])
+; CHECK-NEXT:    call void @use_f32(float [[P]])
+; CHECK-NEXT:    [[R:%.*]] = fdiv reassoc ninf arcp float [[Z:%.*]], [[P]]
+; CHECK-NEXT:    ret float [[R]]
+;
+  %p = call float @llvm.powi.f32(float %x, i32 %y)
+  call void @use_f32(float %p)
+  %r = fdiv reassoc arcp ninf float %z, %p
+  ret float %r
+}
+
+; Negative test - must have reassoc+arcp+ninf
+
+define float @powi_divisor_not_enough_fmf(float %x, i32 %y, float %z) {
+; CHECK-LABEL: @powi_divisor_not_enough_fmf(
+; CHECK-NEXT:    [[P:%.*]] = call fast float @llvm.powi.f32(float [[X:%.*]], i32 [[Y:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fdiv reassoc ninf float [[Z:%.*]], [[P]]
+; CHECK-NEXT:    ret float [[R]]
+;
+  %p = call fast float @llvm.powi.f32(float %x, i32 %y)
+  %r = fdiv reassoc ninf float %z, %p
+  ret float %r
+}
+
+; Negative test - must have reassoc+arcp+ninf
+
+define float @powi_divisor_not_enough_fmf2(float %x, i32 %y, float %z) {
+; CHECK-LABEL: @powi_divisor_not_enough_fmf2(
+; CHECK-NEXT:    [[P:%.*]] = call fast float @llvm.powi.f32(float [[X:%.*]], i32 [[Y:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fdiv ninf arcp float [[Z:%.*]], [[P]]
+; CHECK-NEXT:    ret float [[R]]
+;
+  %p = call fast float @llvm.powi.f32(float %x, i32 %y)
+  %r = fdiv arcp ninf float %z, %p
+  ret float %r
+}
+
+; Special-case - reciprocal does not require extra fmul
+
+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]]
+;
+  %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
+  ret <2 x half> %r
+}


        


More information about the llvm-commits mailing list