[TIR][CSE] Fix crash with thread_extent values#18912
[TIR][CSE] Fix crash with thread_extent values#18912MasterJH5574 wants to merge 1 commit intoapache:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where the Common Subexpression Elimination (CSE) pass inadvertently introduced Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a crash in the Common Subexpression Elimination (CSE) pass when dealing with thread_extent attributes. The fix correctly prevents CSE from processing expressions within thread_extent values in both the CSEPlanner and CSERewriter, which resolves the issue with a later LowerDeviceKernelLaunch pass. The changes are well-targeted, and the new test case effectively validates the fix. I have one minor suggestion to improve code consistency.
| if (body.same_as(op->body)) { | ||
| return ffi::GetRef<Stmt>(op); | ||
| } | ||
| return AttrStmt(op->node, op->attr_key, op->value, body); |
There was a problem hiding this comment.
|
would be good to cross check and deep deeper to see if lowe |
CSE previously inserted Bind statements between nested thread_extent AttrStmts when the extent value (e.g. 511 // B + 1) also appeared in the body. LowerDeviceKernelLaunch later dropped these Binds while the thread_extent value still referenced CSE variables, causing LLVM host codegen to fail with "cannot find variable cse_v3". Fix: skip recording and rewriting expressions in thread_extent values. Body expressions are still CSE'd normally.
22efd83 to
74cd126
Compare
Summary
CSE previously inserted Bind statements between nested
thread_extentAttrStmts when the extent value (e.g.511 // B + 1) also appeared in the body.LowerDeviceKernelLaunchextracts thread_extent values from the device function and transplants them as kernel launch arguments in the host function, assuming they are expressible in terms of the function's parameters. CSE broke this assumption by replacing thread_extent values with locally-scoped Bind variables, producing dangling references in the host function and crashing LLVM codegen withcannot find variable cse_v3.Fix: skip recording and rewriting expressions in thread_extent values. Body expressions are still CSE'd normally.
Test plan
test_thread_extent_no_cse_between_launchregression test (before/after withassert_structural_equal)