Skip to content

[RISCV] Add new tests for RISCV zicond extension #143580

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
Jun 12, 2025

Conversation

bababuck
Copy link
Contributor

I have a few patches to improve compilation for these tests which I will be posting as separate MRs.

@bababuck
Copy link
Contributor Author

@mgudim

@topperc
Copy link
Collaborator

topperc commented Jun 10, 2025

Please test +xventanacondops too. They have identical semantics to Zicond and all code paths affect that extension too.

@mgudim
Copy link
Contributor

mgudim commented Jun 10, 2025

Please test +xventanacondops too. They have identical semantics to Zicond and all code paths affect that extension too.

We plan to remove 'xventanacondops' and just go with zicondops

@topperc
Copy link
Collaborator

topperc commented Jun 10, 2025

Please test +xventanacondops too. They have identical semantics to Zicond and all code paths affect that extension too.

We plan to remove 'xventanacondops' and just go with zicondops

Did xventanacondops ever ship in real hardware?

@mgudim
Copy link
Contributor

mgudim commented Jun 10, 2025

Please test +xventanacondops too. They have identical semantics to Zicond and all code paths affect that extension too.

We plan to remove 'xventanacondops' and just go with zicondops

Did xventanacondops ever ship in real hardware?

No

@bababuck bababuck force-pushed the bababuck/ZicondOptTests branch from 2a23721 to 98eed72 Compare June 10, 2025 20:38
@bababuck
Copy link
Contributor Author

Pushed to address the above suggestions.

@bababuck bababuck requested a review from mgudim June 10, 2025 21:25
@bababuck bababuck force-pushed the bababuck/ZicondOptTests branch from 98eed72 to 7d64e5c Compare June 10, 2025 23:18
}

; (select cond, -2048, t) -> (xor (czero_nez (xor t, -2048), cond), -2048)
define i64 @select_imm_reg_2048(i64 %0, i64 %1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the constant operand of select will alway be last due to canonicalization of IR in the midend

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't rhs same cost as lhs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before:

%imm = li -2048
%res0 = czero.eqz  %imm, %cond
%res1 = czero.nez  %input, %cond
%return = or %res0, %res1
ret %return

After:

%xor = xori %input, -2048
%czero = czero.nez, %input, %cond
%return = xori %czero, -2048
ret %return

DAG of height 3 for both, transformed has one fewer instruction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the constant operand of select will alway be last due to canonicalization of IR in the midend

Will this always be true, I though the order of %select was dependent on the condition, or will the mid-end flip the SETCC condition code so that this is true?

Copy link
Collaborator

@topperc topperc Jun 11, 2025

Choose a reason for hiding this comment

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

I believe the constant operand of select will alway be last due to canonicalization of IR in the midend

I don't want to rely on this. Selects can be created in the backend and I don't think we have the same canonicalization in DAGCombine, but I might be wrong.

Copy link
Contributor

@mgudim mgudim Jun 11, 2025

Choose a reason for hiding this comment

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

Oh, sorry, my bad. I don't know what I was thinking when I wrote this.

ret i64 %4
}

; (select c, (and f, ~x), f) -> (andn f, (czero_nez x, c))
Copy link
Contributor

Choose a reason for hiding this comment

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

note that "0" is identity for "andn" so in terms of implementation this case could be combined with conditional rotation.

@bababuck bababuck force-pushed the bababuck/ZicondOptTests branch from 7d64e5c to cff8037 Compare June 11, 2025 17:54
@bababuck
Copy link
Contributor Author

Updated:

  • Variable names
  • New tests for reverse cases
  • Typos

@bababuck bababuck requested review from mgudim and topperc June 11, 2025 17:55
Copy link
Contributor

@mgudim mgudim left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

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

LGTM

@bababuck bababuck force-pushed the bababuck/ZicondOptTests branch from cff8037 to d3f5efa Compare June 11, 2025 19:04
@bababuck
Copy link
Contributor Author

Pushed one last time, I had a small typo in the rotl test.

@mgudim mgudim merged commit 9f542f1 into llvm:main Jun 12, 2025
7 checks passed
mgudim pushed a commit that referenced this pull request Jun 13, 2025
#143581)

See #143580 for MR with the test commit.

Performs the following transformations:
(select c, c1, t) -> (add (czero_nez t - c1, c), c1)
(select c, t, c1) -> (add (czero_eqz t - c1, c), c1)


@mgudim
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
I have a few patches to improve compilation for these tests which I will
be posting as separate MRs.
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
llvm#143581)

See llvm#143580 for MR with the test commit.

Performs the following transformations:
(select c, c1, t) -> (add (czero_nez t - c1, c), c1)
(select c, t, c1) -> (add (czero_eqz t - c1, c), c1)


@mgudim
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
I have a few patches to improve compilation for these tests which I will
be posting as separate MRs.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
llvm#143581)

See llvm#143580 for MR with the test commit.

Performs the following transformations:
(select c, c1, t) -> (add (czero_nez t - c1, c), c1)
(select c, t, c1) -> (add (czero_eqz t - c1, c), c1)


@mgudim
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.

3 participants