Skip to content

[Build] Stop CMake riscv64 defaults from clobbering test cpu-features - #24866

Merged
AGindinson merged 2 commits into
iree-org:mainfrom
TMahlatini:users/tmahlatini/riscv-cpu-features-declobber
Sep 25, 2026
Merged

AGindinson merged 2 commits into
iree-org:mainfrom
TMahlatini:users/tmahlatini/riscv-cpu-features-declobber

Conversation

@TMahlatini

@TMahlatini TMahlatini commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

platform cmake defaults were appending --iree-llvmcpu-target-cpu-features= after test variants, so the default overwrote +xsmtvdot / VLEN. this prevents the override of an existing cpu-features flag; prepend missing +m,+a,+f,+d,+c. and strips those from generator --requirements=.

Towards: #24859

@TMahlatini

Copy link
Copy Markdown
Contributor Author

@egebeysel

@AGindinson AGindinson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@TMahlatini sorry for losing track of this one. The PR generally looks good, but there's one clarification point before I understand the purpose and the change fully

Comment thread build_tools/cmake/iree_macros.cmake Outdated
Comment on lines +706 to +741
# Append platform defaults whose option is unset. If cpu-features is
# already set, prepend missing G-extension letters (+m,+a,+f,+d,+c).
foreach(_FLAG IN LISTS _PLATFORM_DEFAULT_LLVM_FLAGS)
if(_FLAG MATCHES "^--iree-llvmcpu-target-cpu-features=(.*)$")
set(_DEFAULT_FEATURES "${CMAKE_MATCH_1}")
if(IN_FLAGS MATCHES "--iree-llvmcpu-target-cpu-features=([^;]+)")
set(_VARIANT_FEATURES "${CMAKE_MATCH_1}")
string(REPLACE "," ";" _DEFAULT_LIST "${_DEFAULT_FEATURES}")
string(REPLACE "," ";" _VARIANT_LIST "${_VARIANT_FEATURES}")
set(_MISSING_G "")
foreach(_F IN LISTS _DEFAULT_LIST)
if(_F MATCHES "^\\+[mafdc]$")
list(FIND _VARIANT_LIST "${_F}" _FOUND)
if(_FOUND EQUAL -1)
list(APPEND _MISSING_G "${_F}")
endif()
endif()
endforeach()
if(_MISSING_G)
list(INSERT _VARIANT_LIST 0 ${_MISSING_G})
list(JOIN _VARIANT_LIST "," _MERGED_FEATURES)
list(APPEND _FLAGS "--iree-llvmcpu-target-cpu-features=${_MERGED_FEATURES}")
endif()
continue()
endif()
list(APPEND _FLAGS "${_FLAG}")
continue()
endif()
if(_FLAG MATCHES "^--([^=]+)=")
set(_OPT "${CMAKE_MATCH_1}")
if(IN_FLAGS MATCHES "${_OPT}")
continue()
endif()
endif()
list(APPEND _FLAGS "${_FLAG}")
endforeach()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TBH I'm struggling to understand what this chunk is doing. RISCV*_TEST_DEFAULT_LLVM_FLAGS doesn't seem to be used anywhere else, so we can't we just statically modify that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

RISCV*_TEST_DEFAULT_LLVM_FLAGS is only read here but each call also gets that test's flags IN_FLAGS. The loop checks whether those already contain --iree-llvmcpu-target-features. a variant sets that flag and not --iree-llvmcpu-target-triple sot the risc-v defaults are still appended after it and the later flag replaces the first. If the test omitted cpu-features, the loop appends the full default, including +zvl512b,+v, if the test set it, default copy is dropped and only missing +m,+a,+f,+d,+c are prepended; copying +zvl512b,+v would clobber VLEN and +xsmtvdot again. A fixed edit of the default string cannot do both

RISCV*_TEST_DEFAULT_LLVM_FLAGS might be the only static edit that stops the second flag, but it also drops rvv from every RISC-V test that does not set features. please let me know if this clarifies.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, that helps!

Just by nature of CMake, the code is difficult to follow, and I wonder if it would be easier to just split --iree-llvmcpu-target-cpu-features=... out from RISCV*_TEST_DEFAULT_LLVM_FLAGS into a separate variable (so we'd end up with smth like TEST_DEFAULT_ABI_FLAGS and TEST_DEFAULT_FEAT_FLAGS), and then paste that whole default string in when the test doesn't specify --iree-llvmcpu-target-features. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah that works actually. Thanks for the suggestion, will update the PR soon

@TMahlatini

Copy link
Copy Markdown
Contributor Author

@TMahlatini sorry for losing track of this one. The PR generally looks good, but there's one clarification point before I understand the purpose and the change fully

Hi @AGindinson sorry I just realized I left out the related issue description in my pr summary. I have just fixed that, you can find the problem definition here: #24866

TMahlatini and others added 2 commits September 24, 2026 20:45
platform cmake defaults were appending --iree-llvmcpu-target-cpu-features=
after test variants, so the default overwrote +xsmtvdot / VLEN. Do not
override an existing cpu-features flag; prepend missing +m,+a,+f,+d,+c.
Strip those from generator --requirements=.

Signed-off-by: Terence <[email protected]>
Co-authored-by: Cursor <[email protected]>
triple and ABI flags are now seperate from the default cpu-feature string which is now only appended when the test did not already set --iree-llvmcpu-target-cpu-features. Variants that need +m,+a,+f,+d,+c
spell them themselves.

Signed-off-by: Terence <[email protected]>
@TMahlatini
TMahlatini force-pushed the users/tmahlatini/riscv-cpu-features-declobber branch from d6be4d4 to 769cf59 Compare September 25, 2026 16:14

@AGindinson AGindinson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for the slight rework!

@AGindinson
AGindinson enabled auto-merge (squash) September 25, 2026 16:31
@AGindinson
AGindinson merged commit 5cf0a12 into iree-org:main Sep 25, 2026
54 checks passed
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.

2 participants