llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow SSE/AVX COMI/UCOMI/CMPS/CMPP fp comparison intrinsics to be used in constexpr

Open RKSimon opened this issue 3 months ago • 9 comments

The float/double/half scalar / vector comparison intrinsics can all be handled in constant expressions, accounting for special handling of NAN inputs.

_mm_comieq_ss   _mm_comieq_sd   _mm_comieq_sh
_mm_comige_ss   _mm_comige_sd   _mm_comige_sh
_mm_comigt_ss   _mm_comigt_sd   _mm_comigt_sh
_mm_comile_ss   _mm_comile_sd   _mm_comile_sh
_mm_comilt_ss   _mm_comilt_sd   _mm_comilt_sh
_mm_comineq_ss  _mm_comineq_sd  _mm_comineq_sh
_mm_ucomieq_ss  _mm_ucomieq_sd  _mm_ucomieq_sh
_mm_ucomige_ss  _mm_ucomige_sd  _mm_ucomige_sh
_mm_ucomigt_ss  _mm_ucomigt_sd  _mm_ucomigt_sh
_mm_ucomile_ss  _mm_ucomile_sd  _mm_ucomile_sh
_mm_ucomilt_ss  _mm_ucomilt_sd  _mm_ucomilt_sh 
_mm_ucomineq_ss _mm_ucomineq_sd _mm_ucomineq_sh
_mm_comi_sh

_mm_cmpeq_ss    _mm_cmpeq_sd    _mm_cmpeq_ps    _mm_cmpeq_pd
_mm_cmpge_ss    _mm_cmpge_sd    _mm_cmpge_ps    _mm_cmpge_pd
_mm_cmpgt_ss    _mm_cmpgt_sd    _mm_cmpgt_ps    _mm_cmpgt_pd
_mm_cmple_ss    _mm_cmple_sd    _mm_cmple_ps    _mm_cmple_pd
_mm_cmplt_ss    _mm_cmplt_sd    _mm_cmplt_ps    _mm_cmplt_pd
_mm_cmpneq_ss   _mm_cmpneq_sd   _mm_cmpneq_ps   _mm_cmpneq_pd
_mm_cmpnge_ss   _mm_cmpnge_sd   _mm_cmpnge_ps   _mm_cmpnge_pd
_mm_cmpngt_ss   _mm_cmpngt_sd   _mm_cmpngt_ps   _mm_cmpngt_pd
_mm_cmpnle_ss   _mm_cmpnle_sd   _mm_cmpnle_ps   _mm_cmpnle_pd
_mm_cmpnlt_ss   _mm_cmpnlt_sd   _mm_cmpnlt_ps   _mm_cmpnlt_pd
_mm_cmpord_ss   _mm_cmpord_sd   _mm_cmpord_ps   _mm_cmpord_pd
_mm_cmpunord_ss _mm_cmpunord_sd _mm_cmpunord_ps _mm_cmpunord_pd

_mm_cmp_ss _mm_cmp_sd 
_mm_cmp_ps _mm256_cmp_ps
_mm_cmp_pd _mm256_cmp_pd

RKSimon avatar Sep 24 '25 09:09 RKSimon

@llvm/issue-subscribers-backend-x86

Author: Simon Pilgrim (RKSimon)

