kaist-cp / cs420

KAIST CS420: Compiler Design (2023 Spring)
423 stars 28 forks source link

[Homework 6] About the provided test case #150

Closed Medowhill closed 4 years ago

Medowhill commented 4 years ago

Hi.

Currently, the 28th line of deadcode.input.ir is the following:

%b1:i1:unit = call @sink(%b1:i0:unit)

After dead code elimination, it becomes the following, which is from the 24th line of deadcode.output.ir:

%b1:i0:unit = call @sink(unit:unit)

It is possible because unit:unit is the only value of the unit type, but I am wondering whether such optimization is required in the homework. The lecture note mentions only removing unused allocations, removing nops, and removing unused instructions.

Thank you.

jeehoonkang commented 4 years ago

Let's remove nop from the IR in the deadcode elimination. In that case, the result of nop, e.g., %b1:i0:unit, should be replace with unit:unit.

Medowhill commented 4 years ago

Oh, I was confused... I thought that %b1:i0:unit was %b0:i0:unit. I still have a question though. I am wondering whether we really need such test cases. I believe that every optimization so far replaces an instruction with Nop only if its result is not used. Therefore, such cases seem not to appear in the usual optimization process. Am I missing something here?

Thank you.

jeehoonkang commented 4 years ago

It's a kinda compiler-philosophy question.

Even though nop is not used at all during the specific series of translations and optimizations in KECC, I still believe it's beneficial to optimize them out in deadcode elimination. Because we later may want to support other translations (e.g., from Rust to KECC IR?) and optimizations, which may introduce unused nop as a placeholder. To summarize, I want KECC to support not only the specific series of translations and optimizations but also all possible combinations of them. It is also a goal shared among LLVM compiler writers, as well.

Medowhill commented 4 years ago

I see. Thank you!