Skip to content

[SelectionDAG][X86] Fix the assertion failure in Release build after #91747 #93434

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

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,8 +1801,11 @@ void DAGCombiner::Run(CombineLevel AtLevel) {

if (N->getNumValues() == RV->getNumValues())
DAG.ReplaceAllUsesWith(N, RV.getNode());
else
else {
assert(N->getValueType(0) == RV.getValueType() &&
N->getNumValues() == 1 && "Type mismatch");
DAG.ReplaceAllUsesWith(N, &RV);
}

// Push the new node and any users onto the worklist. Omit this if the
// new node is the EntryToken (e.g. if a store managed to get optimized
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49253,8 +49253,10 @@ static SDValue combineX86SubCmpForFlags(SDNode *N, SDValue Flag,
return SDValue();

SDValue X = SetCC.getOperand(1);
// Replace API is called manually here b/c the number of results may change.
DAG.ReplaceAllUsesOfValueWith(Flag, X);
// sub has two results while X only have one. DAG combine assumes the value
// type matches.
if (N->getOpcode() == X86ISD::SUB)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't N always have 2 results?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N can be a X86ISD::CMP or X86ISD::SUB. When N is CMP, it only has one result.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if (N->getOpcode() == X86ISD::SUB) for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, done

X = DAG.getMergeValues({N->getOperand(0), X}, SDLoc(N));

SDValue CCN = SetCC.getOperand(0);
X86::CondCode CC =
Expand Down
Loading