The float/double/half scalar / vector comparison intrinsics can all be handled in constant expressions, accounting for special handling of NAN inputs. ``` _mm_comieq_ss _mm_comieq_sd _mm_comieq_sh _mm_comige_ss _mm_comige_sd _mm_comige_sh _mm_comigt_ss _mm_comigt_sd _mm_comigt_sh _mm_comile_ss _mm_comile_sd _mm_comile_sh _mm_comilt_ss _mm_comilt_sd _mm_comilt_sh _mm_comineq_ss _mm_comineq_sd _mm_comineq_sh _mm_ucomieq_ss _mm_ucomieq_sd _mm_ucomieq_sh _mm_ucomige_ss _mm_ucomige_sd _mm_ucomige_sh _mm_ucomigt_ss _mm_ucomigt_sd _mm_ucomigt_sh _mm_ucomile_ss _mm_ucomile_sd _mm_ucomile_sh _mm_ucomilt_ss _mm_ucomilt_sd _mm_ucomilt_sh _mm_ucomineq_ss _mm_ucomineq_sd _mm_ucomineq_sh _mm_comi_sh

_mm_cmpeq_ss _mm_cmpeq_sd _mm_cmpeq_ps _mm_cmpeq_pd _mm_cmpge_ss _mm_cmpge_sd _mm_cmpge_ps _mm_cmpge_pd _mm_cmpgt_ss _mm_cmpgt_sd _mm_cmpgt_ps _mm_cmpgt_pd _mm_cmple_ss _mm_cmple_sd _mm_cmple_ps _mm_cmple_pd _mm_cmplt_ss _mm_cmplt_sd _mm_cmplt_ps _mm_cmplt_pd _mm_cmpneq_ss _mm_cmpneq_sd _mm_cmpneq_ps _mm_cmpneq_pd _mm_cmpnge_ss _mm_cmpnge_sd _mm_cmpnge_ps _mm_cmpnge_pd _mm_cmpngt_ss _mm_cmpngt_sd _mm_cmpngt_ps _mm_cmpngt_pd _mm_cmpnle_ss _mm_cmpnle_sd _mm_cmpnle_ps _mm_cmpnle_pd _mm_cmpnlt_ss _mm_cmpnlt_sd _mm_cmpnlt_ps _mm_cmpnlt_pd _mm_cmpord_ss _mm_cmpord_sd _mm_cmpord_ps _mm_cmpord_pd _mm_cmpunord_ss _mm_cmpunord_sd _mm_cmpunord_ps _mm_cmpunord_pd

_mm_cmp_ss _mm_cmp_sd _mm_cmp_ps _mm256_cmp_ps _mm_cmp_pd _mm256_cmp_pd

</details>

llvmbot avatar Sep 24 '25 09:09 llvmbot

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
  2. Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

llvmbot avatar Sep 24 '25 09:09 llvmbot

@llvm/issue-subscribers-good-first-issue

Author: Simon Pilgrim (RKSimon)

The float/double/half scalar / vector comparison intrinsics can all be handled in constant expressions, accounting for special handling of NAN inputs. ``` _mm_comieq_ss _mm_comieq_sd _mm_comieq_sh _mm_comige_ss _mm_comige_sd _mm_comige_sh _mm_comigt_ss _mm_comigt_sd _mm_comigt_sh _mm_comile_ss _mm_comile_sd _mm_comile_sh _mm_comilt_ss _mm_comilt_sd _mm_comilt_sh _mm_comineq_ss _mm_comineq_sd _mm_comineq_sh _mm_ucomieq_ss _mm_ucomieq_sd _mm_ucomieq_sh _mm_ucomige_ss _mm_ucomige_sd _mm_ucomige_sh _mm_ucomigt_ss _mm_ucomigt_sd _mm_ucomigt_sh _mm_ucomile_ss _mm_ucomile_sd _mm_ucomile_sh _mm_ucomilt_ss _mm_ucomilt_sd _mm_ucomilt_sh _mm_ucomineq_ss _mm_ucomineq_sd _mm_ucomineq_sh _mm_comi_sh

_mm_cmpeq_ss _mm_cmpeq_sd _mm_cmpeq_ps _mm_cmpeq_pd _mm_cmpge_ss _mm_cmpge_sd _mm_cmpge_ps _mm_cmpge_pd _mm_cmpgt_ss _mm_cmpgt_sd _mm_cmpgt_ps _mm_cmpgt_pd _mm_cmple_ss _mm_cmple_sd _mm_cmple_ps _mm_cmple_pd _mm_cmplt_ss _mm_cmplt_sd _mm_cmplt_ps _mm_cmplt_pd _mm_cmpneq_ss _mm_cmpneq_sd _mm_cmpneq_ps _mm_cmpneq_pd _mm_cmpnge_ss _mm_cmpnge_sd _mm_cmpnge_ps _mm_cmpnge_pd _mm_cmpngt_ss _mm_cmpngt_sd _mm_cmpngt_ps _mm_cmpngt_pd _mm_cmpnle_ss _mm_cmpnle_sd _mm_cmpnle_ps _mm_cmpnle_pd _mm_cmpnlt_ss _mm_cmpnlt_sd _mm_cmpnlt_ps _mm_cmpnlt_pd _mm_cmpord_ss _mm_cmpord_sd _mm_cmpord_ps _mm_cmpord_pd _mm_cmpunord_ss _mm_cmpunord_sd _mm_cmpunord_ps _mm_cmpunord_pd

_mm_cmp_ss _mm_cmp_sd _mm_cmp_ps _mm256_cmp_ps _mm_cmp_pd _mm256_cmp_pd

</details>

llvmbot avatar Sep 24 '25 09:09 llvmbot

Hi, @RKSimon. I'd like to work on this, can you assign this to me?

zeyi2 avatar Sep 24 '25 09:09 zeyi2

Hi, I opened a draft PR to track progress on adding constexpr support. At the moment my availability is limited, so it may take some time before this is fully ready for review. In the meantime, any early feedback on the overall approach would be greatly appreciated.

zeyi2 avatar Sep 26 '25 11:09 zeyi2

@RKSimon Hi, sorry for bothering you. I recently implemented mm(256)_cmp_ss/sd/ps/pd. But I'm not entirely entirely sure if my approach is consistent with the project. Could you kindly take a look when you have a chance? Thanks a lot for your time.

zeyi2 avatar Oct 08 '25 14:10 zeyi2

Hi, I've been busy with tasks in other parts of LLVM and likely won't be able to complete this issue in a reasonable timeframe, so I'm going to unassign myself. Apologies for the delay and any inconvenience caused.

If anyone would like to pick up this issue, please feel free to do so. My draft PR for this issue contains a partially completed implementation of the instructions that might be useful as a reference.

zeyi2 avatar Dec 09 '25 10:12 zeyi2

Hi can I work on this one?

Red-RobinHood avatar Dec 13 '25 18:12 Red-RobinHood

Hi so I have some other engagements I need to see at the moment so will not be able to work actively if anyone else wants to work on this in the meantime feel free to take it up

Red-RobinHood avatar Dec 17 '25 13:12 Red-RobinHood