cakeml icon indicating copy to clipboard operation
cakeml copied to clipboard

Add optimization for if with both then and else branch the same

Open ordinarymath opened this issue 1 year ago • 0 comments

Right now when cakeml is given the program of the form

fun const_optimization x =
  case x of
    A a => 10
  | B a b => 10
  | C a b c => 10;
  
fun const_optimization2 x =
  case x of
    A a => x
  | B a b => x
  | C a b c => x;

it results in code like this where the branches are still there

(func const_optimization@474 (0)
   (seq
      (2 := (TagLenEq 0 1) (0) none)
      (if 2
         (seq
            (5 := (Const 10) () none)
            (return 5))
         (seq
            (6 := (TagLenEq 0 2) (0) none)
            (if 6
               (seq
                  (11 := (Const 10) () none)
                  (return 11))
               (seq
                  (18 := (Const 10) () none)
                  (return 18)))))))

@myreen thinks that this optimization should be done in datalang

ordinarymath avatar Dec 08 '24 08:12 ordinarymath