[clang] Implement the `fmod` intrinsic (PR #130320)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 10 15:50:05 PDT 2025
================
@@ -22,56 +22,136 @@
//
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
-// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN: -emit-llvm -o - | FileCheck %s \
// RUN: -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=half
//
// ---------- No Native Half support test -----------
//
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
+// RUN: spirv-unknown-vulkan-compute %s -emit-llvm \
// RUN: -o - | FileCheck %s \
// RUN: -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=float
+// DXCHECK: define [[FNATTRS]] [[TYPE]] @
+// DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn [[TYPE]] %4, %5
+// DXCHECK: %fneg.i = fneg reassoc nnan ninf nsz arcp afn [[TYPE]] %7
+// DXCHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn oge [[TYPE]] %6, %fneg.i
+// DXCHECK: %elt.abs.i = call reassoc nnan ninf nsz arcp afn [[TYPE]] @llvm.fabs.[[INT_TYPE]]([[TYPE]] %8)
+// DXCHECK: %hlsl.frac.i = call reassoc nnan ninf nsz arcp afn [[TYPE]] @llvm.dx.frac.[[INT_TYPE]]([[TYPE]] %elt.abs.i)
+// DXCHECK: %fneg2.i = fneg reassoc nnan ninf nsz arcp afn [[TYPE]] %11
+// DXCHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %loadedv.i, [[TYPE]] %10, [[TYPE]] %fneg2.i
+// DXCHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn [[TYPE]] %hlsl.select.i, %12
+// DXCHECK: ret [[TYPE]] %mul.i
----------------
farzonl wrote:
As to the question about `-O1`. I think we should strive for most of the tests in `clang/test/CodeGenHLSL/builtins` to be `-disable-llvm-passes`. That should be a hard requirement if we do the codegen in `cgbuiltins.cpp`. For your case since we are generating code in HLSL source `-O1` would be fine. I think if we can get away with similar codegen without it we should because a `-O1` test takes longer to run.
https://github.com/llvm/llvm-project/pull/130320
More information about the cfe-commits
mailing list