summaryrefslogtreecommitdiff
path: root/ir.c
diff options
context:
space:
mode:
authorWormHeamer2025-08-05 01:47:10 -0400
committerWormHeamer2025-08-05 01:47:10 -0400
commit9963610b308bbf79e0f2e0f3e0c1af1b7bc40b1b (patch)
tree6f00a61c9b7626da6b6de7c1c5dbafe787de216c /ir.c
parent2069733522922fc45cc87da0327e6dfcda74f1b2 (diff)
convert divisions to right-shifts
Diffstat (limited to 'ir.c')
-rw-r--r--ir.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ir.c b/ir.c
index c0de33c..e52e0b9 100644
--- a/ir.c
+++ b/ir.c
@@ -568,6 +568,12 @@ Node *node_idealize(Node *n, Proc *p, Lexer *l) {
if (node_eql_i64(CDR(n), 0)) {
lex_error_at(l, CDR(n)->src_pos, LE_ERROR, S("divisor always evaluates to zero"));
}
+ {
+ int po2;
+ if (T(CDR(n), N_LIT) && CDR(n)->val.type.t == T_INT && (po2 = u64_power_of_2(CDR(n)->val.u))) {;
+ return NODE(N_OP_SHR, CAR(n), node_new_lit_i64(p, po2));
+ }
+ }
break;
case N_OP_OR:
if (same) return CAR(n);