Add optimization for if with both then and else branch the same
- Dominant language
- Standard ML
- Stars
- 1.2k
- Forks
- 104
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 16
Description
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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the datalang optimization pass in the CakeML repository and trace how the shown case expressions become nested conditionals. Compare the generated form for branches returning the same constant or expression, and consider the work done when those redundant branches are eliminated with corresponding compiler tests passing.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100