summaryrefslogtreecommitdiff
path: root/llvm/test/CodeGen/DirectX
diff options
context:
space:
mode:
authorFarzon Lotfi <farzonlotfi@microsoft.com>2025-09-08 13:47:50 -0400
committerGitHub <noreply@github.com>2025-09-08 13:47:50 -0400
commit1dbade85cb3500f11cb8cefd0541efebbb0a8fda (patch)
tree55c20843dd052ad9260da3ba182ad454f235b66f /llvm/test/CodeGen/DirectX
parent393bc0cc9f0e703837ad5fd238472491bb183447 (diff)
[DirectX] Add emulation for fp16 types of llvm.is.fpclass (#157505)
fixes #157504 This changes adds the emulation we need for IsNaN, IsNormal, & IsFinite This change only applies these emulations to the llvm.is.fpclass cases of fp16. Since there is no DX intrinsics yet for these cases, applying the emulation to the necessary intrinsics is left for future implementers of - https://github.com/llvm/llvm-project/issues/99132 - https://github.com/llvm/llvm-project/issues/156069 - https://github.com/llvm/llvm-project/issues/99131
Diffstat (limited to 'llvm/test/CodeGen/DirectX')
-rw-r--r--llvm/test/CodeGen/DirectX/is_fpclass.ll150
1 files changed, 149 insertions, 1 deletions
diff --git a/llvm/test/CodeGen/DirectX/is_fpclass.ll b/llvm/test/CodeGen/DirectX/is_fpclass.ll
index 1796e8bd794d..f5804f341885 100644
--- a/llvm/test/CodeGen/DirectX/is_fpclass.ll
+++ b/llvm/test/CodeGen/DirectX/is_fpclass.ll
@@ -46,6 +46,25 @@ entry:
ret i1 %0
}
+define noundef i1 @isnanh(half noundef %a) {
+; CHECK-LABEL: define noundef i1 @isnanh(
+; CHECK-SAME: half noundef [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; SM69CHECK-NEXT: [[TMP0:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 8, half [[A]]) #[[ATTR0:[0-9]+]]
+; SMOLDCHECK-NEXT: [[BITCAST:%.*]] = bitcast half [[A]] to i16
+; SMOLDCHECK-NEXT: [[AND:%.*]] = and i16 [[BITCAST]], 31744
+; SMOLDCHECK-NEXT: [[CMPHIGH:%.*]] = icmp eq i16 [[AND]], 31744
+; SMOLDCHECK-NEXT: [[ANDLOW:%.*]] = and i16 [[BITCAST]], 1023
+; SMOLDCHECK-NEXT: [[CMPZERO:%.*]] = icmp ne i16 [[ANDLOW]], 0
+; SMOLDCHECK-NEXT: [[ANDLOW:%.*]] = and i1 [[CMPHIGH]], [[CMPZERO]]
+; SMOLDCHECK-NEXT: ret i1 [[ANDLOW]]
+; SM69CHECK-NEXT: ret i1 [[TMP0]]
+;
+entry:
+ %0 = call i1 @llvm.is.fpclass.f16(half %a, i32 3)
+ ret i1 %0
+}
+
define noundef <2 x i1> @isnanv2(<2 x float> noundef %a) {
; CHECK-LABEL: define noundef <2 x i1> @isnanv2(
; CHECK-SAME: <2 x float> noundef [[A:%.*]]) {
@@ -63,6 +82,40 @@ entry:
ret <2 x i1> %0
}
+define noundef <2 x i1> @isnanhv2(<2 x half> noundef %a) {
+; CHECK-LABEL: define noundef <2 x i1> @isnanhv2(
+; CHECK-SAME: <2 x half> noundef [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[A_I0:%.*]] = extractelement <2 x half> [[A]], i64 0
+; SM69CHECK-NEXT: [[DOTI02:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 8, half [[A_I0]]) #[[ATTR0:[0-9]+]]
+; SM69CHECK-NEXT: [[A_I1:%.*]] = extractelement <2 x half> [[A]], i64 1
+; SM69CHECK-NEXT: [[DOTI11:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 8, half [[A_I1]]) #[[ATTR0]]
+; SM69CHECK-NEXT: [[DOTUPTO0:%.*]] = insertelement <2 x i1> poison, i1 [[DOTI02]], i64 0
+; SM69CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i1> [[DOTUPTO0]], i1 [[DOTI11]], i64 1
+; SM69CHECK-NEXT: ret <2 x i1> [[TMP0]]
+;
+; SMOLDCHECK-NEXT: [[DOTI0:%.*]] = bitcast half [[A_I0]] to i16
+; SMOLDCHECK-NEXT: [[A_I1:%.*]] = extractelement <2 x half> [[A]], i64 1
+; SMOLDCHECK-NEXT: [[DOTI1:%.*]] = bitcast half [[A_I1]] to i16
+; SMOLDCHECK-NEXT: [[DOTI01:%.*]] = and i16 [[DOTI0]], 31744
+; SMOLDCHECK-NEXT: [[DOTI12:%.*]] = and i16 [[DOTI1]], 31744
+; SMOLDCHECK-NEXT: [[DOTI03:%.*]] = icmp eq i16 [[DOTI01]], 31744
+; SMOLDCHECK-NEXT: [[DOTI14:%.*]] = icmp eq i16 [[DOTI12]], 31744
+; SMOLDCHECK-NEXT: [[DOTI05:%.*]] = and i16 [[DOTI0]], 1023
+; SMOLDCHECK-NEXT: [[DOTI16:%.*]] = and i16 [[DOTI1]], 1023
+; SMOLDCHECK-NEXT: [[DOTI07:%.*]] = icmp ne i16 [[DOTI05]], 0
+; SMOLDCHECK-NEXT: [[DOTI18:%.*]] = icmp ne i16 [[DOTI16]], 0
+; SMOLDCHECK-NEXT: [[DOTI09:%.*]] = and i1 [[DOTI03]], [[DOTI07]]
+; SMOLDCHECK-NEXT: [[DOTI110:%.*]] = and i1 [[DOTI14]], [[DOTI18]]
+; SMOLDCHECK-NEXT: [[DOTUPTO015:%.*]] = insertelement <2 x i1> poison, i1 [[DOTI09]], i64 0
+; SMOLDCHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i1> [[DOTUPTO015]], i1 [[DOTI110]], i64 1
+; SMOLDCHECK-NEXT: ret <2 x i1> [[TMP0]]
+;
+entry:
+ %0 = call <2 x i1> @llvm.is.fpclass.v2f16(<2 x half> %a, i32 3)
+ ret <2 x i1> %0
+}
+
define noundef i1 @isinf(float noundef %a) {
; CHECK-LABEL: define noundef i1 @isinf(
; CHECK-SAME: float noundef [[A:%.*]]) {
@@ -80,7 +133,7 @@ define noundef i1 @isinfh(half noundef %a) {
; CHECK-SAME: half noundef [[A:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; SM69CHECK-NEXT: [[ISINF:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 9, half [[A]]) #[[ATTR0]]
-; SMOLDCHECK-NEXT: [[BITCAST:%.*]] = bitcast half %a to i16
+; SMOLDCHECK-NEXT: [[BITCAST:%.*]] = bitcast half [[A]] to i16
; SMOLDCHECK-NEXT: [[CMPHIGH:%.*]] = icmp eq i16 [[BITCAST]], 31744
; SMOLDCHECK-NEXT: [[CMPLOW:%.*]] = icmp eq i16 [[BITCAST]], -1024
; SMOLDCHECK-NEXT: [[OR:%.*]] = or i1 [[CMPHIGH]], [[CMPLOW]]
@@ -121,6 +174,22 @@ entry:
ret i1 %0
}
+define noundef i1 @isfiniteh(half noundef %a) {
+; CHECK-LABEL: define noundef i1 @isfiniteh(
+; CHECK-SAME: half noundef [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; SM69CHECK-NEXT: [[TMP0:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 10, half [[A]]) #[[ATTR0]]
+; SMOLDCHECK-NEXT: [[BITCAST:%.*]] = bitcast half [[A]] to i16
+; SMOLDCHECK-NEXT: [[AND:%.*]] = and i16 [[BITCAST]], 31744
+; SMOLDCHECK-NEXT: [[CMPHIGH:%.*]] = icmp ne i16 [[AND]], 31744
+; SMOLDCHECK-NEXT: ret i1 [[CMPHIGH]]
+; SM69CHECK-NEXT: ret i1 [[TMP0]]
+;
+entry:
+ %0 = call i1 @llvm.is.fpclass.f16(half %a, i32 504)
+ ret i1 %0
+}
+
define noundef <2 x i1> @isfinitev2(<2 x float> noundef %a) {
; CHECK-LABEL: define noundef <2 x i1> @isfinitev2(
; CHECK-SAME: <2 x float> noundef [[A:%.*]]) {
@@ -138,6 +207,35 @@ entry:
ret <2 x i1> %0
}
+define noundef <2 x i1> @isfinitehv2(<2 x half> noundef %a) {
+; CHECK-LABEL: define noundef <2 x i1> @isfinitehv2(
+; CHECK-SAME: <2 x half> noundef [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; SM69CHECK-NEXT: [[A_I0:%.*]] = extractelement <2 x half> [[A]], i64 0
+; SM69CHECK-NEXT: [[DOTI02:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 10, half [[A_I0]]) #[[ATTR0:[0-9]+]]
+; SM69CHECK-NEXT: [[A_I1:%.*]] = extractelement <2 x half> [[A]], i64 1
+; SM69CHECK-NEXT: [[DOTI11:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 10, half [[A_I1]]) #[[ATTR0]]
+; SM69CHECK-NEXT: [[DOTUPTO0:%.*]] = insertelement <2 x i1> poison, i1 [[DOTI02]], i64 0
+; SM69CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i1> [[DOTUPTO0]], i1 [[DOTI11]], i64 1
+; SM69CHECK-NEXT: ret <2 x i1> [[TMP0]]
+;
+; SMOLDCHECK-NEXT: [[A_I0:%.*]] = extractelement <2 x half> [[A]], i64 0
+; SMOLDCHECK-NEXT: [[DOTI0:%.*]] = bitcast half [[A_I0]] to i16
+; SMOLDCHECK-NEXT: [[A_I1:%.*]] = extractelement <2 x half> [[A]], i64 1
+; SMOLDCHECK-NEXT: [[DOTI1:%.*]] = bitcast half [[A_I1]] to i16
+; SMOLDCHECK-NEXT: [[DOTI01:%.*]] = and i16 [[DOTI0]], 31744
+; SMOLDCHECK-NEXT: [[DOTI12:%.*]] = and i16 [[DOTI1]], 31744
+; SMOLDCHECK-NEXT: [[DOTI03:%.*]] = icmp ne i16 [[DOTI01]], 31744
+; SMOLDCHECK-NEXT: [[DOTI14:%.*]] = icmp ne i16 [[DOTI12]], 31744
+; SMOLDCHECK-NEXT: [[DOTUPTO06:%.*]] = insertelement <2 x i1> poison, i1 [[DOTI03]], i64 0
+; SMOLDCHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i1> [[DOTUPTO06]], i1 [[DOTI14]], i64 1
+; SMOLDCHECK-NEXT: ret <2 x i1> [[TMP0]]
+;
+entry:
+ %0 = call <2 x i1> @llvm.is.fpclass.v2f16(<2 x half> %a, i32 504)
+ ret <2 x i1> %0
+}
+
define noundef i1 @isnormal(float noundef %a) {
; CHECK-LABEL: define noundef i1 @isnormal(
; CHECK-SAME: float noundef [[A:%.*]]) {
@@ -150,6 +248,24 @@ entry:
ret i1 %0
}
+define noundef i1 @isnormalh(half noundef %a) {
+; CHECK-LABEL: define noundef i1 @isnormalh(
+; CHECK-SAME: half noundef [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; SM69CHECK-NEXT: [[TMP0:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 11, half [[A]]) #[[ATTR0]]
+; SMOLDCHECK-NEXT: [[BITCAST:%.*]] = bitcast half [[A]] to i16
+; SMOLDCHECK-NEXT: [[AND:%.*]] = and i16 [[BITCAST]], 31744
+; SMOLDCHECK-NEXT: [[CMPZERO:%.*]] = icmp ne i16 [[AND]], 0
+; SMOLDCHECK-NEXT: [[CMPHIGH:%.*]] = icmp ne i16 [[AND]], 31744
+; SMOLDCHECK-NEXT: [[ANDCMP:%.*]] = and i1 [[CMPZERO]], [[CMPHIGH]]
+; SMOLDCHECK-NEXT: ret i1 [[ANDCMP]]
+; SM69CHECK-NEXT: ret i1 [[TMP0]]
+;
+entry:
+ %0 = call i1 @llvm.is.fpclass.f16(half %a, i32 264)
+ ret i1 %0
+}
+
define noundef <2 x i1> @isnormalv2(<2 x float> noundef %a) {
; CHECK-LABEL: define noundef <2 x i1> @isnormalv2(
; CHECK-SAME: <2 x float> noundef [[A:%.*]]) {
@@ -167,5 +283,37 @@ entry:
ret <2 x i1> %0
}
+define noundef <2 x i1> @isnormalhv2(<2 x half> noundef %a) {
+; CHECK-LABEL: define noundef <2 x i1> @isnormalhv2(
+; CHECK-SAME: <2 x half> noundef [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[A_I0:%.*]] = extractelement <2 x half> [[A]], i64 0
+; SM69CHECK-NEXT: [[DOTI02:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 11, half [[A_I0]]) #[[ATTR0:[0-9]+]]
+; SM69CHECK-NEXT: [[A_I1:%.*]] = extractelement <2 x half> [[A]], i64 1
+; SM69CHECK-NEXT: [[DOTI11:%.*]] = call i1 @dx.op.isSpecialFloat.f16(i32 11, half [[A_I1]]) #[[ATTR0]]
+; SM69CHECK-NEXT: [[DOTUPTO0:%.*]] = insertelement <2 x i1> poison, i1 [[DOTI02]], i64 0
+; SM69CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i1> [[DOTUPTO0]], i1 [[DOTI11]], i64 1
+; SM69CHECK-NEXT: ret <2 x i1> [[TMP0]]
+;
+; SMOLDCHECK-NEXT: [[DOTI0:%.*]] = bitcast half [[A_I0]] to i16
+; SMOLDCHECK-NEXT: [[A_I1:%.*]] = extractelement <2 x half> [[A]], i64 1
+; SMOLDCHECK-NEXT: [[DOTI1:%.*]] = bitcast half [[A_I1]] to i16
+; SMOLDCHECK-NEXT: [[DOTI01:%.*]] = and i16 [[DOTI0]], 31744
+; SMOLDCHECK-NEXT: [[DOTI12:%.*]] = and i16 [[DOTI1]], 31744
+; SMOLDCHECK-NEXT: [[DOTI03:%.*]] = icmp ne i16 [[DOTI01]], 0
+; SMOLDCHECK-NEXT: [[DOTI14:%.*]] = icmp ne i16 [[DOTI12]], 0
+; SMOLDCHECK-NEXT: [[DOTI05:%.*]] = icmp ne i16 [[DOTI01]], 31744
+; SMOLDCHECK-NEXT: [[DOTI16:%.*]] = icmp ne i16 [[DOTI12]], 31744
+; SMOLDCHECK-NEXT: [[DOTI07:%.*]] = and i1 [[DOTI03]], [[DOTI05]]
+; SMOLDCHECK-NEXT: [[DOTI18:%.*]] = and i1 [[DOTI14]], [[DOTI16]]
+; SMOLDCHECK-NEXT: [[DOTUPTO012:%.*]] = insertelement <2 x i1> poison, i1 [[DOTI07]], i64 0
+; SMOLDCHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i1> [[DOTUPTO012]], i1 [[DOTI18]], i64 1
+; SMOLDCHECK-NEXT: ret <2 x i1> [[TMP0]]
+;
+entry:
+ %0 = call <2 x i1> @llvm.is.fpclass.v2f16(<2 x half> %a, i32 264)
+ ret <2 x i1> %0
+}
+
declare i1 @llvm.is.fpclass.f32(float, i32 immarg)
declare <2 x i1> @llvm.is.fpclass.v2f32(<2 x float>, i32 immarg)