diff options
author | Craig Topper <craig.topper@sifive.com> | 2021-10-12 08:46:08 -0700 |
---|---|---|
committer | Craig Topper <craig.topper@sifive.com> | 2021-10-12 09:19:20 -0700 |
commit | aefaf167588b38768b15c57f0f0bfccfb87a399f (patch) | |
tree | 67677ec681c60d4195444d7920d3997c03d41f9c /llvm/utils/TableGen/CodeGenDAGPatterns.cpp | |
parent | f56548829c4c696d798c252bf097b71538bd45d7 (diff) | |
download | llvm-aefaf167588b38768b15c57f0f0bfccfb87a399f.zip llvm-aefaf167588b38768b15c57f0f0bfccfb87a399f.tar.gz llvm-aefaf167588b38768b15c57f0f0bfccfb87a399f.tar.bz2 |
[TableGen] Fix both sides of '&&' are same
The operand of the second any_of in EnforceSmallerThan should be
B not S like the FP code in the if below.
Unfortunately, fixing that causes an infinite loop in the build
of RISCV. So I've added a workaround for that as well.
Fixes PR44768.
Reviewed By: RKSimon
Differential Revision: https://reviews.llvm.org/D111502
Diffstat (limited to 'llvm/utils/TableGen/CodeGenDAGPatterns.cpp')
-rw-r--r-- | llvm/utils/TableGen/CodeGenDAGPatterns.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp index ebb4a31..2d0694d 100644 --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -451,13 +451,16 @@ static Iter max_if(Iter B, Iter E, Pred P, Less L) { } /// Make sure that for each type in Small, there exists a larger type in Big. -bool TypeInfer::EnforceSmallerThan(TypeSetByHwMode &Small, - TypeSetByHwMode &Big) { +bool TypeInfer::EnforceSmallerThan(TypeSetByHwMode &Small, TypeSetByHwMode &Big, + bool SmallIsVT) { ValidateOnExit _1(Small, *this), _2(Big, *this); if (TP.hasError()) return false; bool Changed = false; + assert((!SmallIsVT || !Small.empty()) && + "Small should not be empty for SDTCisVTSmallerThanOp"); + if (Small.empty()) Changed |= EnforceAny(Small); if (Big.empty()) @@ -476,7 +479,9 @@ bool TypeInfer::EnforceSmallerThan(TypeSetByHwMode &Small, TypeSetByHwMode::SetType &S = Small.get(M); TypeSetByHwMode::SetType &B = Big.get(M); - if (any_of(S, isIntegerOrPtr) && any_of(S, isIntegerOrPtr)) { + assert((!SmallIsVT || !S.empty()) && "Expected non-empty type"); + + if (any_of(S, isIntegerOrPtr) && any_of(B, isIntegerOrPtr)) { auto NotInt = [](MVT VT) { return !isIntegerOrPtr(VT); }; Changed |= berase_if(S, NotInt); Changed |= berase_if(B, NotInt); @@ -484,6 +489,11 @@ bool TypeInfer::EnforceSmallerThan(TypeSetByHwMode &Small, auto NotFP = [](MVT VT) { return !isFloatingPoint(VT); }; Changed |= berase_if(S, NotFP); Changed |= berase_if(B, NotFP); + } else if (SmallIsVT && B.empty()) { + // B is empty and since S is a specific VT, it will never be empty. Don't + // report this as a change, just clear S and continue. This prevents an + // infinite loop. + S.clear(); } else if (S.empty() || B.empty()) { Changed = !S.empty() || !B.empty(); S.clear(); @@ -1637,7 +1647,8 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N, getOperandNum(x.SDTCisVTSmallerThanOp_Info.OtherOperandNum, N, NodeInfo, OResNo); - return TI.EnforceSmallerThan(TypeListTmp, OtherNode->getExtType(OResNo)); + return TI.EnforceSmallerThan(TypeListTmp, OtherNode->getExtType(OResNo), + /*SmallIsVT*/ true); } case SDTCisOpSmallerThanOp: { unsigned BResNo = 0; |