[llvm] [DXIL] Add lowering for `ceil` (PR #87039)
Helena Kotas via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 29 00:43:33 PDT 2024
https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/87039
>From 4b1f2f50142a6872edd9dbb8b48deaa8a6062c69 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Fri, 29 Mar 2024 00:31:11 -0700
Subject: [PATCH 1/2] [DXIL] Add lowering for ceil
---
llvm/lib/Target/DirectX/DXIL.td | 3 +++
llvm/test/CodeGen/DirectX/ceil.ll | 20 ++++++++++++++++++++
llvm/test/CodeGen/DirectX/ceil_error.ll | 10 ++++++++++
3 files changed, 33 insertions(+)
create mode 100644 llvm/test/CodeGen/DirectX/ceil.ll
create mode 100644 llvm/test/CodeGen/DirectX/ceil_error.ll
diff --git a/llvm/lib/Target/DirectX/DXIL.td b/llvm/lib/Target/DirectX/DXIL.td
index c5d7ee76275f86..0d476c0dcf43c4 100644
--- a/llvm/lib/Target/DirectX/DXIL.td
+++ b/llvm/lib/Target/DirectX/DXIL.td
@@ -298,6 +298,9 @@ def Trunc : DXILOpMapping<29, unary, int_trunc,
def Rbits : DXILOpMapping<30, unary, int_bitreverse,
"Returns the specified value with its bits reversed.",
[llvm_anyint_ty, LLVMMatchType<0>]>;
+def Ceil : DXILOpMapping<28, unary, int_ceil,
+ "Returns the smallest integer that is greater than or equal to the input.",
+ [llvm_halforfloat_ty, LLVMMatchType<0>]>;
def FMax : DXILOpMapping<35, binary, int_maxnum,
"Float maximum. FMax(a,b) = a > b ? a : b">;
def FMin : DXILOpMapping<36, binary, int_minnum,
diff --git a/llvm/test/CodeGen/DirectX/ceil.ll b/llvm/test/CodeGen/DirectX/ceil.ll
new file mode 100644
index 00000000000000..ac451824367aad
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ceil.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
+
+; Make sure dxil operation function calls for ceil are generated for float and half.
+
+define noundef float @ceil_float(float noundef %a) {
+entry:
+; CHECK:call float @dx.op.unary.f32(i32 28, float %{{.*}})
+ %elt.ceil = call ceil @llvm.ceil.f32(float %a)
+ ret float %elt.ceil
+}
+
+define noundef half @ceil_half(half noundef %a) {
+entry:
+; CHECK:call half @dx.op.unary.f16(i32 28, half %{{.*}})
+ %elt.ceil = call half @llvm.ceil.f16(half %a)
+ ret half %elt.ceil
+}
+
+declare half @llvm.ceil.f16(half)
+declare float @llvm.ceil.f32(float)
diff --git a/llvm/test/CodeGen/DirectX/ceil_error.ll b/llvm/test/CodeGen/DirectX/ceil_error.ll
new file mode 100644
index 00000000000000..1b554d8715566e
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ceil_error.ll
@@ -0,0 +1,10 @@
+; RUN: not opt -S -dxil-op-lower %s 2>&1 | FileCheck %s
+
+; DXIL operation ceil does not support double overload type
+; CHECK: LLVM ERROR: Invalid Overload Type
+
+define noundef double @ceil_double(double noundef %a) {
+entry:
+ %elt.ceil = call double @llvm.ceil.f64(double %a)
+ ret double %elt.ceil
+}
>From 8fd1fac85862efd7d9d10e7d923c242403015acb Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Fri, 29 Mar 2024 00:43:14 -0700
Subject: [PATCH 2/2] Fix ordering of DXIL op mapping after rebasing
---
llvm/lib/Target/DirectX/DXIL.td | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXIL.td b/llvm/lib/Target/DirectX/DXIL.td
index 0d476c0dcf43c4..a9ae47c5c0c5a0 100644
--- a/llvm/lib/Target/DirectX/DXIL.td
+++ b/llvm/lib/Target/DirectX/DXIL.td
@@ -292,15 +292,15 @@ def Round : DXILOpMapping<26, unary, int_round,
def Floor : DXILOpMapping<27, unary, int_floor,
"Returns the largest integer that is less than or equal to the input.",
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
+def Ceil : DXILOpMapping<28, unary, int_ceil,
+ "Returns the smallest integer that is greater than or equal to the input.",
+ [llvm_halforfloat_ty, LLVMMatchType<0>]>;
def Trunc : DXILOpMapping<29, unary, int_trunc,
"Returns the specified value truncated to the integer component.",
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
def Rbits : DXILOpMapping<30, unary, int_bitreverse,
"Returns the specified value with its bits reversed.",
[llvm_anyint_ty, LLVMMatchType<0>]>;
-def Ceil : DXILOpMapping<28, unary, int_ceil,
- "Returns the smallest integer that is greater than or equal to the input.",
- [llvm_halforfloat_ty, LLVMMatchType<0>]>;
def FMax : DXILOpMapping<35, binary, int_maxnum,
"Float maximum. FMax(a,b) = a > b ? a : b">;
def FMin : DXILOpMapping<36, binary, int_minnum,
More information about the llvm-commits
mailing list