Skip to content

[mlir] Ensure fmaximum/fminimum is defined in mlir/Dialect/LLVMIR/LLVMEnums.td #138198

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 2 commits into from
May 2, 2025

Conversation

jthackray
Copy link
Contributor

Fix a compile error (with LLVM_ENABLE_WERROR=On) when building bin/flang:

   enumeration values 'FMaximum' and 'FMinimum' not handled in switch

caused by adding new LLVM IR instructions in #137701.

This wasn't picked up by the auto CI builders on GitHub, so I hadn't
realised until @kazutakahirata notified me about it.

…tions in #137701

Fix a compile error (with LLVM_ENABLE_WERROR=On) when building `bin/flang`:
```
   enumeration values 'FMaximum' and 'FMinimum' not handled in switch
```
caused by adding new LLVM IR instructions in #137701.

This wasn't picked up by the auto CI test on GitHub, so I hadn't
realised until @kazutakahirata notified me about it.
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-mlir-llvm

@llvm/pr-subscribers-mlir

Author: Jonathan Thackray (jthackray)

Changes

Fix a compile error (with LLVM_ENABLE_WERROR=On) when building bin/flang:

   enumeration values 'FMaximum' and 'FMinimum' not handled in switch

caused by adding new LLVM IR instructions in #137701.

This wasn't picked up by the auto CI builders on GitHub, so I hadn't
realised until @kazutakahirata notified me about it.


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

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td (+4-1)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
index 6c0fe363d5551..596f562911f8f 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
@@ -110,6 +110,8 @@ def AtomicBinOpUSubCond : LLVM_EnumAttrCase<"usub_cond",
                                             "usub_cond", "USubCond", 17>;
 def AtomicBinOpUSubSat : LLVM_EnumAttrCase<"usub_sat",
                                            "usub_sat", "USubSat", 18>;
+def AtomicBinOpFMaximum : LLVM_EnumAttrCase<"fmaximum", "fmaximum", "FMaximum", 19>;
+def AtomicBinOpFMinimum : LLVM_EnumAttrCase<"fminimum", "fminimum", "FMinimum", 20>;
 
 // A sentinel value that has no MLIR counterpart.
 def AtomicBadBinOp : LLVM_EnumAttrCase<"", "", "BAD_BINOP", 0>;
@@ -122,7 +124,8 @@ def AtomicBinOp : LLVM_EnumAttr<
      AtomicBinOpNand, AtomicBinOpOr, AtomicBinOpXor, AtomicBinOpMax,
      AtomicBinOpMin, AtomicBinOpUMax, AtomicBinOpUMin, AtomicBinOpFAdd,
      AtomicBinOpFSub, AtomicBinOpFMax, AtomicBinOpFMin, AtomicBinOpUIncWrap,
-     AtomicBinOpUDecWrap, AtomicBinOpUSubCond, AtomicBinOpUSubSat],
+     AtomicBinOpUDecWrap, AtomicBinOpUSubCond, AtomicBinOpUSubSat,
+     AtomicBinOpFMaximum, AtomicBinOpFMinimum],
     [AtomicBadBinOp]> {
   let cppNamespace = "::mlir::LLVM";
 }

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

Probably should have tests showing this translates correctly?

Copy link
Contributor

@krzysz00 krzysz00 left a comment

Choose a reason for hiding this comment

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

Approved

Can you do me a favor and have a followup PR where you hook these up to memref.atomicrmw?

@krzysz00
Copy link
Contributor

krzysz00 commented May 1, 2025

(Huh, yeah, should have a test)

@jthackray
Copy link
Contributor Author

Probably should have tests showing this translates correctly?

Thanks @arsenm. I'm not familiar with where existing tests for other atomics are tested in this way. Can you point them out to me? Thanks.

@jthackray
Copy link
Contributor Author

Can you do me a favor and have a followup PR where you hook these up to memref.atomicrmw?

@krzysz00 - sure, not sure exactly how to do that, but I'll give it a try tomorrow.

@arsenm
Copy link
Contributor

arsenm commented May 1, 2025

Probably should have tests showing this translates correctly?

Thanks @arsenm. I'm not familiar with where existing tests for other atomics are tested in this way. Can you point them out to me? Thanks.

I don't know how to mlir, but I would hope there is an existing test to adjust. the closest match grep finds is mlir/test/Target/LLVMIR/llvmir.mlir? seems to cover too much, but has most atomicrmw ops covered

@krzysz00
Copy link
Contributor

krzysz00 commented May 1, 2025

The tests are in mlir/test/Target/LLVMIR/ - llvmir.mlir has the export tests and import.ll has the import tests. There's a bunch of other llvm.atomicrmw in there

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

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

Thank you for reproducing and fixing the problem quickly!

@jthackray
Copy link
Contributor Author

Thank you for reproducing and fixing the problem quickly!

No problem - sorry I didn't see your original comment 17 hours ago. This won't get merged until tomorrow and I've added tests - hope you can wait until then. You can manually apply my patch to your local build if you need it sooner.

@jthackray
Copy link
Contributor Author

Thanks for the pointers, @arsenm @krzysz00 - I've added some extra tests now.

Copy link

github-actions bot commented May 1, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@jthackray jthackray force-pushed the users/jthackray/fix-flang-build branch from 2db656e to 1853659 Compare May 1, 2025 22:59
@jthackray jthackray changed the title [flang] Fix build issue in flang caused by adding new LLVM IR instructions in #137701 [flang] Ensure fmaximum/fminimum is defined in mlir/Dialect/LLVMIR/LLVMEnums.td May 1, 2025
@jthackray jthackray changed the title [flang] Ensure fmaximum/fminimum is defined in mlir/Dialect/LLVMIR/LLVMEnums.td [mlir] Ensure fmaximum/fminimum is defined in mlir/Dialect/LLVMIR/LLVMEnums.td May 1, 2025
@jthackray jthackray merged commit 6f39995 into main May 2, 2025
11 checks passed
@jthackray jthackray deleted the users/jthackray/fix-flang-build branch May 2, 2025 06:02
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.

5 participants