Skip to content

[mlir][Arith] Remove arith-to-llvm from func-to-llvm #120548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

matthias-springer
Copy link
Member

@matthias-springer matthias-springer commented Dec 19, 2024

Do not run arith-to-llvm as part of func-to-llvm. This commit partly fixes #70982.

Also simplify the pass pipeline for two math dialect integration tests.

@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2024

@llvm/pr-subscribers-mlir-spirv
@llvm/pr-subscribers-mlir-core
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-sve

@llvm/pr-subscribers-mlir-llvm

Author: Matthias Springer (matthias-springer)

Changes

Do not run arith-to-llvm as part of func-to-llvm. This commit partly fixes #70982.


Full diff: https://github.com/llvm/llvm-project/pull/120548.diff

5 Files Affected:

  • (modified) mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp (-1)
  • (modified) mlir/test/Dialect/ArmSVE/legalize-for-llvm.mlir (+1-1)
  • (modified) mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp (+3)
  • (modified) mlir/test/mlir-cpu-runner/math-polynomial-approx.mlir (+1-1)
  • (modified) mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir (+1-1)
diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index c046ea1b824fc8..938d7cb9a20040 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -787,7 +787,6 @@ struct ConvertFuncToLLVMPass
 
     // TODO(https://github.com/llvm/llvm-project/issues/70982): Remove these in
     // favor of their dedicated conversion passes.
-    arith::populateArithToLLVMConversionPatterns(typeConverter, patterns);
     cf::populateControlFlowToLLVMConversionPatterns(typeConverter, patterns);
 
     LLVMConversionTarget target(getContext());
