MLIR Open Meeting: Side Effect Semantics, CSE and Linalg ops, 2025-05-06 (original) (raw)

Next Tuesday, May 6, (note that weekday change) we will hold an open design meeting on side effect semantics, its use for Linalg operations and how it affects CSE as well as other transformations, following the discussion in Bug in `OperationEquivalence` (breaks `-cse` on `linalg.index`).

The call starts at 9am PDT, 4pm UTC, 6pm CEST.

Zoom Meeting Link

Meeting ID: 851 5109 0498
Passcode: 828404

This meeting is moved from Thursday, May 8 as per Time slots for Open MLIR Meetings.

KFAF May 6, 2025, 5:08pm 2

Here are the slides that I used today.

KFAF May 6, 2025, 8:44pm 3

Yeah, turns out I didn’t know how sharing works on Google docs… I fixed it now, everybody should have read access.

AI generated summary (Verbatim):

Meeting summary for MLIR Open Meeting (05/06/2025)
Quick recap
The team discussed the challenges of side effects and semantic equivalence in MLIR, particularly in relation to special operations like the index and vector mask. They explored the concept of side effects in programming, the challenges of recursive side effects in data flow analysis, and the implications of speculatability for code optimization. The team also discussed the need for better handling of side effects, the potential for a general solution to the problem of operation equivalence, and the challenges they face with their current tool.
Next steps
• Karl to implement a prototype interface for operation equivalence and measure its impact on compile times using a test dataset.
• Alex to post a brief update on the RFC and create a poll to schedule another call to continue discussing the problem and potential solutions.
• Alex to bump the existing thread with references to the old thread and PR about adding an interface for CSE.
• MLIR team to consider creating an MLIR test suite for benchmarking and performance testing.

Summary
MLIR CSE Pass Semantic Equivalence
In the meeting, Alex and Mehdi welcomed everyone to the MLIR open design meeting and discussed the topic of side effects and semantic equivalence, particularly in relation to special operations like the index and vector mask. Karl presented a short presentation on the issue, explaining that the Common Sub-Expression Elimination (CSE) pass in MLIR incorrectly concludes that two nested linear generic operations can be replaced by one, which contradicts their definitions. He also presented a similar issue with the Vector mask operation. Karl explained that the CSE pass works by tracking existing definitions and looking at isolated scopes, and it needs to prove that two operations are semantically equivalent and act on the same data. However, the current model does not account for dependencies between operations, leading to incorrect conclusions. The team agreed to further discuss the issue and potential solutions.
Side Effects in Programming Discussion
Karl discussed the concept of side effects in programming, explaining that they introduce true dependencies between operations, which are crucial for maintaining program correctness. He proposed a model where side effects are used to reason about program correctness, and these dependencies can be analyzed using data flow analysis. Karl also highlighted the need for more interfaces to model these side effects and the challenges of injecting side effects into existing operations. He concluded by mentioning the potential impact of side effects on code optimization techniques like common subexpression elimination (CSE) and loop invariant code motion.
Recursive Side Effects in Data Flow
Karl and Mehdi discussed the challenges of recursive side effects in data flow analysis. They agreed that while it’s possible to figure out these effects, it can be non-trivial. Mehdi suggested that having the ability to encode these kinds of information directly in the IR in a readily available way is valuable. Karl proposed a solution to model these effects using memory effects and speculation, but acknowledged that it would increase computational demand. Jacques raised a point about other Ops where the index behavior is passed as the first argument. Mehdi and Karl discussed the issue of filtering effects and the order in which they happen. Alex suggested a way to specify an order of effects, but Karl pointed out that recursive effects are collected differently.
Speculatability and Compiler Optimization Discussion
Karl, Mehdi, and Alex discuss the concept of speculatability and its implications for code optimization. They explore the differences between speculating and hoisting operations in the context of compiler optimizations. Karl explains that speculatability is currently used primarily to determine if an operation can be hoisted out of a loop, as it affects the ordering dependency and potential state observations. The group also discusses the behavior of Common Subexpression Elimination (CSE) and its limitations in moving operations outside of control flow structures. They conclude that there might be some confusion or differing interpretations of these terms among them, and decide to move forward with the discussion.
Addressing CSE Issues in MLIR
Karl discusses ways to address issues with Common Subexpression Elimination (CSE) in MLIR. He proposes modeling certain operations as SSA dependencies or using witness-like structures to prevent unwanted optimizations. Karl then explains that these solutions are not sufficient for all cases, such as preventing CSE from changing the number of users on operations without adding write effects. He provides an example from IRDL where type constraints can lead to unexpected behavior due to CSE. Karl suggests modifying the operation equivalence check to imply semantic equivalence, potentially through an interface that allows overriding the equivalence check. He acknowledges that this approach has drawbacks, including increased memory usage and loss of introspectability, but argues it could address the functionality issues discussed.
MLIR Semantics and Memory Effects
Karl presents a summary of the discussion on infrastructure and dispatch mechanisms, highlighting issues with dynamic index and vector dot mask operations. He emphasizes the need for all operations to be modeled with memory effects and suggests hardening semantic equivalents in MLIR to solve over-approximation problems. Alex adds that GPU thread ID and block ID operations also have incorrect or weird semantics, similar to the relationship between GPU kernel and ML generic. The group discusses the complexities of nested kernels and the semantics of MLIR, particularly regarding SSA and graph regions. Mehdi points out that MLIR’s design involves trade-offs between extensibility and maintaining a system where program executions and state can be described using SSA values or side effects modeled with resources.
Addressing Tool Challenges and Interface Needs
In the meeting, the team discussed the challenges they face with their current tool, which is generic and doesn’t allow for accurate analysis. They also discussed the possibility of adding an interface for Csc, specifically, and the potential for a general solution to the problem of operation equivalence. The team also discussed the need for a balance between better handling of side effects and supporting cases where those don’t help. They concluded that they need more time to discuss the issue and may need to schedule another meeting.

ftynse May 7, 2025, 11:40am 5