Skip to content

Commit 4863fc3

Browse files
authored
merge main into amd-staging (llvm#3820)
2 parents cbd2e16 + 5322474 commit 4863fc3

File tree

25 files changed

+274
-91
lines changed

25 files changed

+274
-91
lines changed

clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ AST_MATCHER(Expr, usedInBooleanContext) {
8989
return Result;
9090
}
9191

92-
AST_MATCHER(CXXConstructExpr, isDefaultConstruction) {
93-
return Node.getConstructor()->isDefaultConstructor();
94-
}
95-
9692
AST_MATCHER(QualType, isIntegralType) {
9793
return Node->isIntegralType(Finder->getASTContext());
9894
}
@@ -211,7 +207,7 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
211207
const auto WrongComparend =
212208
anyOf(stringLiteral(hasSize(0)),
213209
userDefinedLiteral(hasLiteral(stringLiteral(hasSize(0)))),
214-
cxxConstructExpr(isDefaultConstruction()),
210+
cxxConstructExpr(argumentCountIs(0)),
215211
cxxUnresolvedConstructExpr(argumentCountIs(0)));
216212
// Match the object being compared.
217213
const auto STLArg =

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ Changes in existing checks
232232

233233
- Improved :doc:`readability-container-size-empty
234234
<clang-tidy/checks/readability/container-size-empty>` check by correctly
235-
generating fix-it hints when size method is called from implicit ``this``
236-
and adding detection in container's method except ``empty``.
235+
generating fix-it hints when size method is called from implicit ``this``,
236+
ignoring default constructors with user provided arguments and adding
237+
detection in container's method except ``empty``.
237238

238239
- Improved :doc:`readability-identifier-naming
239240
<clang-tidy/checks/readability/identifier-naming>` check by ignoring

clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,40 @@ class foo : public std::string{
909909

910910
}
911911

912+
namespace GH154762 {
913+
class TypeRange {
914+
std::vector<int> b;
915+
916+
public:
917+
TypeRange(std::vector<int> b = {});
918+
TypeRange(int);
919+
bool operator==(const TypeRange& other) const;
920+
921+
size_t size() const {
922+
return b.size();
923+
}
924+
925+
bool empty() const {
926+
return size() == 0;
927+
}
928+
};
929+
930+
void foo(std::vector<int> v) {
931+
if (TypeRange(1) == TypeRange(v)) { // no warning
932+
}
933+
934+
if (TypeRange(1) == TypeRange()) {
935+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object
936+
// CHECK-FIXES: if (TypeRange(1).empty()) {
937+
}
938+
939+
if (TypeRange(v) == TypeRange()) {
940+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object
941+
// CHECK-FIXES: if (TypeRange(v).empty()) {
942+
}
943+
}
944+
}
945+
912946
class ReportInContainerNonEmptyMethod {
913947
public:
914948
int size() const;

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,14 @@ class AnnotatingParser {
10451045
}
10461046
}
10471047
// Parse the [DagArgList] part
1048+
return parseTableGenDAGArgList(Opener, BreakInside);
1049+
}
1050+
1051+
// DagArgList ::= "," DagArg [DagArgList]
1052+
// This parses SimpleValue 6's [DagArgList] part.
1053+
bool parseTableGenDAGArgList(FormatToken *Opener, bool BreakInside) {
1054+
ScopedContextCreator ContextCreator(*this, tok::l_paren, 0);
1055+
Contexts.back().IsTableGenDAGArgList = true;
10481056
bool FirstDAGArgListElm = true;
10491057
while (CurrentToken) {
10501058
if (!FirstDAGArgListElm && CurrentToken->is(tok::comma)) {
@@ -1101,6 +1109,9 @@ class AnnotatingParser {
11011109
// SimpleValue6 ::= "(" DagArg [DagArgList] ")"
11021110
if (Tok->is(tok::l_paren)) {
11031111
Tok->setType(TT_TableGenDAGArgOpener);
1112+
// Nested DAGArg requires space before '(' as separator.
1113+
if (Contexts.back().IsTableGenDAGArgList)
1114+
Tok->SpacesRequiredBefore = 1;
11041115
return parseTableGenDAGArgAndList(Tok);
11051116
}
11061117
// SimpleValue 9: Bang operator
@@ -2138,7 +2149,7 @@ class AnnotatingParser {
21382149
// Whether the braces may mean concatenation instead of structure or array
21392150
// literal.
21402151
bool VerilogMayBeConcatenation = false;
2141-
bool IsTableGenDAGArg = false;
2152+
bool IsTableGenDAGArgList = false;
21422153
bool IsTableGenBangOpe = false;
21432154
bool IsTableGenCondOpe = false;
21442155
enum {

clang/unittests/Format/FormatTestTableGen.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,16 @@ TEST_F(FormatTestTableGen, SimpleValue6) {
187187
" );\n"
188188
" let DAGArgBang = (!cast<SomeType>(\"Some\") i32:$src1,\n"
189189
" i32:$src2);\n"
190+
" let NestedDAGArg = ((DAGArg1 (v111 v112, v113), v12) v2,\n"
191+
" (DAGArg3 (v31 v32)));\n"
190192
"}");
191193
}
192194

195+
TEST_F(FormatTestTableGen, SimpleValue6_NestedInPat) {
196+
verifyFormat("def : Pat<(vec.vt (avg (vec.vt V128:$l), (vec.vt V128:$r))),\n"
197+
" (inst $l, $r)>;");
198+
}
199+
193200
TEST_F(FormatTestTableGen, SimpleValue7) {
194201
verifyFormat("def SimpleValue7 { let Identifier = SimpleValue; }");
195202
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,6 +3850,22 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
38503850
Known = KnownBits::ashr(Known, Known2, /*ShAmtNonZero=*/false,
38513851
Op->getFlags().hasExact());
38523852
break;
3853+
case ISD::ROTL:
3854+
case ISD::ROTR:
3855+
if (ConstantSDNode *C =
3856+
isConstOrConstSplat(Op.getOperand(1), DemandedElts)) {
3857+
unsigned Amt = C->getAPIntValue().urem(BitWidth);
3858+
3859+
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
3860+
3861+
// Canonicalize to ROTR.
3862+
if (Opcode == ISD::ROTL && Amt != 0)
3863+
Amt = BitWidth - Amt;
3864+
3865+
Known.Zero = Known.Zero.rotr(Amt);
3866+
Known.One = Known.One.rotr(Amt);
3867+
}
3868+
break;
38533869
case ISD::FSHL:
38543870
case ISD::FSHR:
38553871
if (ConstantSDNode *C = isConstOrConstSplat(Op.getOperand(2), DemandedElts)) {

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9733,43 +9733,46 @@ SDValue TargetLowering::expandABS(SDNode *N, SelectionDAG &DAG,
97339733
SDValue TargetLowering::expandABD(SDNode *N, SelectionDAG &DAG) const {
97349734
SDLoc dl(N);
97359735
EVT VT = N->getValueType(0);
9736-
SDValue LHS = DAG.getFreeze(N->getOperand(0));
9737-
SDValue RHS = DAG.getFreeze(N->getOperand(1));
9736+
SDValue LHS = N->getOperand(0);
9737+
SDValue RHS = N->getOperand(1);
97389738
bool IsSigned = N->getOpcode() == ISD::ABDS;
97399739

97409740
// abds(lhs, rhs) -> sub(smax(lhs,rhs), smin(lhs,rhs))
97419741
// abdu(lhs, rhs) -> sub(umax(lhs,rhs), umin(lhs,rhs))
97429742
unsigned MaxOpc = IsSigned ? ISD::SMAX : ISD::UMAX;
97439743
unsigned MinOpc = IsSigned ? ISD::SMIN : ISD::UMIN;
97449744
if (isOperationLegal(MaxOpc, VT) && isOperationLegal(MinOpc, VT)) {
9745+
LHS = DAG.getFreeze(LHS);
9746+
RHS = DAG.getFreeze(RHS);
97459747
SDValue Max = DAG.getNode(MaxOpc, dl, VT, LHS, RHS);
97469748
SDValue Min = DAG.getNode(MinOpc, dl, VT, LHS, RHS);
97479749
return DAG.getNode(ISD::SUB, dl, VT, Max, Min);
97489750
}
97499751

97509752
// abdu(lhs, rhs) -> or(usubsat(lhs,rhs), usubsat(rhs,lhs))
9751-
if (!IsSigned && isOperationLegal(ISD::USUBSAT, VT))
9753+
if (!IsSigned && isOperationLegal(ISD::USUBSAT, VT)) {
9754+
LHS = DAG.getFreeze(LHS);
9755+
RHS = DAG.getFreeze(RHS);
97529756
return DAG.getNode(ISD::OR, dl, VT,
97539757
DAG.getNode(ISD::USUBSAT, dl, VT, LHS, RHS),
97549758
DAG.getNode(ISD::USUBSAT, dl, VT, RHS, LHS));
9759+
}
97559760

97569761
// If the subtract doesn't overflow then just use abs(sub())
9757-
// NOTE: don't use frozen operands for value tracking.
9758-
bool IsNonNegative = DAG.SignBitIsZero(N->getOperand(1)) &&
9759-
DAG.SignBitIsZero(N->getOperand(0));
9762+
bool IsNonNegative = DAG.SignBitIsZero(LHS) && DAG.SignBitIsZero(RHS);
97609763

9761-
if (DAG.willNotOverflowSub(IsSigned || IsNonNegative, N->getOperand(0),
9762-
N->getOperand(1)))
9764+
if (DAG.willNotOverflowSub(IsSigned || IsNonNegative, LHS, RHS))
97639765
return DAG.getNode(ISD::ABS, dl, VT,
97649766
DAG.getNode(ISD::SUB, dl, VT, LHS, RHS));
97659767

9766-
if (DAG.willNotOverflowSub(IsSigned || IsNonNegative, N->getOperand(1),
9767-
N->getOperand(0)))
9768+
if (DAG.willNotOverflowSub(IsSigned || IsNonNegative, RHS, LHS))
97689769
return DAG.getNode(ISD::ABS, dl, VT,
97699770
DAG.getNode(ISD::SUB, dl, VT, RHS, LHS));
97709771

97719772
EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
97729773
ISD::CondCode CC = IsSigned ? ISD::CondCode::SETGT : ISD::CondCode::SETUGT;
9774+
LHS = DAG.getFreeze(LHS);
9775+
RHS = DAG.getFreeze(RHS);
97739776
SDValue Cmp = DAG.getSetCC(dl, CCVT, LHS, RHS, CC);
97749777

97759778
// Branchless expansion iff cmp result is allbits:

llvm/lib/Target/ARC/ARCInstrFormats.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,12 +964,10 @@ class F16_OP_U7<bit i, string asmstr> :
964964

965965
// Special types for different instruction operands.
966966
def ccond : Operand<i32> {
967-
let MIOperandInfo = (ops i32imm);
968967
let PrintMethod = "printPredicateOperand";
969968
}
970969

971970
def brccond : Operand<i32> {
972-
let MIOperandInfo = (ops i32imm);
973971
let PrintMethod = "printBRCCPredicateOperand";
974972
}
975973

llvm/lib/Target/ARC/ARCInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ include "ARCInstrFormats.td"
1818

1919
// Operand for printing out a condition code.
2020
let PrintMethod = "printCCOperand" in
21-
def CCOp : PredicateOperand<i32, (ops i32imm), (ops)>;
21+
def CCOp : PredicateOperand<i32, (ops), (ops)>;
2222

2323
// The "u6" operand of a RRU6-type instruction
2424
let PrintMethod = "printU6" in {

llvm/lib/Target/ARM/ARMInstrInfo.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ class MVEVectorIndexOperand<int NumLanes> : AsmOperandClass {
765765
class MVEVectorIndex<int NumLanes> : Operand<i32> {
766766
let PrintMethod = "printVectorIndex";
767767
let ParserMatchClass = MVEVectorIndexOperand<NumLanes>;
768-
let MIOperandInfo = (ops i32imm);
769768
}
770769

771770
// shift_imm: An integer that encodes a shift amount and the type of shift
@@ -1181,7 +1180,6 @@ def PostIdxImm8AsmOperand : AsmOperandClass { let Name = "PostIdxImm8"; }
11811180
def postidx_imm8 : MemOperand {
11821181
let PrintMethod = "printPostIdxImm8Operand";
11831182
let ParserMatchClass = PostIdxImm8AsmOperand;
1184-
let MIOperandInfo = (ops i32imm);
11851183
}
11861184

11871185
// postidx_imm8s4 := +/- [0,1020]

0 commit comments

Comments
 (0)