Skip to content

Conversation

@ianayl
Copy link
Contributor

@ianayl ianayl commented Oct 10, 2025

This PR is a fix for #159878, which failed in postcommit testing due to linker errors that were not caught in precommit.

Original PR:


This PR introduces a MathToXeVM pass, which implements support for the afn fastmath flag for SPIRV/XeVM targets - It takes supported Math Ops with the afn flag, and converts them to function calls to OpenCL native_ intrinsics.

These intrinsic functions are supported by the SPIRV backend, and are automatically converted to OpExtInst calls to native_ ops from the OpenCL SPIRV ext. inst. set when outputting to SPIRV/XeVM.

Note:

  • This pass also supports converting arith.divf to native equivalents. There is an option provided in the pass to turn this behavior off.
  • This pass preserves fastmath flags, but these flags are currently ignored by the SPIRV backend. Thus, in order to generate SPIRV that truly preserves fastmath flags, support needs to be added to the SPIRV backend.

@ianayl
Copy link
Contributor Author

ianayl commented Oct 10, 2025

Sidenote: Is there a way to trigger the postcommit runner tests before merging? I was able to replicate the issue and fix it on my local machine, but nonetheless confirmation would be helpful.

@charithaintc
Copy link
Contributor

I can see all the changes in this PR. I think you need to either revert the previous PR and apply this or only add the missing link libraries.

@ianayl
Copy link
Contributor Author

ianayl commented Oct 10, 2025

I can see all the changes in this PR. I think you need to either revert the previous PR and apply this or only add the missing link libraries.

A revert was merged at #162923, I think I have to land my prior PR again

@charithaintc
Copy link
Contributor

I can see all the changes in this PR. I think you need to either revert the previous PR and apply this or only add the missing link libraries.

A revert was merged at #162923, I think I have to land my prior PR again

ah great. thanks!

Tip: you can avoid linking issues by doing a local shared_lib build. -DBUILD_SHARED_LIBS=ON

@ianayl
Copy link
Contributor Author

ianayl commented Oct 10, 2025

I can see all the changes in this PR. I think you need to either revert the previous PR and apply this or only add the missing link libraries.

A revert was merged at #162923, I think I have to land my prior PR again

ah great. thanks!

Tip: you can avoid linking issues by doing a local shared_lib build. -DBUILD_SHARED_LIBS=ON

Thank you for the tip, I unfortunately had to learn this the hard way 😅 It builds now with BUILD_SHARED_LIBS=ON

Are there anything else that I should watch out for?

@charithaintc
Copy link
Contributor

I can see all the changes in this PR. I think you need to either revert the previous PR and apply this or only add the missing link libraries.

A revert was merged at #162923, I think I have to land my prior PR again

ah great. thanks!
Tip: you can avoid linking issues by doing a local shared_lib build. -DBUILD_SHARED_LIBS=ON

Thank you for the tip, I unfortunately had to learn this the hard way 😅 It builds now with BUILD_SHARED_LIBS=ON

Are there anything else that I should watch out for?

AFAIK That's all you can do + PR CI.

sometimes it can still fail in post merge CI. for those the only solution is to revert unfortunately.

@ianayl
Copy link
Contributor Author

ianayl commented Oct 10, 2025

Please let me do a double-check first: I will ask for the PR to be merged after I run through everything a second time.

Checked everything over one last time, PR should be good now to merge

@mshahneo mshahneo merged commit 3f3ffed into llvm:main Oct 14, 2025
10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 14, 2025

LLVM Buildbot has detected a new failure on builder ppc64le-mlir-rhel-clang running on ppc64le-mlir-rhel-test while building mlir at step 3 "clean-build-dir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/31408

