-
Notifications
You must be signed in to change notification settings - Fork 143
Improve SSA optimizations #268
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
13f90a9
Add ARM BX instruction for function returns
jserv 81fa621
Add constant folding for unary operators
jserv a06e3c6
Improve dead code elimination
jserv 400ec54
Add safety guards for division and modulo optimizations
jserv 9b42b28
Enhance algebraic simplifications
jserv 474be1a
Add phi node optimization
jserv 807f02f
Implement multi-instruction analysis and optimization
jserv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1750,18 +1750,40 @@ void read_expr_operand(block_t *parent, basic_block_t **bb) | |
read_expr_operand(parent, bb); | ||
|
||
rs1 = opstack_pop(); | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_log_not, vd, rs1, NULL, 0, NULL); | ||
|
||
/* Constant folding for logical NOT */ | ||
if (rs1 && rs1->is_const && !rs1->ptr_level && !rs1->is_global) { | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
vd->is_const = true; | ||
vd->init_val = !rs1->init_val; | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_load_constant, vd, NULL, NULL, 0, NULL); | ||
} else { | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_log_not, vd, rs1, NULL, 0, NULL); | ||
} | ||
} else if (lex_accept(T_bit_not)) { | ||
read_expr_operand(parent, bb); | ||
|
||
rs1 = opstack_pop(); | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_bit_not, vd, rs1, NULL, 0, NULL); | ||
|
||
/* Constant folding for bitwise NOT */ | ||
if (rs1 && rs1->is_const && !rs1->ptr_level && !rs1->is_global) { | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
vd->is_const = true; | ||
vd->init_val = ~rs1->init_val; | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_load_constant, vd, NULL, NULL, 0, NULL); | ||
} else { | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_bit_not, vd, rs1, NULL, 0, NULL); | ||
} | ||
Comment on lines
+1774
to
+1786
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
} else if (lex_accept(T_ampersand)) { | ||
handle_address_of_operator(parent, bb); | ||
} else if (lex_accept(T_asterisk)) { | ||
|
@@ -2179,10 +2201,22 @@ void read_expr_operand(block_t *parent, basic_block_t **bb) | |
|
||
if (is_neg) { | ||
rs1 = opstack_pop(); | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_negate, vd, rs1, NULL, 0, NULL); | ||
|
||
/* Constant folding for negation */ | ||
if (rs1 && rs1->is_const && !rs1->ptr_level && !rs1->is_global) { | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
vd->is_const = true; | ||
vd->init_val = -rs1->init_val; | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_load_constant, vd, NULL, NULL, 0, | ||
NULL); | ||
} else { | ||
vd = require_var(parent); | ||
gen_name_to(vd->var_name); | ||
opstack_push(vd); | ||
add_insn(parent, *bb, OP_negate, vd, rs1, NULL, 0, NULL); | ||
} | ||
Comment on lines
+2205
to
+2219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
require_var()
andgen_name_to()
can be moved to before the if statement to improve code reusability. That is: