diff options
| author | WormHeamer | 2025-08-05 01:47:10 -0400 |
|---|---|---|
| committer | WormHeamer | 2025-08-05 01:47:10 -0400 |
| commit | 9963610b308bbf79e0f2e0f3e0c1af1b7bc40b1b (patch) | |
| tree | 6f00a61c9b7626da6b6de7c1c5dbafe787de216c | |
| parent | 2069733522922fc45cc87da0327e6dfcda74f1b2 (diff) | |
convert divisions to right-shifts
| -rw-r--r-- | ir.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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); |