diff --git a/mlir/test/Dialect/ArmSVE/legalize-for-llvm.mlir b/mlir/test/Dialect/ArmSVE/legalize-for-llvm.mlir
index 31d5376c32d9c5..bdb69a95a52dee 100644
--- a/mlir/test/Dialect/ArmSVE/legalize-for-llvm.mlir
+++ b/mlir/test/Dialect/ArmSVE/legalize-for-llvm.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -convert-vector-to-llvm="enable-arm-sve" -convert-func-to-llvm -cse -reconcile-unrealized-casts -split-input-file %s | FileCheck %s
+// RUN: mlir-opt -convert-vector-to-llvm="enable-arm-sve" -convert-func-to-llvm -convert-arith-to-llvm -cse -reconcile-unrealized-casts -split-input-file %s | FileCheck %s
 
 func.func @arm_sve_sdot(%a: vector<[16]xi8>,
                    %b: vector<[16]xi8>,
diff --git a/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp b/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
index 10c21612f64ac6..b9033df7fe2b20 100644
--- a/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
+++ b/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "mlir/Conversion/AffineToStandard/AffineToStandard.h"
+#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
 #include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
 #include "mlir/Conversion/IndexToLLVM/IndexToLLVM.h"
 #include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
@@ -73,6 +74,8 @@ void buildTestLowerToLLVM(OpPassManager &pm,
   pm.addPass(createFinalizeMemRefToLLVMConversionPass());
   // Convert Func to LLVM (always needed).
   pm.addPass(createConvertFuncToLLVMPass());
+  // Convert Arith to LLVM (always needed).
+  pm.addPass(createArithToLLVMConversionPass());
   // Convert Index to LLVM (always needed).
   pm.addPass(createConvertIndexToLLVMPass());
   // Convert remaining unrealized_casts (always needed).
diff --git a/mlir/test/mlir-cpu-runner/math-polynomial-approx.mlir b/mlir/test/mlir-cpu-runner/math-polynomial-approx.mlir
index b8861198d596b0..bfd5706580991d 100644
--- a/mlir/test/mlir-cpu-runner/math-polynomial-approx.mlir
+++ b/mlir/test/mlir-cpu-runner/math-polynomial-approx.mlir
@@ -1,4 +1,4 @@
-// RUN:   mlir-opt %s -pass-pipeline="builtin.module(func.func(test-math-polynomial-approximation,convert-arith-to-llvm),convert-vector-to-scf,convert-scf-to-cf,convert-cf-to-llvm,convert-vector-to-llvm,func.func(convert-math-to-llvm),convert-func-to-llvm,reconcile-unrealized-casts)" \
+// RUN:   mlir-opt %s -pass-pipeline="builtin.module(func.func(test-math-polynomial-approximation),convert-vector-to-scf,convert-scf-to-cf,convert-vector-to-llvm,convert-to-llvm,reconcile-unrealized-casts)" \
 // RUN: | mlir-cpu-runner                                                      \
 // RUN:     -e main -entry-point-result=void -O0                               \
 // RUN:     -shared-libs=%mlir_c_runner_utils  \
diff --git a/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir b/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
index 93de767b551769..140b5f43d5eb8f 100644
--- a/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
+++ b/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
@@ -1,4 +1,4 @@
-// RUN:   mlir-opt %s -pass-pipeline="builtin.module(func.func(test-expand-math,convert-arith-to-llvm),convert-vector-to-scf,convert-scf-to-cf,convert-cf-to-llvm,convert-vector-to-llvm,func.func(convert-math-to-llvm),convert-func-to-llvm,reconcile-unrealized-casts)" \
+// RUN:   mlir-opt %s -pass-pipeline="builtin.module(func.func(test-expand-math),convert-vector-to-scf,convert-scf-to-cf,convert-vector-to-llvm,convert-to-llvm,reconcile-unrealized-casts)" \
 // RUN: | mlir-cpu-runner                                                      \
 // RUN:     -e main -entry-point-result=void -O0                               \
 // RUN:     -shared-libs=%mlir_c_runner_utils  \

Copy link
Contributor

@makslevental makslevental left a comment

Choose a reason for hiding this comment

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

LGTM

@zero9178
Copy link
Member

Small heads up: When testing locally on my machine this PR caused crashes in tests for mlir-vulkan-runner that see mrelated:

Failed Tests (13):
  MLIR :: mlir-vulkan-runner/addf.mlir
  MLIR :: mlir-vulkan-runner/addf_if.mlir
  MLIR :: mlir-vulkan-runner/addi.mlir
  MLIR :: mlir-vulkan-runner/addi8.mlir
  MLIR :: mlir-vulkan-runner/addui_extended.mlir
  MLIR :: mlir-vulkan-runner/mulf.mlir
  MLIR :: mlir-vulkan-runner/smul_extended.mlir
  MLIR :: mlir-vulkan-runner/subf.mlir
  MLIR :: mlir-vulkan-runner/time.mlir
  MLIR :: mlir-vulkan-runner/umul_extended.mlir
  MLIR :: mlir-vulkan-runner/vector-deinterleave.mlir
  MLIR :: mlir-vulkan-runner/vector-interleave.mlir
  MLIR :: mlir-vulkan-runner/vector-shuffle.mlir

Error messages are all the same:

FAIL: MLIR :: mlir-vulkan-runner/addui_extended.mlir (13 of 2682)
******************** TEST 'MLIR :: mlir-vulkan-runner/addui_extended.mlir' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 4
g:\clion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\mlir-opt.exe G:\CLion\llvm-project\mlir\test\mlir-vulkan-runner\addui_extended.mlir -test-vulkan-runner-pipeline    | mlir-vulkan-runner -      --shared-libs=G:\CLion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\vulkan-runtime-wrappers.dll,G:\CLion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\mlir_runner_utils.dll      --entry-point-result=void | g:\clion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\filecheck.exe G:\CLion\llvm-project\mlir\test\mlir-vulkan-runner\addui_extended.mlir
# executed command: 'g:\clion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\mlir-opt.exe' 'G:\CLion\llvm-project\mlir\test\mlir-vulkan-runner\addui_extended.mlir' -test-vulkan-runner-pipeline
# executed command: mlir-vulkan-runner - '--shared-libs=G:\CLion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\vulkan-runtime-wrappers.dll,G:\CLion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\mlir_runner_utils.dll' --entry-point-result=void
# .---command stderr------------
# | loc("<stdin>":62:12): error: cannot be converted to LLVM IR: missing `LLVMTranslationDialectInterface` registration for dialect for op: arith.constant
# | Error: could not convert to LLVM IR
# `-----------------------------
# error: command failed with exit status: 1
# executed command: 'g:\clion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\filecheck.exe' 'G:\CLion\llvm-project\mlir\test\mlir-vulkan-runner\addui_extended.mlir'
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  g:\clion\llvm-project\llvm\cmake-build-release-clang-visual-studio\bin\filecheck.exe G:\CLion\llvm-project\mlir\test\mlir-vulkan-runner\addui_extended.mlir
# `-----------------------------
# error: command failed with exit status: 2

Don't think pre-commit will catch this IIRC

@makslevental
Copy link
Contributor

Small heads up: When testing locally on my machine this PR caused crashes in tests for mlir-vulkan-runner that see mrelated:

Failed Tests (13):
  MLIR :: mlir-vulkan-runner/addf.mlir
  MLIR :: mlir-vulkan-runner/addf_if.mlir
  MLIR :: mlir-vulkan-runner/addi.mlir
  MLIR :: mlir-vulkan-runner/addi8.mlir
  MLIR :: mlir-vulkan-runner/addui_extended.mlir
  MLIR :: mlir-vulkan-runner/mulf.mlir
  MLIR :: mlir-vulkan-runner/smul_extended.mlir
  MLIR :: mlir-vulkan-runner/subf.mlir
  MLIR :: mlir-vulkan-runner/time.mlir
  MLIR :: mlir-vulkan-runner/umul_extended.mlir
  MLIR :: mlir-vulkan-runner/vector-deinterleave.mlir
  MLIR :: mlir-vulkan-runner/vector-interleave.mlir
  MLIR :: mlir-vulkan-runner/vector-shuffle.mlir

are these not run pre-commit? I guess not

@matthias-springer matthias-springer force-pushed the users/matthias-springer/arith_to_llvm branch from 0a160d7 to 78704d8 Compare December 20, 2024 09:00
@matthias-springer matthias-springer force-pushed the users/matthias-springer/arith_to_llvm branch from 78704d8 to 6e95065 Compare December 20, 2024 09:01
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir:spirv labels Dec 20, 2024
@matthias-springer matthias-springer merged commit 53d080c into main Dec 20, 2024
8 of 9 checks passed
@matthias-springer matthias-springer deleted the users/matthias-springer/arith_to_llvm branch December 20, 2024 09:14
@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 20, 2024

LLVM Buildbot has detected a new failure on builder mlir-rocm-mi200 running on mi200-buildbot while building mlir at step 7 "test-build-check-mlir-build-only-check-mlir".

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

Here is the relevant piece of the build log for the reference
Step 7 (test-build-check-mlir-build-only-check-mlir) failure: test (failure)
******************** TEST 'MLIR :: Integration/Dialect/ControlFlow/assert.mlir' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/ControlFlow/assert.mlir -test-cf-assert      -convert-func-to-llvm |  /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-cpu-runner -e main -entry-point-result=void |  /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/FileCheck /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/ControlFlow/assert.mlir
# executed command: /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/ControlFlow/assert.mlir -test-cf-assert -convert-func-to-llvm
# executed command: /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-cpu-runner -e main -entry-point-result=void
# .---command stderr------------
# | loc("<stdin>":6:14): error: Dialect `arith' not found for custom op 'arith.constant' 
# | could not parse the input IR
# `-----------------------------
# error: command failed with exit status: 1
# executed command: /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/FileCheck /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/ControlFlow/assert.mlir
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/FileCheck /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/ControlFlow/assert.mlir
# `-----------------------------
# error: command failed with exit status: 2

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 20, 2024

LLVM Buildbot has detected a new failure on builder mlir-nvidia-gcc7 running on mlir-nvidia while building mlir at step 7 "test-build-check-mlir-build-only-check-mlir".

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

Here is the relevant piece of the build log for the reference
Step 7 (test-build-check-mlir-build-only-check-mlir) failure: test (failure)
******************** TEST 'MLIR :: Integration/Dialect/ControlFlow/assert.mlir' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/mlir-opt /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/ControlFlow/assert.mlir -test-cf-assert      -convert-func-to-llvm |  /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/mlir-cpu-runner -e main -entry-point-result=void |  /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/ControlFlow/assert.mlir
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/mlir-opt /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/ControlFlow/assert.mlir -test-cf-assert -convert-func-to-llvm
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/mlir-cpu-runner -e main -entry-point-result=void
# .---command stderr------------
# | loc("<stdin>":6:14): error: Dialect `arith' not found for custom op 'arith.constant' 
# | could not parse the input IR
# `-----------------------------
# error: command failed with exit status: 1
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/ControlFlow/assert.mlir
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/ControlFlow/assert.mlir
# `-----------------------------
# error: command failed with exit status: 2

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 20, 2024

LLVM Buildbot has detected a new failure on builder mlir-nvidia running on mlir-nvidia while building mlir at step 7 "test-build-check-mlir-build-only-check-mlir".

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

Here is the relevant piece of the build log for the reference
Step 7 (test-build-check-mlir-build-only-check-mlir) failure: test (failure)
******************** TEST 'MLIR :: Integration/Dialect/Async/CPU/microbench-scf-async-parallel-for.mlir' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/Dialect/Async/CPU/microbench-scf-async-parallel-for.mlir                                                                         -async-parallel-for                                                     -async-to-async-runtime                                                 -async-runtime-ref-counting                                             -async-runtime-ref-counting-opt                                         -convert-async-to-llvm                                                  -convert-linalg-to-loops                                                -convert-scf-to-cf                                                     -arith-expand                                                           -memref-expand                                                             -convert-vector-to-llvm                                                 -finalize-memref-to-llvm                                                 -convert-func-to-llvm                                                    -reconcile-unrealized-casts                               | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-cpu-runner                                                       -e entry -entry-point-result=void -O3                                   -shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_runner_utils.so   -shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_c_runner_utils.so -shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_async_runtime.so  | /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/Dialect/Async/CPU/microbench-scf-async-parallel-for.mlir --dump-input=always
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-opt /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/Dialect/Async/CPU/microbench-scf-async-parallel-for.mlir -async-parallel-for -async-to-async-runtime -async-runtime-ref-counting -async-runtime-ref-counting-opt -convert-async-to-llvm -convert-linalg-to-loops -convert-scf-to-cf -arith-expand -memref-expand -convert-vector-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/mlir-cpu-runner -e entry -entry-point-result=void -O3 -shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_runner_utils.so -shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_c_runner_utils.so -shared-libs=/vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/lib/libmlir_async_runtime.so
# .---command stderr------------
# | loc("<stdin>":27:12): error: Dialect `arith' not found for custom op 'arith.constant' 
# | could not parse the input IR
# `-----------------------------
# error: command failed with exit status: 1
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/Dialect/Async/CPU/microbench-scf-async-parallel-for.mlir --dump-input=always
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /vol/worker/mlir-nvidia/mlir-nvidia/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/test/Integration/Dialect/Async/CPU/microbench-scf-async-parallel-for.mlir --dump-input=always
# `-----------------------------
# error: command failed with exit status: 2

--

********************


matthias-springer added a commit that referenced this pull request Dec 20, 2024
This should have been part of #120548.
matthias-springer added a commit that referenced this pull request Dec 20, 2024
qiaojbao pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Feb 7, 2025
Local branch amd-gfx f0fbc98 Merged main:93743ee56669 into amd-gfx:ab47d36e0ead
Remote branch main 53d080c [mlir][Arith] Remove `arith-to-llvm` from `func-to-llvm` (llvm#120548)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mlir]: Remove arith/cf converion patterns from FuncToLLVM.cpp
6 participants