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

div to shift for positive power of 2 divs #8474

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cranelift/codegen/src/opts/arithmetic.isle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@
(iconst_u ty 1)))
(subsume x))

;; TODO: strength reduction: div to shifts
;; TODO: strength reduction: div to shifts when negative power of two
;; x/c == x>>log2(c) when c is a power of two.
(rule (simplify (udiv ty x (iconst _ (imm64_power_of_two c))))
(ushr ty x (iconst ty (imm64 c))))

(rule (simplify (sdiv ty x (iconst _ (imm64_power_of_two c))))
(sshr ty x (iconst ty (imm64 c))))
;; TODO: div/rem by constants -> magic multiplications

;; x*2 == x+x.
Expand Down