-
Notifications
You must be signed in to change notification settings - Fork 149
Eliminate arithmetic instructions based on properties #183
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
Conversation
c49885d to
7a830d0
Compare
| * {ALU rn, rs1, rs2; mv rd, rn;} | ||
| * reduces to: | ||
| * {ALU rd, rs1, rs2;} | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the meaning of the proposed changes, but I want to ask a question:
After applying these changes, shecc may find two proper instructions and merge them into the first instruction (ph2_ir) if possible. However, the second instruction (next) remains in a certain ph2_ir_list after merging, but it seems unnecessary.
Therefore, I think the second instruction could be deleted from the linked list after fusion. Do you consider my opinion correct? If you agree, please add the deletion process to the proposed changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct in this case, but I am also working on regional allocation for ph2_ir_t in the mean time, implemented in arena allocation to be specific. I am aiming to free all ph2_ir in that work. Therefore, I prefer to keep it as is.
7a830d0 to
bf65ba4
Compare
jserv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of referring the instructions as "math," classify them in the field of "arithmetic instructions."
|
Provide the statistics of the proposed changes. |
bf65ba4 to
4b153fa
Compare
This patch eliminates arithmetic instructions (add, sub, and mul to be specific) when the criterion is matched. Including: - Identity property for addition. - Zero and identity property for multiplication, these are effective when doing pointer offset. - Subtraction will be replaced based on operand, e.g., "s - 0" will be replaced with "s"; "0 - s" will be replaced with "-s".
4b153fa to
52a81ab
Compare
|
The results generated by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Did you test stage-1 on armv7 machine?
|
No, and I don't have any armv7 / riscv machine to run tests. I am currently using qemu to bootstrap and benchmark locally, which may not be accurate. |
|
Thank @ChAoSUnItY for contributing! |

This patch eliminates arithmetic instructions (
add,sub, andmul, in particular) when the criterion is matched. Including:Notice that
insn_fusion's return value has changed fromvoidtoboolto preserve ability to indicate whether instruction has been optimized or not.Analysis of performance statistics
Before:
hyperfine --warmup 3 './out/shecc ./src/main.c' './out/shecc-stage1.elf ./src/main.c'After:
hyperfine --warmup 3 './out/shecc ./src/main.c' './out/shecc-stage1.elf ./src/main.c'I assume the minor performance regression is caused by introduction of more condition checking on every instructions.