-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
'X86 DAG->DAG Instruction Selection' assertion failure #57283
'X86 DAG->DAG Instruction Selection' assertion failure #57283
Comments
@llvm/issue-subscribers-backend-x86 |
Godbolt: https://llvm.godbolt.org/z/T6vh17s9z |
I found the problem is MatchRotate expects both are shift, but getNode returns a constant node due to optimization. |
Its a shame that extractShiftForRotate creates node at all - as well as constant folding it can also create multiuses in a place where we have a lot of OneUse checks and its not even guaranteed they will be used.... To prevent the crash it's probably best that initially we just bail if MatchRotate doesn't find a SHL/SRL pair. |
extractShiftForRotate may fail to return canonicalized shifts due to constant folding or other simplification that can occur in getNode() Fixes Issue #57283
I'll leave this to brew for 24 hours then request a cherry pick for 15.x |
Thanks for fixing it so fast! Really appreciate it!.
However, I am fairly new to x86 backend, would you explain a bit more what is "OneUse checks" and how did this test case, where no shift is presented, ended up as a shifting error? |
OneUse checks - new nodes are often only created from a pattern of existing nodes if all of those nodes only occur once (i.e. inside that pattern):
|
Based off Issue #57283 - we need to try harder to ensure we're not creating nodes on-the-fly - so make sure we're just using SelectionDAG for analysis where possible
Multiply/divide by powers-of-2 are strength-reduced to shifts. This is in IR, but we do the same thing in llc (backend): |
/cherry-pick e624f8a |
/branch llvm/llvm-project-release-prs/issue57283 |
/pull-request llvm/llvm-project-release-prs#127 |
@RKSimon Thanks for the fix. I just found a case where it seems its not 100% fixed. https://llvm.godbolt.org/z/M1r9j7W1c In your patch, I think you need to move the check for opcode up a little, up before // Something has gone wrong - we've lost the shl/srl pair - bail.
if (LHSShift.getOpcode() != ISD::SHL || RHSShift.getOpcode() != ISD::SRL)
return SDValue();
// Have LHS side of the rotate, try to extract the needed shift from the RHS.
if (LHSShift)
if (SDValue NewRHSShift =
extractShiftForRotate(DAG, LHSShift, RHS, RHSMask, DL))
RHSShift = NewRHSShift;
// Have RHS side of the rotate, try to extract the needed shift from the LHS.
if (RHSShift)
if (SDValue NewLHSShift =
extractShiftForRotate(DAG, RHSShift, LHS, LHSMask, DL))
LHSShift = NewLHSShift;
/// The check was below here. |
@DataCorrupted Did you find any other cases of this? Otherwise I'd like to start refactoring extractShiftForRotate to not create nodes at all and fix this properly, but that will make further cherry picking into 15.x very difficult. |
My fuzzing process has (unfortunately) stopped sometime ago. If you want I can fuzz the current version for a week and see the result. But for now, I don't have any other testcases. |
When fuzzing x86_64 we found a module that will trigger an assertion failure.
Seems like this is a newly introduced bug. LLVM14.0.0 compiles correctly, but crashes on latest commit
cfd2c5ce580f
The text was updated successfully, but these errors were encountered: