Skip to content

Commit

Permalink
[InstCombine] add tests for fdiv+powi; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Feb 24, 2021
1 parent 589223e commit 3475159
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions llvm/test/Transforms/InstCombine/fdiv.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}

0 comments on commit 3475159

Please sign in to comment.