Skip to content

Commit 9a6aa39

Browse files
authored
Revert "Cranelift: Reassociate long and narrow chains of operations into shallow and wide trees (#7466)" (#12116)
* Revert "Cranelift: Reassociate long and narrow chains of operations into shallow and wide trees (#7466)" This reverts commit 72534b0. This mid-end rule was shown to be the root cause of a codegen regression in #12106 and we didn't have any real examples that would improve from this rule, just a theoretical idea of its benefit. Better to do actual instruction scheduling while lowering and/or during regalloc than to do hack-y instruction scheduling in the mid-end (where we have no idea how many registers are available, for example). * update disas tests
1 parent 91abf8c commit 9a6aa39

File tree

11 files changed

+222
-654
lines changed

11 files changed

+222
-654
lines changed

cranelift/codegen/src/opts/arithmetic.isle

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -196,105 +196,6 @@
196196
(rule (simplify (fmul ty (fneg ty x) (fneg ty y)))
197197
(fmul ty x y))
198198

199-
;; (a op (b op (c op d))) ==> ((a op b) op (c op d))
200-
;;
201-
;; and
202-
;;
203-
;; (((a op b) op c) op d) ==> ((a op b) op (c op d))
204-
;;
205-
;; where `op` is an associative operation: `iadd`, `imul`, `band`, or `bxor`.
206-
;;
207-
;; This increases instruction-level parallelism and shrinks live ranges. It also
208-
;; canonicalizes into the shallow-and-wide form for reassociating constants
209-
;; together for cprop.
210-
;;
211-
;; NB: We subsume to avoid exponential e-node blow up due to reassociating very
212-
;; large chains of operations.
213-
;;
214-
;; TODO: We should add `bor` rules for this as well. Unfortunately, they
215-
;; conflict with our `bswap` recognizing rules when we `subsume`.
216-
217-
(rule (simplify (iadd ty a (iadd ty b (iadd ty c d))))
218-
(subsume (iadd ty (iadd ty a b) (iadd ty c d))))
219-
(rule (simplify (iadd ty (iadd ty (iadd ty a b) c) d))
220-
(subsume (iadd ty (iadd ty a b) (iadd ty c d))))
221-
222-
(rule (simplify (imul ty a (imul ty b (imul ty c d))))
223-
(subsume (imul ty (imul ty a b) (imul ty c d))))
224-
(rule (simplify (imul ty (imul ty (imul ty a b) c) d))
225-
(subsume (imul ty (imul ty a b) (imul ty c d))))
226-
227-
(rule (simplify (band ty a (band ty b (band ty c d))))
228-
(subsume (band ty (band ty a b) (band ty c d))))
229-
(rule (simplify (band ty (band ty (band ty a b) c) d))
230-
(subsume (band ty (band ty a b) (band ty c d))))
231-
232-
(rule (simplify (bxor ty a (bxor ty b (bxor ty c d))))
233-
(subsume (bxor ty (bxor ty a b) (bxor ty c d))))
234-
(rule (simplify (bxor ty (bxor ty (bxor ty a b) c) d))
235-
(subsume (bxor ty (bxor ty a b) (bxor ty c d))))
236-
237-
238-
;; Similar rules but for associating combinations of + and -
239-
240-
;; a -(b-(c-d)) = (a-b) + (c-d)
241-
(rule (simplify (isub ty a (isub ty b (isub ty c d))))
242-
(subsume (iadd ty (isub ty a b) (isub ty c d))))
243-
244-
;; a -(b-(c+d)) = (a-b) + (c+d)
245-
(rule (simplify (isub ty a (isub ty b (iadd ty c d))))
246-
(subsume (iadd ty (isub ty a b) (iadd ty c d))))
247-
248-
;; a -(b+(c-d)) = (a-b) - (c-d)
249-
(rule (simplify (isub ty a (iadd ty b (isub ty c d))))
250-
(subsume (isub ty (isub ty a b) (isub ty c d))))
251-
252-
;; a -(b+(c+d)) = (a-b) - (c+d)
253-
(rule (simplify (isub ty a (iadd ty b (iadd ty c d))))
254-
(subsume (isub ty (isub ty a b) (iadd ty c d))))
255-
256-
;; a +(b-(c-d)) = (a+b) - (c-d)
257-
(rule (simplify (iadd ty a (isub ty b (isub ty c d))))
258-
(subsume (isub ty (iadd ty a b) (isub ty c d))))
259-
260-
;; a +(b-(c+d)) = (a+b) - (c+d)
261-
(rule (simplify (iadd ty a (isub ty b (iadd ty c d))))
262-
(subsume (isub ty (iadd ty a b) (iadd ty c d))))
263-
264-
;; a +(b+(c-d)) = (a+b) + (c-d)
265-
(rule (simplify (iadd ty a (iadd ty b (isub ty c d))))
266-
(subsume (iadd ty (iadd ty a b) (isub ty c d))))
267-
268-
;; and nested the other way
269-
270-
;; ((a-b)-c)-d = (a-b) - (c+d)
271-
(rule (simplify (isub ty (isub ty (isub ty a b) c) d))
272-
(subsume (isub ty (isub ty a b) (iadd ty c d))))
273-
274-
;; ((a-b)-c)+d = (a-b) - (c-d)
275-
(rule (simplify (iadd ty (isub ty (isub ty a b) c) d))
276-
(subsume (isub ty (isub ty a b) (isub ty c d))))
277-
278-
;; ((a-b)+c)-d = (a-b) + (c-d)
279-
(rule (simplify (isub ty (iadd ty (isub ty a b) c) d))
280-
(subsume (iadd ty (isub ty a b) (isub ty c d))))
281-
282-
;; ((a-b)+c)+d = (a-b) + (c+d)
283-
(rule (simplify (iadd ty (iadd ty (isub ty a b) c) d))
284-
(subsume (iadd ty (isub ty a b) (iadd ty c d))))
285-
286-
;; ((a+b)-c)-d = (a+b) - (c+d)
287-
(rule (simplify (isub ty (isub ty (iadd ty a b) c) d))
288-
(subsume (isub ty (iadd ty a b) (iadd ty c d))))
289-
290-
;; ((a+b)-c)+d = (a+b) - (c-d)
291-
(rule (simplify (iadd ty (isub ty (iadd ty a b) c) d))
292-
(subsume (isub ty (iadd ty a b) (isub ty c d))))
293-
294-
;; ((a+b)+c)-d = (a+b) + (c-d)
295-
(rule (simplify (isub ty (iadd ty (iadd ty a b) c) d))
296-
(subsume (iadd ty (iadd ty a b) (isub ty c d))))
297-
298199
;; Detect people open-coding `mulhi`: (x as big * y as big) >> bits
299200
;; LLVM doesn't have an intrinsic for it, so you'll see it in code like
300201
;; <https://github.com/rust-lang/rust/blob/767453eb7ca188e991ac5568c17b984dd4893e77/library/core/src/num/mod.rs#L174-L180>

cranelift/filetests/filetests/egraph/associative-and-commutative.clif

Lines changed: 0 additions & 287 deletions
This file was deleted.

0 commit comments

Comments
 (0)