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

WordLang CSE is not doing enough #966

Open
myreen opened this issue Aug 8, 2023 · 0 comments
Open

WordLang CSE is not doing enough #966

myreen opened this issue Aug 8, 2023 · 0 comments
Assignees

Comments

@myreen
Copy link
Contributor

myreen commented Aug 8, 2023

Using the new --explorer output, I found a bad code pattern. I gave the compiler the following code to compile:

fun add_all x =
  case x of
    A a => (a,a,a)
  | B a b => (a,b,b)
  | C a b c => (a,b,c);

Now looking at the code for loading a, b, c in the last line, I see:

              (move 0 ((417 := 389)))
              (inst (Arith (Shift Lsr 421 417 9)))
              (425 := CurrHeap Add 421)
              (inst (Mem Load 429 (Addr 425 0x8)))
              (move 0 ((433 := 389)))
              (inst (Arith (Shift Lsr 437 433 9)))
              (441 := CurrHeap Add 437)
              (inst (Mem Load 445 (Addr 441 0x10)))
              (move 0 ((449 := 389)))
              (inst (Arith (Shift Lsr 453 449 9)))
              (457 := CurrHeap Add 453)
              (inst (Mem Load 461 (Addr 457 0x18))) 

And this is after common subexpression elimination in WordLang. It ought to be:

              (move 0 ((417 := 389)))
              (inst (Arith (Shift Lsr 421 389 9)))
              (425 := CurrHeap Add 421)
              (inst (Mem Load 429 (Addr 425 0x8)))
              (move 0 ((433 := 389)))
              (move 0 ((433 := 421)))
              (move 0 ((441 := 425)))
              (inst (Mem Load 445 (Addr 425 0x10)))
              (move 0 ((449 := 389)))
              (move 0 ((453 := 421)))
              (move 0 ((457 := 425)))
              (inst (Mem Load 461 (Addr 425 0x18)))  

which after dead code elimination ought to be:

              (move 0 ((417 := 389)))
              (inst (Arith (Shift Lsr 421 389 9)))
              (425 := CurrHeap Add 421)
              (inst (Mem Load 429 (Addr 425 0x8)))
              (inst (Mem Load 445 (Addr 425 0x10)))
              (inst (Mem Load 461 (Addr 425 0x18)))  

i.e. loads generated by straightforward pattern matching should be just a list of loads at this point.

@myreen myreen self-assigned this Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant