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

[Xtensa] Fix FP mul-sub fusion (LLVM-276) #76

Closed

Conversation

zRedShift
Copy link

performMADD_MSUBCombine treats x * y ± z and z ± x * y interchangeably which is wrong for msub.s which expects the latter. Added a check to determine that the orientation is correct, and if not, negate the result.

Seems like the original code was inspired by the MIPS code, which only has fused-multiply-add, and the order of the operands is irrelevant in that case.

This is my first PR to LLVM, so keep this in mind while reviewing, because I don't want to introduce a regression.

Related to (and hopefully fixes) esp-rs/rust#180, esp-rs/rust#185.

`performMADD_MSUBCombine` treats `x * y ± z` and `z ± x * y`
interchangeably which is wrong for `msub.s` which expects the
latter. Added a check to determine that the orientation is
correct, and if not, negate the result.
@github-actions github-actions bot changed the title [Xtensa] Fix FP mul-sub fusion [Xtensa] Fix FP mul-sub fusion (LLVM-276) Jul 13, 2023
@zRedShift
Copy link
Author

Correction: MIPS does in fact have msub.(s|d), but the instruction shape is inverted to the way xtensa handles it

MSUB.S fd, fr, fs, ft
fd ← (fs × ft) - fr

Planning to add some llc/filechecker codegen tests for this fix

1. Prefer `fneg.s` to `l32r ar, 0x80000000; xor ar, as, ar` when `wfr/rfr` are used anyway
2. Add Patterns for fma/madd/msub to automatically generate msub when it's the better choice
3. XtensaISelLowering.cpp: Rely on LLVM to lower FMA to madd.s/msub.s instead of hardcoding
4. Add float-fma.ll with various fused multiply add/subtract permutations
@espressif-bot espressif-bot added Status: In Progress work is in progress and removed Status: Opened labels Jul 20, 2023
@espressif-bot espressif-bot added Status: In Review and removed Status: In Progress work is in progress labels Jul 27, 2023
@gerekon
Copy link
Collaborator

gerekon commented Sep 1, 2023

Closed with 19e97af

@gerekon gerekon closed this Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants