intel / llvm

Intel staging area for llvm.org contribution. Home for Intel LLVM-based projects.
Other
1.23k stars 736 forks source link

Unexpected llvm intrinsic: `llvm.fptosi.sat.i8.f64` #10709

Closed fwyzard closed 5 months ago

fwyzard commented 1 year ago

Describe the bug

While building a SYCL application, clang/llvm aborts with an error about an unsupported intrinsic:

InvalidFunctionCall: Unexpected llvm intrinsic:
 llvm.fptosi.sat.i8.f64 [Src: /data/user/fwyzard/sycl/llvm/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp:4544 false ]

To Reproduce Please find attached a preprocessed file that reproduces the problem: gpuVertexFinder.ii.gz .

The failure can be reproduced with

gunzip gpuVertexFinder.ii.gz
clang++ -std=c++17 -O2 -fPIC -pipe -g -fsycl gpuVertexFinder.ii -shared -o liboutput.so

using the latest nightly.

The nightly itself was built with

python3 llvm/buildbot/configure.py --cmake-opt=-DCMAKE_INSTALL_PREFIX=/data/user/fwyzard/sycl/install/sycl-nightly/20230805_160000 -o /data/user/fwyzard/sycl/build/sycl-nightly/20230805_160000 --cmake-gen 'Unix Makefiles' --cuda --cmake-opt=-DCUDA_TOOLKIT_ROOT_DIR=/cvmfs/patatrack.cern.ch/externals/x86_64/rhel8/nvidia/cuda-11.8.0 --hip --hip-platform AMD --cmake-opt=-DSYCL_BUILD_PI_HIP_ROCM_DIR=/cvmfs/patatrack.cern.ch/externals/x86_64/rhel8/amd/rocm-5.4.0 --enable-all-llvm-targets --disable-fusion --shared-libs -t Release
make -C /data/user/fwyzard/sycl/build/sycl-nightly/20230805_160000 -j 24 all sycl-toolchain install

from the commit 8e0cc4b7a845df9389a1313a3e680babc4d87782 corresponding to the tag sycl-nightly/20230805_160000 .

The full build log is attached: build-sycl_nightly_20230805_160000.log.gz .

Environment (please complete the following information):

Additional context The program compiles and runs successfully using oneAPI 2023.2.0, and older versions of the open source SYCL compiler.

fwyzard commented 1 year ago

@AuroraPerego @igorvorobtsov FYI

fwyzard commented 1 year ago

@igorvorobtsov, I've attached a preprocessed file build in a different way:

It can be used like

tar xaf gpuVertexFinder.tgz
clang++ -std=c++17 -O2 -fPIC -fsycl  -Wno-deprecated-declarations -shared gpuVertexFinder.cc -o gpuVertexFinder.so

which fails with

InvalidFunctionCall: Unexpected llvm intrinsic:
 llvm.fptosi.sat.i8.f64 [Src: /data/user/fwyzard/sycl/llvm/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp:4544 false ]
llvm-foreach: 
clang++: error: llvm-spirv command failed with exit code 8 (use -v to see invocation)
fwyzard commented 1 year ago

Sorry, looks like I forgot to attach the archive: gpuVertexFinder.tar.gz .

igorvorobtsov commented 1 year ago

Note that I don't see this problem with icpx nightly build (20230816). However, it still fails with latest open-source build: $ clang++ -std=c++17 -O2 -fPIC -pipe -g -fsycl gpuVertexFinder.cc -shared -o liboutput.so ... InvalidFunctionCall: Unexpected llvm intrinsic: llvm.fptosi.sat.i8.f64 [Src: /nfs/site/home/ivorobts/llvm_21082023/llvm/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp:4458 false ] llvm-foreach: clang++: error: llvm-spirv command failed with exit code 8 (use -v to see invocation) Attaching a smaller one file reproducer (no SYCL and standard library headers preprocessed): clang++ -fPIC -fsycl test.cpp -shared -o liboutput.so

igorvorobtsov commented 1 year ago

test.zip

MrSidims commented 1 year ago

Seems like we can replace call to this intrinsic with OpConvertFToS instruction decorated with SaturatedConversion. Its counterpart llvm.fptoui.sat can be represented with OpConvertFToU with the same decoration.

MrSidims commented 9 months ago

@LU-JOHN has added translation of the intrinsic in the translator in

commit aab0dac9225808840f1c8dbed33ce8b20549ca6e
Author: LU-JOHN <111294400+LU-JOHN@users.noreply.github.com>
Date:   Mon Sep 18 11:14:34 2023 -0500

    Translate llvm.fpto[s|u]i.sat.* intrinsics (#2149)

    Signed-off-by: Lu, John <john.lu@intel.com>

@fwyzard @igorvorobtsov do you still observe that sort of issue or it can be closed?

igorvorobtsov commented 9 months ago

I am not able to reproduce this problem anymore, so, I believe it can be closed.