Skip to content
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

[Mips] mips1 DivByZeroTrap #81311

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cmccord-dev
Copy link

Inserts bnez + break instead of teq $zero for mips1 target

Fixes #80554

I updated the llvmir sdiv/udiv test as well.

This is my first contribution, please let me know if there is anything else I need to do!

Copy link

github-actions bot commented Feb 9, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@cmccord-dev
Copy link
Author

@topperc

@brad0
Copy link
Contributor

brad0 commented Feb 10, 2024

cc @wzssyqa

; GP32-NEXT: teq $5, $zero, 7
; GP32-NEXT: jr $ra
; GP32-NEXT: mflo $2
; GP32R0R1-LABEL: sdiv_i32:
Copy link
Contributor

Choose a reason for hiding this comment

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

Note, MIPS32R1 is not same as MIPS I.
The road map of MIPS Rev is like

32bit I II 32R1
64bit III IV V. 64R1

This name scheme is quite confusion.

Copy link
Author

Choose a reason for hiding this comment

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

I based the naming here off the entries that already existed for MIPS II, my changes are specifically for MIPS I, not Mips32R1, though I agree the naming scheme is very confusing. Whoever wrote this originally referred to MIPSII as MIPS32R0R2, then MIPS32R1 as just MIPS32R1 Would you recommend changing the names for both mips1 and mips2?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since MIPS I is not supported well yet for LLVM, and I guess the 32R0 was supposed to be equal with MIPS II in this context.

If we need MIPS I, we may use a new name for it, maybe 32_I?

; GP32R0R2-NEXT: nop
; GP32R0R2-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
; GP32R0R2-NEXT: jr $ra
; GP32R0R2-NEXT: addiu $sp, $sp, 24
Copy link
Contributor

Choose a reason for hiding this comment

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

The only difference of GP32R0R2 and GP32R0R1 is about some nop?
If so, they can be merged.

Copy link
Author

Choose a reason for hiding this comment

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

The nop is at least significant on mips1 since it has load delay slots, removing it would not be valid, but I agree that this test case is kind of pointless otherwise. or is there some way of merging it and keeping the nop only for mips1?

Copy link
Contributor

@wzssyqa wzssyqa Feb 22, 2024

Choose a reason for hiding this comment

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

Can you have a try this syntax?

GP32R_1-NEXT: nop
GP32-NEXT: lw
``

As you may notice that
FileCheck %s -check-prefixes=GP32,GP32R0R1
`FileCheck` can have multiple prefixes.

; GP32R2R5-NEXT: div $zero, $4, $5
; GP32R2R5-NEXT: teq $5, $zero, 7
; GP32R2R5-NEXT: jr $ra
; GP32R2R5-NEXT: mflo $2
Copy link
Contributor

Choose a reason for hiding this comment

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

R0R2 is same with R2R5?
If so, why not merge them?

Copy link
Author

Choose a reason for hiding this comment

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

good point, these test cases were autogenerated by utils/update_llc_test_checks.py, I just changed the header bit. I can merge them, but if the test cases change again later, they'll have to be remerged.

@brad0
Copy link
Contributor

brad0 commented Mar 9, 2024

Update?

@brad0
Copy link
Contributor

brad0 commented Mar 22, 2024

@cmccord-dev Ping.

@cmccord-dev
Copy link
Author

I did some more testing on another project I'm working on with this fix and found that it trips assertions on more complex examples. I don't currently have a good minimal example, but it seems I'm not handling liveness correctly with the newly generated blocks. If someone who understands the system better could take a look I would greatly appreciate it. Additionally, I've only tested with sdiv/udiv but I believe srem/urem should also be tested. I will implement these, along with the comments above when I get a chance.

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.

mips1 target generates invalid instruction
3 participants