This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Fix for MSVC bool splat issue encountered in Windows Bazel build
ClosedPublic

Authored by GleasonK on Jul 19 2023, 1:12 PM.

Details

Summary

When building MLIR using bazel on windows with MSVC2019, bool splats
were being created incorrectly:

dense<[true,true,true,true]> : tensor<4xi1>
-(parse with mlir-opt)-> dense<[true, false, false, false]> : tensor<4xi1>

Appears that a windows bazel build produces a corrupt DenseIntOrFPElementsAttr.
Not able to repro using MSVC with cmake.

Issue first discovered here:
https://github.com/google/jax/issues/16394

Added test point for reproduction:

$ bazel test @llvm-project//mlir/unittests:ir_tests --test_arg=--gtest_filter=DenseSplatTest.BoolSplatSmall

Diff Detail

Event Timeline

GleasonK created this revision.Jul 19 2023, 1:12 PM
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
GleasonK published this revision for review.Jul 19 2023, 1:15 PM
rriddle added inline comments.Jul 19 2023, 1:21 PM
mlir/lib/IR/AttributeDetail.h
196–204

Could we just switch to using an enum for this?

GleasonK added inline comments.Jul 19 2023, 1:54 PM
mlir/lib/IR/AttributeDetail.h
196–204

Meaning switch from using these constexpr values to enum values? I believe the reason static member variables are used is since KeyTy gets passed around, but uses an ArrayRef<char> for data, so needs these values to persist between calls to getKey and uses of the key, like construct.

rriddle added inline comments.Jul 19 2023, 1:59 PM
mlir/lib/IR/AttributeDetail.h
196–204

Yeah, I'm paging back in why I even wrote it this way in the first place. Do we need to if/def _MSC_VER? Can we just align around that version?

jpienaar added inline comments.Jul 19 2023, 3:31 PM
mlir/lib/IR/AttributeDetail.h
196–204

I think just for discussion, I think we should just have one here. I almost wonder if we should just use pre-C++17 approach of static const char declaration here and definition in body. (apparently this failed with const added MSC_VER side)

GleasonK added inline comments.Jul 19 2023, 4:05 PM
mlir/lib/IR/AttributeDetail.h
196–204

(apparently this failed with const added MSC_VER side)

That's correct, even static inline const char failed as well.

I almost wonder if we should just use pre-C++17 approach of static const char declaration here and definition in body.

Just confirmed that this works, tested by putting the definition in BuiltinAttributes.cpp and changed this to just declaration. This is probably a better solution to align on than what I have coded up now, since these member variables really should be const.

GleasonK updated this revision to Diff 542987.Jul 21 2023, 10:39 AM

Use pre-C++17 declaration for static member variables for splats

GleasonK updated this revision to Diff 542989.Jul 21 2023, 10:49 AM
  • Use pre-C++17 declaration of static member variables for splats
  • clang-format
GleasonK edited the summary of this revision. (Show Details)Jul 24 2023, 12:32 PM
GleasonK retitled this revision from [mlir] Fix for MSVC bool splat issue encountered in JAX to [mlir] Fix for MSVC bool splat issue encountered in Windows Bazel build.
jpienaar accepted this revision.Jul 24 2023, 8:44 PM
This revision is now accepted and ready to land.Jul 24 2023, 8:44 PM
This revision was automatically updated to reflect the committed changes.
mlir/unittests/IR/AttributeTest.cpp