Skip to content

[TableGen] Sort matchables depending on predicates. #84483

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

Closed
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
4 changes: 2 additions & 2 deletions llvm/test/MC/Mips/micromips32r6/valid.s
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
# CHECK-NEXT: # <MCInst #{{.*}} LH_MM
lhu $4, 8($2) # CHECK: lhu $4, 8($2) # encoding: [0x34,0x82,0x00,0x08]
# CHECK-NEXT: # <MCInst #{{.*}} LHu_MM
lsa $2, $3, $4, 3 # CHECK: lsa $2, $3, $4, 3 # encoding: [0x00,0x43,0x24,0x0f]
lsa $2, $3, $4, 3 # CHECK: lsa $2, $3, $4, 3 # encoding: [0x00,0x83,0x14,0x0f]
lwpc $2,268 # CHECK: lwpc $2, 268 # encoding: [0x78,0x48,0x00,0x43]
lwm $16, $17, $ra, 8($sp) # CHECK: lwm16 $16, $17, $ra, 8($sp) # encoding: [0x45,0x22]
lwm16 $16, $17, $ra, 8($sp) # CHECK: lwm16 $16, $17, $ra, 8($sp) # encoding: [0x45,0x22]
Expand Down Expand Up @@ -194,7 +194,7 @@
msubf.d $f3, $f4, $f5 # CHECK: msubf.d $f3, $f4, $f5 # encoding: [0x54,0xa4,0x1b,0xf8]
mov.s $f6, $f7 # CHECK: mov.s $f6, $f7 # encoding: [0x54,0xc7,0x00,0x7b]
mov.d $f4, $f6 # CHECK: mov.d $f4, $f6 # encoding: [0x54,0x86,0x20,0x7b]
# CHECK-NEXT: # <MCInst #{{[0-9]+}} FMOV_D64_MM
# CHECK-NEXT: # <MCInst #{{[0-9]+}} FMOV_D_MMR6
neg.s $f6, $f7 # CHECK: neg.s $f6, $f7 # encoding: [0x54,0xc7,0x0b,0x7b]
neg.d $f0, $f2 # CHECK: neg.d $f0, $f2 # encoding: [0x54,0x02,0x2b,0x7b]
# CHECK-NEXT: # <MCInst #{{[0-9]+}} FNEG_D64_MM
Expand Down
26 changes: 25 additions & 1 deletion llvm/utils/TableGen/AsmMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,16 @@ struct MatchableInfo {
if (RequiredFeatures.size() != RHS.RequiredFeatures.size())
return RequiredFeatures.size() > RHS.RequiredFeatures.size();

// Sort by the alphabetical naming of the required features.
for (unsigned i = 0, e = RequiredFeatures.size(); i != e; ++i) {
if (RequiredFeatures[i]->TheDef->getName() <
RHS.RequiredFeatures[i]->TheDef->getName())
return true;
if (RHS.RequiredFeatures[i]->TheDef->getName() <
RequiredFeatures[i]->TheDef->getName())
return false;
}

return false;
}

Expand Down Expand Up @@ -689,7 +699,21 @@ struct MatchableInfo {
HasGT = true;
}

return HasLT == HasGT;
if (HasLT != HasGT)
return false;

// Check if can distringuish by the alphabetical ordering of features.
if (RequiredFeatures.size() != RHS.RequiredFeatures.size())
return false;
for (unsigned i = 0, e = RequiredFeatures.size(); i != e; ++i) {
if (RequiredFeatures[i]->TheDef->getName() <
RHS.RequiredFeatures[i]->TheDef->getName() ||
RHS.RequiredFeatures[i]->TheDef->getName() <
RequiredFeatures[i]->TheDef->getName())
return false;
}

return true;
}

void dump() const;
Expand Down