kaist-cp / cs420

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

[Question] Domination tree construction equation #159

Closed h2oche closed 4 years ago

h2oche commented 4 years ago

In lecture slides, there is domination tree construction which using equation idom(X) = ⊓_{y \in pred(X)} idom(Y). However, it seems to be incorrect.

For example, for graph 1 -> 2 -> 3, idom(3) = 2, idom(2) = 1, but if I use above equation idom(3) becomes 1.

I think idom(X) = (⊓_{y \in pred(X)} idom(Y)) if not exists y s.t y \in pred(X) and y is idom(X) = ⊓ pred(X) if exists y s.t y \in pred(X) and y is idom(X)

is correct equation.

h2oche commented 4 years ago

Actually, model solution in video also seems to be incorrect. When I give following ir to Domtree in model solution,

fun unit @aa {
init:
  bid: b0
  allocations:

block b0:
  j b1()

block b1:
  j b2()

block b2:
  ret 0:i32
}

It says domtree.parent is {1 -> 0, 2 -> 0} (I guess {1 -> 0, 2 -> 1} is correct result).

Updated : Sorry, in updated video in Register Promotion(Code, Domination), this problem seems to be fixed.

jeehoonkang commented 4 years ago

Thank you for reporting the bug. I agree with you on that "idom(X) = ⊓_{y \in pred(X)} idom(Y)" is wrong.

The fix will be, as you said, like this:

idom(X) = y                                            if y \in pred(X) and forall z \in pred(X), y=z or y dominates z
idom(X) = ⊓_{y \in pred(X)} idom(Y)     otherwise

I'll update the slide.

jeehoonkang commented 4 years ago

Slide updated: https://docs.google.com/presentation/d/1SqtU-Cn60Sd1jkbO0OSsRYKPMIkul0eZoYG9KpMugFE/edit#slide=id.g8489bbc41c_7_22

h2oche commented 4 years ago

Oh, thanks! By the way, notion of domination is really useful to me while doing homework :). May I close this issue?

jeehoonkang commented 4 years ago

I'm glad it's helpful :) I'm closing this issue.