egraphs-good / eggcc

MIT License
51 stars 11 forks source link

[DAG In Context] CICM for `If` #420

Closed rtjoa closed 7 months ago

rtjoa commented 7 months ago

See also https://github.com/egraphs-good/eggcc/pull/381.

Example rewrite (arg and const types elided for brevity):

(If
  (Get (Arg) 2)
  (Bop (LessThan) (Get (Arg) 0) (Const (Int 7)))
  (Bop (LessThan) (Get (Arg) 1) (Const (Int 7))))
~~>
(Bop (LessThan)
  (If
    (Get (Arg) 2)
    (Get (Arg) 0)
    (Get (Arg) 1))
  (Const (Int 7)))

Example generated rule:

(rewrite (If c (Bop _op _x e1) (Bop _op _x e2))
         (Bop _op _x (If c e1 e2))
         :when ((ExprIsValid (If c (Bop _op _x e1) (Bop _op _x e2))))
         :ruleset conditional-invariant-code-motion)