Repository navigation
[InstCombine] Fix miscompile when folding a select into a masked load #216730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5379,11 +5379,21 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { | |
| if (match(TrueVal, m_OneUse(m_MaskedLoad(m_Value(MaskedLoadPtr), | ||
| m_Specific(CondVal), m_Value())))) { | ||
| auto *LoadInst = cast<IntrinsicInst>(TrueVal); | ||
| Instruction *In = Builder.CreateMaskedLoad( | ||
| TrueVal->getType(), MaskedLoadPtr, | ||
| LoadInst->getParamAlign(0).valueOrOne(), CondVal, FalseVal); | ||
| In->setAAMetadata(LoadInst->getAAMetadata()); | ||
| return replaceInstUsesWith(SI, In); | ||
| // Keep the load at its original position to avoid crossing writes. The new | ||
| // passthrough must therefore be available there. | ||
| // TODO: Sink the load when the passthrough is unavailable but no | ||
| // intervening instruction can modify memory. | ||
| if (DT.dominates(FalseVal, LoadInst)) { | ||
| Builder.SetInsertPoint(LoadInst); | ||
| // SetInsertPoint() took the debug location from the old load, but the new | ||
| // load replaces the select, so restore the select's location. | ||
| Builder.SetCurrentDebugLocation(SI.getDebugLoc()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, I'm not sure this really makes sense. Both locations are not entirely correct here, but keeping the Load location will avoid jumpy debugging.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review. I removed the explicit debug-location override. |
||
| Instruction *In = Builder.CreateMaskedLoad( | ||
| TrueVal->getType(), MaskedLoadPtr, | ||
| LoadInst->getParamAlign(0).valueOrOne(), CondVal, FalseVal); | ||
| In->setAAMetadata(LoadInst->getAAMetadata()); | ||
| return replaceInstUsesWith(SI, In); | ||
| } | ||
| } | ||
|
|
||
| // Canonicalize sign function ashr pattern: select (icmp slt X, 1), ashr X, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the TODO. (AI risk mitigation.)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, removed the TODO.