Skip to content

Commit fbca27b

Browse files
committed
[InstCombine] add tests for fdiv of exp/exp2; NFC
1 parent b6088f7 commit fbca27b

File tree

1 file changed

+134
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+134
-0
lines changed

llvm/test/Transforms/InstCombine/fdiv.ll

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
declare float @llvm.fabs.f32(float) nounwind readnone
55
declare float @llvm.pow.f32(float, float) nounwind readnone
66
declare <2 x half> @llvm.pow.v2f16(<2 x half>, <2 x half>) nounwind readnone
7+
declare float @llvm.exp.f32(float) nounwind readnone
8+
declare <2 x half> @llvm.exp.v2f16(<2 x half>) nounwind readnone
9+
declare float @llvm.exp2.f32(float) nounwind readnone
10+
declare <2 x half> @llvm.exp2.v2f16(<2 x half>) nounwind readnone
711

812
define float @exact_inverse(float %x) {
913
; CHECK-LABEL: @exact_inverse(
@@ -724,3 +728,133 @@ define <2 x half> @pow_recip(<2 x half> %x, <2 x half> %y) {
724728
%r = fdiv reassoc arcp ninf <2 x half> <half 1.0, half 1.0>, %p
725729
ret <2 x half> %r
726730
}
731+
732+
define float @exp_divisor(float %y, float %z) {
733+
; CHECK-LABEL: @exp_divisor(
734+
; CHECK-NEXT: [[P:%.*]] = call float @llvm.exp.f32(float [[Y:%.*]])
735+
; CHECK-NEXT: [[R:%.*]] = fdiv reassoc arcp float [[Z:%.*]], [[P]]
736+
; CHECK-NEXT: ret float [[R]]
737+
;
738+
%p = call float @llvm.exp.f32(float %y)
739+
%r = fdiv reassoc arcp float %z, %p
740+
ret float %r
741+
}
742+
743+
; Negative test - don't create an extra exp
744+
745+
define float @exp_divisor_extra_use(float %y, float %z) {
746+
; CHECK-LABEL: @exp_divisor_extra_use(
747+
; CHECK-NEXT: [[P:%.*]] = call float @llvm.exp.f32(float [[Y:%.*]])
748+
; CHECK-NEXT: call void @use_f32(float [[P]])
749+
; CHECK-NEXT: [[R:%.*]] = fdiv reassoc arcp float [[Z:%.*]], [[P]]
750+
; CHECK-NEXT: ret float [[R]]
751+
;
752+
%p = call float @llvm.exp.f32(float %y)
753+
call void @use_f32(float %p)
754+
%r = fdiv reassoc arcp float %z, %p
755+
ret float %r
756+
}
757+
758+
; Negative test - must have reassoc+arcp
759+
760+
define float @exp_divisor_not_enough_fmf(float %y, float %z) {
761+
; CHECK-LABEL: @exp_divisor_not_enough_fmf(
762+
; CHECK-NEXT: [[P:%.*]] = call fast float @llvm.exp.f32(float [[Y:%.*]])
763+
; CHECK-NEXT: [[R:%.*]] = fdiv reassoc float [[Z:%.*]], [[P]]
764+
; CHECK-NEXT: ret float [[R]]
765+
;
766+
%p = call fast float @llvm.exp.f32(float %y)
767+
%r = fdiv reassoc float %z, %p
768+
ret float %r
769+
}
770+
771+
; Negative test - must have reassoc+arcp
772+
773+
define float @exp_divisor_not_enough_fmf2(float %y, float %z) {
774+
; CHECK-LABEL: @exp_divisor_not_enough_fmf2(
775+
; CHECK-NEXT: [[P:%.*]] = call fast float @llvm.exp.f32(float [[Y:%.*]])
776+
; CHECK-NEXT: [[R:%.*]] = fdiv arcp float [[Z:%.*]], [[P]]
777+
; CHECK-NEXT: ret float [[R]]
778+
;
779+
%p = call fast float @llvm.exp.f32(float %y)
780+
%r = fdiv arcp float %z, %p
781+
ret float %r
782+
}
783+
784+
; Special-case - reciprocal does not require extra fmul
785+
786+
define <2 x half> @exp_recip(<2 x half> %x, <2 x half> %y) {
787+
; CHECK-LABEL: @exp_recip(
788+
; CHECK-NEXT: [[P:%.*]] = call <2 x half> @llvm.exp.v2f16(<2 x half> [[Y:%.*]])
789+
; CHECK-NEXT: [[R:%.*]] = fdiv reassoc ninf arcp <2 x half> <half 0xH3C00, half 0xH3C00>, [[P]]
790+
; CHECK-NEXT: ret <2 x half> [[R]]
791+
;
792+
%p = call <2 x half> @llvm.exp.v2f16(<2 x half> %y)
793+
%r = fdiv reassoc arcp ninf <2 x half> <half 1.0, half 1.0>, %p
794+
ret <2 x half> %r
795+
}
796+
797+
define float @exp2_divisor(float %y, float %z) {
798+
; CHECK-LABEL: @exp2_divisor(
799+
; CHECK-NEXT: [[P:%.*]] = call float @llvm.exp2.f32(float [[Y:%.*]])
800+
; CHECK-NEXT: [[R:%.*]] = fdiv reassoc arcp float [[Z:%.*]], [[P]]
801+
; CHECK-NEXT: ret float [[R]]
802+
;
803+
%p = call float @llvm.exp2.f32(float %y)
804+
%r = fdiv reassoc arcp float %z, %p
805+
ret float %r
806+
}
807+
808+
; Negative test - don't create an extra exp
809+
810+
define float @exp2_divisor_extra_use(float %y, float %z) {
811+
; CHECK-LABEL: @exp2_divisor_extra_use(
812+
; CHECK-NEXT: [[P:%.*]] = call float @llvm.exp2.f32(float [[Y:%.*]])
813+
; CHECK-NEXT: call void @use_f32(float [[P]])
814+
; CHECK-NEXT: [[R:%.*]] = fdiv reassoc arcp float [[Z:%.*]], [[P]]
815+
; CHECK-NEXT: ret float [[R]]
816+
;
817+
%p = call float @llvm.exp2.f32(float %y)
818+
call void @use_f32(float %p)
819+
%r = fdiv reassoc arcp float %z, %p
820+
ret float %r
821+
}
822+
823+
; Negative test - must have reassoc+arcp
824+
825+
define float @exp2_divisor_not_enough_fmf(float %y, float %z) {
826+
; CHECK-LABEL: @exp2_divisor_not_enough_fmf(
827+
; CHECK-NEXT: [[P:%.*]] = call fast float @llvm.exp2.f32(float [[Y:%.*]])
828+
; CHECK-NEXT: [[R:%.*]] = fdiv reassoc float [[Z:%.*]], [[P]]
829+
; CHECK-NEXT: ret float [[R]]
830+
;
831+
%p = call fast float @llvm.exp2.f32(float %y)
832+
%r = fdiv reassoc float %z, %p
833+
ret float %r
834+
}
835+
836+
; Negative test - must have reassoc+arcp
837+
838+
define float @exp2_divisor_not_enough_fmf2(float %y, float %z) {
839+
; CHECK-LABEL: @exp2_divisor_not_enough_fmf2(
840+
; CHECK-NEXT: [[P:%.*]] = call fast float @llvm.exp2.f32(float [[Y:%.*]])
841+
; CHECK-NEXT: [[R:%.*]] = fdiv arcp float [[Z:%.*]], [[P]]
842+
; CHECK-NEXT: ret float [[R]]
843+
;
844+
%p = call fast float @llvm.exp2.f32(float %y)
845+
%r = fdiv arcp float %z, %p
846+
ret float %r
847+
}
848+
849+
; Special-case - reciprocal does not require extra fmul
850+
851+
define <2 x half> @exp2_recip(<2 x half> %x, <2 x half> %y) {
852+
; CHECK-LABEL: @exp2_recip(
853+
; CHECK-NEXT: [[P:%.*]] = call <2 x half> @llvm.exp2.v2f16(<2 x half> [[Y:%.*]])
854+
; CHECK-NEXT: [[R:%.*]] = fdiv reassoc ninf arcp <2 x half> <half 0xH3C00, half 0xH3C00>, [[P]]
855+
; CHECK-NEXT: ret <2 x half> [[R]]
856+
;
857+
%p = call <2 x half> @llvm.exp2.v2f16(<2 x half> %y)
858+
%r = fdiv reassoc arcp ninf <2 x half> <half 1.0, half 1.0>, %p
859+
ret <2 x half> %r
860+
}

0 commit comments

Comments
 (0)