Here is the relevant piece of the build log for the reference
Step 3 (clean-build-dir) failure: Delete failed. (failure) (timed out)
Step 4 (cmake-configure) failure: cmake (failure) (timed out)
command timed out: 1200 seconds without output running [b'cmake', b'-DLLVM_TARGETS_TO_BUILD=PowerPC', b'-DLLVM_INSTALL_UTILS=ON', b'-DCMAKE_CXX_STANDARD=17', b'-DLLVM_ENABLE_PROJECTS=mlir', b'-DLLVM_LIT_ARGS=-vj 256', b'-DCMAKE_C_COMPILER_LAUNCHER=ccache', b'-DCMAKE_CXX_COMPILER_LAUNCHER=ccache', b'-DCMAKE_BUILD_TYPE=Release', b'-DLLVM_ENABLE_ASSERTIONS=ON', b'-GNinja', b'../llvm-project/llvm'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1200.566415

@ianayl
Copy link
Contributor Author

ianayl commented Oct 14, 2025

Step 3 (clean-build-dir) failure: Delete failed. (failure) (timed out) Step 4 (cmake-configure) failure: cmake (failure) (timed out) command timed out: 1200 seconds without output running [b'cmake', b'-DLLVM_TARGETS_TO_BUILD=PowerPC', b'-DLLVM_INSTALL_UTILS=ON', b'-DCMAKE_CXX_STANDARD=17', b'-DLLVM_ENABLE_PROJECTS=mlir', b'-DLLVM_LIT_ARGS=-vj 256', b'-DCMAKE_C_COMPILER_LAUNCHER=ccache', b'-DCMAKE_CXX_COMPILER_LAUNCHER=ccache', b'-DCMAKE_BUILD_TYPE=Release', b'-DLLVM_ENABLE_ASSERTIONS=ON', b'-GNinja', b'../llvm-project/llvm'], attempting to kill

AFAICT this seems to be a CI issue; the same command runs fine on my machine. Please let me know if there are problems however.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 14, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-bootstrap-asan running on sanitizer-buildbot1 while building mlir at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/52/builds/11940

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using ld.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:74: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 92650 tests, 64 workers --
Testing:  0.. 10.. 20
FAIL: Clang-Unit :: Basic/./BasicTests/38/97 (23500 of 92650)
******************** TEST 'Clang-Unit :: Basic/./BasicTests/38/97' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/unittests/Basic/./BasicTests-Clang-Unit-1169183-38-97.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=97 GTEST_SHARD_INDEX=38 /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/unittests/Basic/./BasicTests
--

Note: This is test shard 39 of 97.
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from SuppressionMappingTest
[ RUN      ] SuppressionMappingTest.LongestMatchWins

--
exit: 1
--
shard JSON output does not exist: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/unittests/Basic/./BasicTests-Clang-Unit-1169183-38-97.json
********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
134.56s: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir
127.67s: Clang :: Driver/fsanitize.c
81.23s: Clang :: Driver/arm-cortex-cpus-2.c
80.29s: Clang :: Preprocessor/riscv-target-features.c
79.38s: Clang :: Driver/arm-cortex-cpus-1.c
76.84s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
75.76s: Clang :: OpenMP/target_update_codegen.cpp
68.56s: Clang :: Preprocessor/arm-target-features.c
68.25s: Clang :: Preprocessor/aarch64-target-features.c
63.70s: LLVM :: CodeGen/AMDGPU/amdgcn.bitcast.1024bit.ll
58.33s: LLVM :: CodeGen/RISCV/attributes.ll
58.00s: Clang :: Preprocessor/predefined-arch-macros.c
54.31s: Clang :: Driver/linux-ld.c
50.54s: Clang :: Driver/clang_f_opts.c
48.63s: Clang :: Analysis/a_flaky_crash.cpp
47.98s: Clang :: Driver/cl-options.c
43.21s: Clang :: Driver/x86-target-features.c
41.62s: Clang :: Driver/range-warnings.c
Step 11 (stage2/asan check) failure: stage2/asan check (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using ld.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:74: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 92650 tests, 64 workers --
Testing:  0.. 10.. 20
FAIL: Clang-Unit :: Basic/./BasicTests/38/97 (23500 of 92650)
******************** TEST 'Clang-Unit :: Basic/./BasicTests/38/97' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/unittests/Basic/./BasicTests-Clang-Unit-1169183-38-97.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=97 GTEST_SHARD_INDEX=38 /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/unittests/Basic/./BasicTests
--

Note: This is test shard 39 of 97.
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from SuppressionMappingTest
[ RUN      ] SuppressionMappingTest.LongestMatchWins

--
exit: 1
--
shard JSON output does not exist: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/unittests/Basic/./BasicTests-Clang-Unit-1169183-38-97.json
********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
134.56s: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir
127.67s: Clang :: Driver/fsanitize.c
81.23s: Clang :: Driver/arm-cortex-cpus-2.c
80.29s: Clang :: Preprocessor/riscv-target-features.c
79.38s: Clang :: Driver/arm-cortex-cpus-1.c
76.84s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
75.76s: Clang :: OpenMP/target_update_codegen.cpp
68.56s: Clang :: Preprocessor/arm-target-features.c
68.25s: Clang :: Preprocessor/aarch64-target-features.c
63.70s: LLVM :: CodeGen/AMDGPU/amdgcn.bitcast.1024bit.ll
58.33s: LLVM :: CodeGen/RISCV/attributes.ll
58.00s: Clang :: Preprocessor/predefined-arch-macros.c
54.31s: Clang :: Driver/linux-ld.c
50.54s: Clang :: Driver/clang_f_opts.c
48.63s: Clang :: Analysis/a_flaky_crash.cpp
47.98s: Clang :: Driver/cl-options.c
43.21s: Clang :: Driver/x86-target-features.c
41.62s: Clang :: Driver/range-warnings.c

@ianayl
Copy link
Contributor Author

ianayl commented Oct 14, 2025

Sanitizer failures can also be observed in other PRs: #163302

Neither my commit nor the mentioned commit has anything to do with clang, failure should be unrelated.

rupprecht added a commit to rupprecht/llvm-project that referenced this pull request Oct 14, 2025
rupprecht added a commit that referenced this pull request Oct 14, 2025
akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
…62934)

This PR is a fix for llvm#159878,
which failed in postcommit testing due to linker errors that were not
caught in precommit.

Original PR:

---

This PR introduces a `MathToXeVM` pass, which implements support for the
`afn` fastmath flag for SPIRV/XeVM targets - It takes supported `Math`
Ops with the `afn` flag, and converts them to function calls to OpenCL
`native_` intrinsics.

These intrinsic functions are supported by the SPIRV backend, and are
automatically converted to `OpExtInst` calls to `native_` ops from the
OpenCL SPIRV ext. inst. set when outputting to SPIRV/XeVM.

Note:
- This pass also supports converting `arith.divf` to native equivalents.
There is an option provided in the pass to turn this behavior off.
- This pass preserves fastmath flags, but these flags are currently
ignored by the SPIRV backend. Thus, in order to generate SPIRV that
truly preserves fastmath flags, support needs to be added to the SPIRV
backend.
akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
rupprecht added a commit that referenced this pull request Oct 15, 2025
This passes buildkite CI, but fails downstream if the SPIRV target is
not enabled.

This is needed after #162934
@@ -0,0 +1,118 @@
// RUN: mlir-opt %s -gpu-module-to-binary="format=isa" \
// RUN: -debug-only=serialize-to-isa 2> %t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed eca6144 to fix this test in release builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants