Skip to content

Commit b789ae0

Browse files
committed
ValueTracking: Add tests for fneg/fabs computeKnownFPClass
1 parent 6966859 commit b789ae0

File tree

1 file changed

+305
-0
lines changed

1 file changed

+305
-0
lines changed

llvm/test/Transforms/Attributor/nofpclass.ll

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare void @extern.use.array([2 x [3 x float]])
1010
declare void @llvm.assume(i1 noundef)
1111
declare void @unknown()
1212
declare half @llvm.fabs.f16(half)
13+
declare float @llvm.fabs.f32(float)
1314
declare void @extern.use.f16(half)
1415
declare i1 @llvm.is.fpclass.f32(float, i32 immarg)
1516
declare float @llvm.experimental.constrained.sitofp.f32.i32(i32, metadata, metadata)
@@ -683,6 +684,310 @@ define float @pass_nofpclass_inf_through_memory(float nofpclass(inf) %arg) {
683684
ret float %ret
684685
}
685686

687+
define float @returned_fabs(float %x) {
688+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
689+
; CHECK-LABEL: define float @returned_fabs
690+
; CHECK-SAME: (float [[X:%.*]]) #[[ATTR2]] {
691+
; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]]) #[[ATTR7]]
692+
; CHECK-NEXT: ret float [[FABS]]
693+
;
694+
%fabs = call float @llvm.fabs.f32(float %x)
695+
ret float %fabs
696+
}
697+
698+
define float @returned_fabs_nosnan(float nofpclass(snan) %x) {
699+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
700+
; CHECK-LABEL: define nofpclass(snan) float @returned_fabs_nosnan
701+
; CHECK-SAME: (float nofpclass(snan) [[X:%.*]]) #[[ATTR2]] {
702+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(snan) float @llvm.fabs.f32(float nofpclass(snan) [[X]]) #[[ATTR7]]
703+
; CHECK-NEXT: ret float [[FABS]]
704+
;
705+
%fabs = call float @llvm.fabs.f32(float %x)
706+
ret float %fabs
707+
}
708+
709+
define float @returned_fabs_noqnan(float nofpclass(qnan) %x) {
710+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
711+
; CHECK-LABEL: define nofpclass(qnan) float @returned_fabs_noqnan
712+
; CHECK-SAME: (float nofpclass(qnan) [[X:%.*]]) #[[ATTR2]] {
713+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(qnan) float @llvm.fabs.f32(float nofpclass(qnan) [[X]]) #[[ATTR7]]
714+
; CHECK-NEXT: ret float [[FABS]]
715+
;
716+
%fabs = call float @llvm.fabs.f32(float %x)
717+
ret float %fabs
718+
}
719+
720+
define float @returned_fabs_nonan(float nofpclass(nan) %x) {
721+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
722+
; CHECK-LABEL: define nofpclass(nan) float @returned_fabs_nonan
723+
; CHECK-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR2]] {
724+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(nan) float @llvm.fabs.f32(float nofpclass(nan) [[X]]) #[[ATTR7]]
725+
; CHECK-NEXT: ret float [[FABS]]
726+
;
727+
%fabs = call float @llvm.fabs.f32(float %x)
728+
ret float %fabs
729+
}
730+
731+
define float @returned_fabs_noinf(float nofpclass(inf) %x) {
732+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
733+
; CHECK-LABEL: define nofpclass(inf) float @returned_fabs_noinf
734+
; CHECK-SAME: (float nofpclass(inf) [[X:%.*]]) #[[ATTR2]] {
735+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(inf) float @llvm.fabs.f32(float nofpclass(inf) [[X]]) #[[ATTR7]]
736+
; CHECK-NEXT: ret float [[FABS]]
737+
;
738+
%fabs = call float @llvm.fabs.f32(float %x)
739+
ret float %fabs
740+
}
741+
742+
define float @returned_fneg(float %x) {
743+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
744+
; CHECK-LABEL: define float @returned_fneg
745+
; CHECK-SAME: (float [[X:%.*]]) #[[ATTR2]] {
746+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
747+
; CHECK-NEXT: ret float [[FNEG]]
748+
;
749+
%fneg = fneg float %x
750+
ret float %fneg
751+
}
752+
753+
define float @returned_fneg_nosnan(float nofpclass(snan) %x) {
754+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
755+
; CHECK-LABEL: define nofpclass(snan) float @returned_fneg_nosnan
756+
; CHECK-SAME: (float nofpclass(snan) [[X:%.*]]) #[[ATTR2]] {
757+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
758+
; CHECK-NEXT: ret float [[FNEG]]
759+
;
760+
%fneg = fneg float %x
761+
ret float %fneg
762+
}
763+
764+
define float @returned_fneg_noqnan(float nofpclass(qnan) %x) {
765+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
766+
; CHECK-LABEL: define nofpclass(qnan) float @returned_fneg_noqnan
767+
; CHECK-SAME: (float nofpclass(qnan) [[X:%.*]]) #[[ATTR2]] {
768+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
769+
; CHECK-NEXT: ret float [[FNEG]]
770+
;
771+
%fneg = fneg float %x
772+
ret float %fneg
773+
}
774+
775+
define float @returned_fneg_nosnan_ninf_flag(float nofpclass(snan) %x) {
776+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
777+
; CHECK-LABEL: define nofpclass(snan inf) float @returned_fneg_nosnan_ninf_flag
778+
; CHECK-SAME: (float nofpclass(snan) [[X:%.*]]) #[[ATTR2]] {
779+
; CHECK-NEXT: [[FNEG:%.*]] = fneg ninf float [[X]]
780+
; CHECK-NEXT: ret float [[FNEG]]
781+
;
782+
%fneg = fneg ninf float %x
783+
ret float %fneg
784+
}
785+
786+
define float @returned_fneg_nonan(float nofpclass(nan) %x) {
787+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
788+
; CHECK-LABEL: define nofpclass(nan) float @returned_fneg_nonan
789+
; CHECK-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR2]] {
790+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
791+
; CHECK-NEXT: ret float [[FNEG]]
792+
;
793+
%fneg = fneg float %x
794+
ret float %fneg
795+
}
796+
797+
define float @returned_fneg_noinf(float nofpclass(inf) %x) {
798+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
799+
; CHECK-LABEL: define nofpclass(inf) float @returned_fneg_noinf
800+
; CHECK-SAME: (float nofpclass(inf) [[X:%.*]]) #[[ATTR2]] {
801+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
802+
; CHECK-NEXT: ret float [[FNEG]]
803+
;
804+
%fneg = fneg float %x
805+
ret float %fneg
806+
}
807+
808+
define float @returned_fneg_noneg(float nofpclass(ninf nsub nnorm nzero) %x) {
809+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
810+
; CHECK-LABEL: define nofpclass(pinf pzero psub pnorm) float @returned_fneg_noneg
811+
; CHECK-SAME: (float nofpclass(ninf nzero nsub nnorm) [[X:%.*]]) #[[ATTR2]] {
812+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
813+
; CHECK-NEXT: ret float [[FNEG]]
814+
;
815+
%fneg = fneg float %x
816+
ret float %fneg
817+
}
818+
819+
define float @returned_fneg_noneg_nnan_flag(float nofpclass(ninf nsub nnorm nzero) %x) {
820+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
821+
; CHECK-LABEL: define nofpclass(nan pinf pzero psub pnorm) float @returned_fneg_noneg_nnan_flag
822+
; CHECK-SAME: (float nofpclass(ninf nzero nsub nnorm) [[X:%.*]]) #[[ATTR2]] {
823+
; CHECK-NEXT: [[FNEG:%.*]] = fneg nnan float [[X]]
824+
; CHECK-NEXT: ret float [[FNEG]]
825+
;
826+
%fneg = fneg nnan float %x
827+
ret float %fneg
828+
}
829+
830+
define float @returned_fneg_nonsubnnorm(float nofpclass(nsub nnorm) %x) {
831+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
832+
; CHECK-LABEL: define nofpclass(psub pnorm) float @returned_fneg_nonsubnnorm
833+
; CHECK-SAME: (float nofpclass(nsub nnorm) [[X:%.*]]) #[[ATTR2]] {
834+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
835+
; CHECK-NEXT: ret float [[FNEG]]
836+
;
837+
%fneg = fneg float %x
838+
ret float %fneg
839+
}
840+
841+
define float @returned_fneg_nopos(float nofpclass(pinf psub pnorm pzero) %x) {
842+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
843+
; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) float @returned_fneg_nopos
844+
; CHECK-SAME: (float nofpclass(pinf pzero psub pnorm) [[X:%.*]]) #[[ATTR2]] {
845+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
846+
; CHECK-NEXT: ret float [[FNEG]]
847+
;
848+
%fneg = fneg float %x
849+
ret float %fneg
850+
}
851+
852+
define float @returned_fneg_nopnormpsub(float nofpclass(psub pnorm) %x) {
853+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
854+
; CHECK-LABEL: define nofpclass(nsub nnorm) float @returned_fneg_nopnormpsub
855+
; CHECK-SAME: (float nofpclass(psub pnorm) [[X:%.*]]) #[[ATTR2]] {
856+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
857+
; CHECK-NEXT: ret float [[FNEG]]
858+
;
859+
%fneg = fneg float %x
860+
ret float %fneg
861+
}
862+
863+
define float @returned_fneg_mixed(float nofpclass(psub nnorm nzero qnan ninf) %x) {
864+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
865+
; CHECK-LABEL: define nofpclass(qnan pinf pzero nsub pnorm) float @returned_fneg_mixed
866+
; CHECK-SAME: (float nofpclass(qnan ninf nzero psub nnorm) [[X:%.*]]) #[[ATTR2]] {
867+
; CHECK-NEXT: [[FNEG:%.*]] = fneg float [[X]]
868+
; CHECK-NEXT: ret float [[FNEG]]
869+
;
870+
%fneg = fneg float %x
871+
ret float %fneg
872+
}
873+
874+
define float @returned_fneg_fabs(float %x) {
875+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
876+
; CHECK-LABEL: define float @returned_fneg_fabs
877+
; CHECK-SAME: (float [[X:%.*]]) #[[ATTR2]] {
878+
; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]]) #[[ATTR7]]
879+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg float [[FABS]]
880+
; CHECK-NEXT: ret float [[FNEG_FABS]]
881+
;
882+
%fabs = call float @llvm.fabs.f32(float %x)
883+
%fneg.fabs = fneg float %fabs
884+
ret float %fneg.fabs
885+
}
886+
887+
define float @returned_fneg_fabs_nosnan(float nofpclass(snan) %x) {
888+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
889+
; CHECK-LABEL: define nofpclass(snan) float @returned_fneg_fabs_nosnan
890+
; CHECK-SAME: (float nofpclass(snan) [[X:%.*]]) #[[ATTR2]] {
891+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(snan) float @llvm.fabs.f32(float nofpclass(snan) [[X]]) #[[ATTR7]]
892+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg float [[FABS]]
893+
; CHECK-NEXT: ret float [[FNEG_FABS]]
894+
;
895+
%fabs = call float @llvm.fabs.f32(float %x)
896+
%fneg.fabs = fneg float %fabs
897+
ret float %fneg.fabs
898+
}
899+
900+
define float @returned_fneg_fabs_noqnan(float nofpclass(qnan) %x) {
901+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
902+
; CHECK-LABEL: define nofpclass(qnan) float @returned_fneg_fabs_noqnan
903+
; CHECK-SAME: (float nofpclass(qnan) [[X:%.*]]) #[[ATTR2]] {
904+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(qnan) float @llvm.fabs.f32(float nofpclass(qnan) [[X]]) #[[ATTR7]]
905+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg float [[FABS]]
906+
; CHECK-NEXT: ret float [[FNEG_FABS]]
907+
;
908+
%fabs = call float @llvm.fabs.f32(float %x)
909+
%fneg.fabs = fneg float %fabs
910+
ret float %fneg.fabs
911+
}
912+
913+
define float @returned_fneg_fabs_nonan(float nofpclass(nan) %x) {
914+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
915+
; CHECK-LABEL: define nofpclass(nan) float @returned_fneg_fabs_nonan
916+
; CHECK-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR2]] {
917+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(nan) float @llvm.fabs.f32(float nofpclass(nan) [[X]]) #[[ATTR7]]
918+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg float [[FABS]]
919+
; CHECK-NEXT: ret float [[FNEG_FABS]]
920+
;
921+
%fabs = call float @llvm.fabs.f32(float %x)
922+
%fneg.fabs = fneg float %fabs
923+
ret float %fneg.fabs
924+
}
925+
926+
define float @returned_fneg_fabs_noneg(float nofpclass(ninf nsub nnorm nzero) %x) {
927+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
928+
; CHECK-LABEL: define float @returned_fneg_fabs_noneg
929+
; CHECK-SAME: (float nofpclass(ninf nzero nsub nnorm) [[X:%.*]]) #[[ATTR2]] {
930+
; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float nofpclass(ninf nzero nsub nnorm) [[X]]) #[[ATTR7]]
931+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg float [[FABS]]
932+
; CHECK-NEXT: ret float [[FNEG_FABS]]
933+
;
934+
%fabs = call float @llvm.fabs.f32(float %x)
935+
%fneg.fabs = fneg float %fabs
936+
ret float %fneg.fabs
937+
}
938+
939+
define float @returned_fneg_fabs_nopos(float nofpclass(pinf psub pnorm pzero) %x) {
940+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
941+
; CHECK-LABEL: define nofpclass(inf zero sub norm) float @returned_fneg_fabs_nopos
942+
; CHECK-SAME: (float nofpclass(pinf pzero psub pnorm) [[X:%.*]]) #[[ATTR2]] {
943+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(inf zero sub norm) float @llvm.fabs.f32(float nofpclass(pinf pzero psub pnorm) [[X]]) #[[ATTR7]]
944+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg float [[FABS]]
945+
; CHECK-NEXT: ret float [[FNEG_FABS]]
946+
;
947+
%fabs = call float @llvm.fabs.f32(float %x)
948+
%fneg.fabs = fneg float %fabs
949+
ret float %fneg.fabs
950+
}
951+
952+
define float @returned_fneg_fabs_mixed(float nofpclass(psub nnorm nzero qnan ninf) %x) {
953+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
954+
; CHECK-LABEL: define nofpclass(qnan sub) float @returned_fneg_fabs_mixed
955+
; CHECK-SAME: (float nofpclass(qnan ninf nzero psub nnorm) [[X:%.*]]) #[[ATTR2]] {
956+
; CHECK-NEXT: [[FABS:%.*]] = call nofpclass(qnan sub) float @llvm.fabs.f32(float nofpclass(qnan ninf nzero psub nnorm) [[X]]) #[[ATTR7]]
957+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg float [[FABS]]
958+
; CHECK-NEXT: ret float [[FNEG_FABS]]
959+
;
960+
%fabs = call float @llvm.fabs.f32(float %x)
961+
%fneg.fabs = fneg float %fabs
962+
ret float %fneg.fabs
963+
}
964+
965+
define float @returned_fneg_fabs_ninf_flag_fabs(float %x) {
966+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
967+
; CHECK-LABEL: define nofpclass(inf) float @returned_fneg_fabs_ninf_flag_fabs
968+
; CHECK-SAME: (float [[X:%.*]]) #[[ATTR2]] {
969+
; CHECK-NEXT: [[FABS:%.*]] = call ninf nofpclass(inf) float @llvm.fabs.f32(float [[X]]) #[[ATTR7]]
970+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg float [[FABS]]
971+
; CHECK-NEXT: ret float [[FNEG_FABS]]
972+
;
973+
%fabs = call ninf float @llvm.fabs.f32(float %x)
974+
%fneg.fabs = fneg float %fabs
975+
ret float %fneg.fabs
976+
}
977+
978+
define float @returned_fneg_fabs_ninf_flag_fneg(float %x) {
979+
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
980+
; CHECK-LABEL: define nofpclass(inf) float @returned_fneg_fabs_ninf_flag_fneg
981+
; CHECK-SAME: (float [[X:%.*]]) #[[ATTR2]] {
982+
; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X]]) #[[ATTR7]]
983+
; CHECK-NEXT: [[FNEG_FABS:%.*]] = fneg ninf float [[FABS]]
984+
; CHECK-NEXT: ret float [[FNEG_FABS]]
985+
;
986+
%fabs = call float @llvm.fabs.f32(float %x)
987+
%fneg.fabs = fneg ninf float %fabs
988+
ret float %fneg.fabs
989+
}
990+
686991
define float @uitofp_i32_to_f32(i32 %arg) {
687992
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
688993
; CHECK-LABEL: define nofpclass(nan inf nzero sub nnorm) float @uitofp_i32_to_f32

0 commit comments

Comments
 (0)