← Advanced course and all videos

Video 14 of 53 · 4:21 · Execution, sharing and reuse

Identifying a distinct compiler mechanism

In this video

  1. 0:00 · Introduction
  2. 0:16 · Prove the distributive identity before naming a mechanism
  3. 1:14 · Core explanation
  4. 2:14 · An explicit mixed-branch distributivity check
  5. 3:16 · Inspect what a compiler actually changed
  6. 4:09 · Direct takeaways

Caption transcript

Show transcript
This overview explains how to compare CM-IR and CSE-flat after crediting both for the sharing and flattening they implement. A method name cannot explain a speed difference when the relevant output structures are the same. Both expressions describe an A requirement combined with alternatives B and C. In the first, A is repeated in two branches. In the second, A appears once outside the alternative. The proposed relationship is distributivity, which is more than flattening a chain of identical operators. When A is zero, both branches of the first expression are zero. Their or is zero. The second expression also has an outer and with zero, so it returns zero regardless of B and C. This covers four complete assignments at once. When A is one, each and in the first expression passes through its other input, leaving B or C. The second expression reduces to the same result. The two cases for A exhaust its possibilities, establishing the identity for all eight assignments. Give CSE-flat and CM-IR credit for mechanisms they both implement. Then identify an actual extra transformation on the example, rather than attributing any gain to a method name. For a conceptual normalization example, compare A AND A with A. Their two-assignment output columns agree. A compiler that removes this duplicate can eliminate an instruction here; a comparator that already performs the same rewrite deserves the same credit. For the repeated S example, protect the shared child in both arms before comparing the remaining lowered structures. The companion checks Boolean identities separately from the repository compiler trace. Inspect the trace to establish which current compiler actually performs a rewrite. Structural change is a mechanism observation; elapsed-time advantage still requires a retained matched experiment. Work a second complete case with A 1, B 0, C 1. Keep this assignment fixed throughout the calculation. Each symbol retains the meaning already introduced; a new value does not create a new logical rule. In the original form, the first branch is zero and the second branch is one, so their or is one. In the factored form, evaluate the parenthesized or first: zero or one gives one. Combining that with A one gives one. The two execution structures agree on this mixed-branch case. This case establishes a specific contrast. Two structures, one exact output. Distinct emitted code still needs inspection. Keep the input, intermediate values, and conclusion together when comparing it with the previous case. The calculated answer belongs to this complete assignment under the stated rule. Suppose both compiler paths emit the factored graph. The mathematical identity is valid, but this example does not demonstrate a distinct mechanism that only one compiler supplies. Naming one path differently does not change that observation. If the emitted plans differ as shown, there is a concrete transformation to examine. Trace the nodes, the shared values, and the operations. Then verify exact outputs independently rather than assuming that a shorter-looking graph must be correct. A transformation can change sharing elsewhere in a larger graph, so inspect all consumers. Even a correct distinct transformation needs a fair cost comparison before supporting a runtime claim. This separates an identity, an implemented mechanism, and a measured benefit. Inspect the actual compiler trace for a distinct transformation. Treat structural changes and measured runtime advantages as separate observations.