Skip to content

Commit 10c5c64

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:25002b7aeb2f into amd-gfx:8ae830866bb0
Local branch amd-gfx 8ae8308 Merged main:3d7802d2107f into amd-gfx:3573343a8b3e Remote branch main 25002b7 [InstCombine] Add additional aligned allocation tests for llvm#69474.
2 parents 8ae8308 + 25002b7 commit 10c5c64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+12649
-255
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ namespace interp {
2929
template <class Emitter> class DeclScope final : public VariableScope<Emitter> {
3030
public:
3131
DeclScope(ByteCodeExprGen<Emitter> *Ctx, const ValueDecl *VD)
32-
: VariableScope<Emitter>(Ctx), Scope(Ctx->P, VD) {}
32+
: VariableScope<Emitter>(Ctx), Scope(Ctx->P, VD),
33+
OldGlobalDecl(Ctx->GlobalDecl) {
34+
Ctx->GlobalDecl = Context::shouldBeGloballyIndexed(VD);
35+
}
3336

3437
void addExtended(const Scope::Local &Local) override {
3538
return this->addLocal(Local);
3639
}
3740

41+
~DeclScope() { this->Ctx->GlobalDecl = OldGlobalDecl; }
42+
3843
private:
3944
Program::DeclScope Scope;
45+
bool OldGlobalDecl;
4046
};
4147

4248
/// Scope used to handle initialization methods.
@@ -1198,21 +1204,30 @@ bool ByteCodeExprGen<Emitter>::VisitMaterializeTemporaryExpr(
11981204
if (DiscardResult)
11991205
return this->discard(SubExpr);
12001206

1207+
// When we're initializing a global variable *or* the storage duration of
1208+
// the temporary is explicitly static, create a global variable.
12011209
std::optional<PrimType> SubExprT = classify(SubExpr);
1202-
if (E->getStorageDuration() == SD_Static) {
1210+
bool IsStatic = E->getStorageDuration() == SD_Static;
1211+
if (GlobalDecl || IsStatic) {
12031212
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
12041213
if (!GlobalIndex)
12051214
return false;
12061215

12071216
const LifetimeExtendedTemporaryDecl *TempDecl =
12081217
E->getLifetimeExtendedTemporaryDecl();
1209-
assert(TempDecl);
1218+
if (IsStatic)
1219+
assert(TempDecl);
12101220

12111221
if (SubExprT) {
12121222
if (!this->visit(SubExpr))
12131223
return false;
1214-
if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
1215-
return false;
1224+
if (IsStatic) {
1225+
if (!this->emitInitGlobalTemp(*SubExprT, *GlobalIndex, TempDecl, E))
1226+
return false;
1227+
} else {
1228+
if (!this->emitInitGlobal(*SubExprT, *GlobalIndex, E))
1229+
return false;
1230+
}
12161231
return this->emitGetPtrGlobal(*GlobalIndex, E);
12171232
}
12181233

@@ -1221,7 +1236,9 @@ bool ByteCodeExprGen<Emitter>::VisitMaterializeTemporaryExpr(
12211236
return false;
12221237
if (!this->visitInitializer(SubExpr))
12231238
return false;
1224-
return this->emitInitGlobalTempComp(TempDecl, E);
1239+
if (IsStatic)
1240+
return this->emitInitGlobalTempComp(TempDecl, E);
1241+
return true;
12251242
}
12261243

12271244
// For everyhing else, use local variables.

clang/lib/AST/Interp/ByteCodeExprGen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
304304
/// Flag inidicating if we're initializing an already created
305305
/// variable. This is set in visitInitializer().
306306
bool Initializing = false;
307+
308+
/// Flag indicating if we're initializing a global variable.
309+
bool GlobalDecl = false;
307310
};
308311

309312
extern template class ByteCodeExprGen<ByteCodeEmitter>;

clang/lib/AST/Interp/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ enum class IncDecOp {
522522

523523
template <typename T, IncDecOp Op, PushVal DoPush>
524524
bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
525-
T Value = Ptr.deref<T>();
525+
const T &Value = Ptr.deref<T>();
526526
T Result;
527527

528528
if constexpr (DoPush == PushVal::Yes)

clang/test/AST/Interp/records.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,22 @@ namespace ParenInit {
10641064
};
10651065

10661066
constexpr B b(A(1),2);
1067+
1068+
1069+
struct O {
1070+
int &&j;
1071+
};
1072+
1073+
/// Not constexpr!
1074+
O o1(0);
1075+
constinit O o2(0); // ref-error {{variable does not have a constant initializer}} \
1076+
// ref-note {{required by 'constinit' specifier}} \
1077+
// ref-note {{reference to temporary is not a constant expression}} \
1078+
// ref-note {{temporary created here}} \
1079+
// expected-error {{variable does not have a constant initializer}} \
1080+
// expected-note {{required by 'constinit' specifier}} \
1081+
// expected-note {{reference to temporary is not a constant expression}} \
1082+
// expected-note {{temporary created here}}
10671083
}
10681084
#endif
10691085

clang/test/SemaCXX/paren-list-agg-init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
2+
// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only -fexperimental-new-constant-interpreter
3+
// RUN: %clang_cc1 -verify=expected,beforecxx20 -Wc++20-extensions -std=c++20 %s -fsyntax-only -fexperimental-new-constant-interpreter
24
// RUN: %clang_cc1 -verify=expected,beforecxx20 -Wc++20-extensions -std=c++20 %s -fsyntax-only
35

46
struct A { // expected-note 4{{candidate constructor}}

llvm/docs/LangRef.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15760,7 +15760,8 @@ Syntax:
1576015760
"""""""
1576115761

1576215762
This is an overloaded intrinsic. You can use ``llvm.lrint`` on any
15763-
floating-point type. Not all targets support all types however.
15763+
floating-point type or vector of floating-point type. Not all targets
15764+
support all types however.
1576415765

1576515766
::
1576615767

@@ -15804,7 +15805,8 @@ Syntax:
1580415805
"""""""
1580515806

1580615807
This is an overloaded intrinsic. You can use ``llvm.llrint`` on any
15807-
floating-point type. Not all targets support all types however.
15808+
floating-point type or vector of floating-point type. Not all targets
15809+
support all types however.
1580815810

1580915811
::
1581015812

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,12 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
18471847
case Intrinsic::rint:
18481848
ISD = ISD::FRINT;
18491849
break;
1850+
case Intrinsic::lrint:
1851+
ISD = ISD::LRINT;
1852+
break;
1853+
case Intrinsic::llrint:
1854+
ISD = ISD::LLRINT;
1855+
break;
18501856
case Intrinsic::round:
18511857
ISD = ISD::FROUND;
18521858
break;

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 477999
19+
#define LLVM_MAIN_REVISION 478009
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ namespace {
505505
SDValue visitUINT_TO_FP(SDNode *N);
506506
SDValue visitFP_TO_SINT(SDNode *N);
507507
SDValue visitFP_TO_UINT(SDNode *N);
508+
SDValue visitXRINT(SDNode *N);
508509
SDValue visitFP_ROUND(SDNode *N);
509510
SDValue visitFP_EXTEND(SDNode *N);
510511
SDValue visitFNEG(SDNode *N);
@@ -1911,6 +1912,7 @@ void DAGCombiner::Run(CombineLevel AtLevel) {
19111912
}
19121913

19131914
SDValue DAGCombiner::visit(SDNode *N) {
1915+
// clang-format off
19141916
switch (N->getOpcode()) {
19151917
default: break;
19161918
case ISD::TokenFactor: return visitTokenFactor(N);
@@ -2011,6 +2013,8 @@ SDValue DAGCombiner::visit(SDNode *N) {
20112013
case ISD::UINT_TO_FP: return visitUINT_TO_FP(N);
20122014
case ISD::FP_TO_SINT: return visitFP_TO_SINT(N);
20132015
case ISD::FP_TO_UINT: return visitFP_TO_UINT(N);
2016+
case ISD::LRINT:
2017+
case ISD::LLRINT: return visitXRINT(N);
20142018
case ISD::FP_ROUND: return visitFP_ROUND(N);
20152019
case ISD::FP_EXTEND: return visitFP_EXTEND(N);
20162020
case ISD::FNEG: return visitFNEG(N);
@@ -2065,6 +2069,7 @@ SDValue DAGCombiner::visit(SDNode *N) {
20652069
#include "llvm/IR/VPIntrinsics.def"
20662070
return visitVPOp(N);
20672071
}
2072+
// clang-format on
20682073
return SDValue();
20692074
}
20702075

@@ -17480,6 +17485,21 @@ SDValue DAGCombiner::visitFP_TO_UINT(SDNode *N) {
1748017485
return FoldIntToFPToInt(N, DAG);
1748117486
}
1748217487

17488+
SDValue DAGCombiner::visitXRINT(SDNode *N) {
17489+
SDValue N0 = N->getOperand(0);
17490+
EVT VT = N->getValueType(0);
17491+
17492+
// fold (lrint|llrint undef) -> undef
17493+
if (N0.isUndef())
17494+
return DAG.getUNDEF(VT);
17495+
17496+
// fold (lrint|llrint c1fp) -> c1
17497+
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
17498+
return DAG.getNode(N->getOpcode(), SDLoc(N), VT, N0);
17499+
17500+
return SDValue();
17501+
}
17502+
1748317503
SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
1748417504
SDValue N0 = N->getOperand(0);
1748517505
SDValue N1 = N->getOperand(1);

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,7 @@ bool DAGTypeLegalizer::PromoteFloatOperand(SDNode *N, unsigned OpNo) {
21982198
// to use the promoted float operand. Nodes that produce at least one
21992199
// promotion-requiring floating point result have their operands legalized as
22002200
// a part of PromoteFloatResult.
2201+
// clang-format off
22012202
switch (N->getOpcode()) {
22022203
default:
22032204
#ifndef NDEBUG
@@ -2209,7 +2210,9 @@ bool DAGTypeLegalizer::PromoteFloatOperand(SDNode *N, unsigned OpNo) {
22092210
case ISD::BITCAST: R = PromoteFloatOp_BITCAST(N, OpNo); break;
22102211
case ISD::FCOPYSIGN: R = PromoteFloatOp_FCOPYSIGN(N, OpNo); break;
22112212
case ISD::FP_TO_SINT:
2212-
case ISD::FP_TO_UINT: R = PromoteFloatOp_FP_TO_XINT(N, OpNo); break;
2213+
case ISD::FP_TO_UINT:
2214+
case ISD::LRINT:
2215+
case ISD::LLRINT: R = PromoteFloatOp_UnaryOp(N, OpNo); break;
22132216
case ISD::FP_TO_SINT_SAT:
22142217
case ISD::FP_TO_UINT_SAT:
22152218
R = PromoteFloatOp_FP_TO_XINT_SAT(N, OpNo); break;
@@ -2218,6 +2221,7 @@ bool DAGTypeLegalizer::PromoteFloatOperand(SDNode *N, unsigned OpNo) {
22182221
case ISD::SETCC: R = PromoteFloatOp_SETCC(N, OpNo); break;
22192222
case ISD::STORE: R = PromoteFloatOp_STORE(N, OpNo); break;
22202223
}
2224+
// clang-format on
22212225

22222226
if (R.getNode())
22232227
ReplaceValueWith(SDValue(N, 0), R);
@@ -2251,7 +2255,7 @@ SDValue DAGTypeLegalizer::PromoteFloatOp_FCOPYSIGN(SDNode *N, unsigned OpNo) {
22512255
}
22522256

22532257
// Convert the promoted float value to the desired integer type
2254-
SDValue DAGTypeLegalizer::PromoteFloatOp_FP_TO_XINT(SDNode *N, unsigned OpNo) {
2258+
SDValue DAGTypeLegalizer::PromoteFloatOp_UnaryOp(SDNode *N, unsigned OpNo) {
22552259
SDValue Op = GetPromotedFloat(N->getOperand(0));
22562260
return DAG.getNode(N->getOpcode(), SDLoc(N), N->getValueType(0), Op);
22572261
}

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
711711
SDValue PromoteFloatOp_BITCAST(SDNode *N, unsigned OpNo);
712712
SDValue PromoteFloatOp_FCOPYSIGN(SDNode *N, unsigned OpNo);
713713
SDValue PromoteFloatOp_FP_EXTEND(SDNode *N, unsigned OpNo);
714-
SDValue PromoteFloatOp_FP_TO_XINT(SDNode *N, unsigned OpNo);
714+
SDValue PromoteFloatOp_UnaryOp(SDNode *N, unsigned OpNo);
715715
SDValue PromoteFloatOp_FP_TO_XINT_SAT(SDNode *N, unsigned OpNo);
716716
SDValue PromoteFloatOp_STORE(SDNode *N, unsigned OpNo);
717717
SDValue PromoteFloatOp_SELECT_CC(SDNode *N, unsigned OpNo);

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
402402
case ISD::FCEIL:
403403
case ISD::FTRUNC:
404404
case ISD::FRINT:
405+
case ISD::LRINT:
406+
case ISD::LLRINT:
405407
case ISD::FNEARBYINT:
406408
case ISD::FROUND:
407409
case ISD::FROUNDEVEN:

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ void DAGTypeLegalizer::ScalarizeVectorResult(SDNode *N, unsigned ResNo) {
101101
case ISD::FP_TO_SINT:
102102
case ISD::FP_TO_UINT:
103103
case ISD::FRINT:
104+
case ISD::LRINT:
105+
case ISD::LLRINT:
104106
case ISD::FROUND:
105107
case ISD::FROUNDEVEN:
106108
case ISD::FSIN:
@@ -681,6 +683,8 @@ bool DAGTypeLegalizer::ScalarizeVectorOperand(SDNode *N, unsigned OpNo) {
681683
case ISD::FP_TO_UINT:
682684
case ISD::SINT_TO_FP:
683685
case ISD::UINT_TO_FP:
686+
case ISD::LRINT:
687+
case ISD::LLRINT:
684688
Res = ScalarizeVecOp_UnaryOp(N);
685689
break;
686690
case ISD::STRICT_SINT_TO_FP:
@@ -1097,6 +1101,8 @@ void DAGTypeLegalizer::SplitVectorResult(SDNode *N, unsigned ResNo) {
10971101
case ISD::VP_FP_TO_UINT:
10981102
case ISD::FRINT:
10991103
case ISD::VP_FRINT:
1104+
case ISD::LRINT:
1105+
case ISD::LLRINT:
11001106
case ISD::FROUND:
11011107
case ISD::VP_FROUND:
11021108
case ISD::FROUNDEVEN:
@@ -2974,6 +2980,8 @@ bool DAGTypeLegalizer::SplitVectorOperand(SDNode *N, unsigned OpNo) {
29742980
case ISD::ZERO_EXTEND:
29752981
case ISD::ANY_EXTEND:
29762982
case ISD::FTRUNC:
2983+
case ISD::LRINT:
2984+
case ISD::LLRINT:
29772985
Res = SplitVecOp_UnaryOp(N);
29782986
break;
29792987
case ISD::FLDEXP:
@@ -4209,6 +4217,8 @@ void DAGTypeLegalizer::WidenVectorResult(SDNode *N, unsigned ResNo) {
42094217
case ISD::FLOG2:
42104218
case ISD::FNEARBYINT:
42114219
case ISD::FRINT:
4220+
case ISD::LRINT:
4221+
case ISD::LLRINT:
42124222
case ISD::FROUND:
42134223
case ISD::FROUNDEVEN:
42144224
case ISD::FSIN:
@@ -5958,7 +5968,11 @@ bool DAGTypeLegalizer::WidenVectorOperand(SDNode *N, unsigned OpNo) {
59585968
case ISD::STRICT_FSETCCS: Res = WidenVecOp_STRICT_FSETCC(N); break;
59595969
case ISD::VSELECT: Res = WidenVecOp_VSELECT(N); break;
59605970
case ISD::FLDEXP:
5961-
case ISD::FCOPYSIGN: Res = WidenVecOp_UnrollVectorOp(N); break;
5971+
case ISD::FCOPYSIGN:
5972+
case ISD::LRINT:
5973+
case ISD::LLRINT:
5974+
Res = WidenVecOp_UnrollVectorOp(N);
5975+
break;
59625976
case ISD::IS_FPCLASS: Res = WidenVecOp_IS_FPCLASS(N); break;
59635977

59645978
case ISD::ANY_EXTEND:

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5011,8 +5011,6 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
50115011

50125012
unsigned Opcode = Op.getOpcode();
50135013
switch (Opcode) {
5014-
case ISD::AssertSext:
5015-
case ISD::AssertZext:
50165014
case ISD::FREEZE:
50175015
case ISD::CONCAT_VECTORS:
50185016
case ISD::INSERT_SUBVECTOR:
@@ -5135,6 +5133,8 @@ bool SelectionDAG::isKnownNeverNaN(SDValue Op, bool SNaN, unsigned Depth) const
51355133
case ISD::FROUND:
51365134
case ISD::FROUNDEVEN:
51375135
case ISD::FRINT:
5136+
case ISD::LRINT:
5137+
case ISD::LLRINT:
51385138
case ISD::FNEARBYINT:
51395139
case ISD::FLDEXP: {
51405140
if (SNaN)

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,13 +873,13 @@ void TargetLoweringBase::initActions() {
873873

874874
// These operations default to expand for vector types.
875875
if (VT.isVector())
876-
setOperationAction({ISD::FCOPYSIGN, ISD::SIGN_EXTEND_INREG,
877-
ISD::ANY_EXTEND_VECTOR_INREG,
878-
ISD::SIGN_EXTEND_VECTOR_INREG,
879-
ISD::ZERO_EXTEND_VECTOR_INREG, ISD::SPLAT_VECTOR},
880-
VT, Expand);
876+
setOperationAction(
877+
{ISD::FCOPYSIGN, ISD::SIGN_EXTEND_INREG, ISD::ANY_EXTEND_VECTOR_INREG,
878+
ISD::SIGN_EXTEND_VECTOR_INREG, ISD::ZERO_EXTEND_VECTOR_INREG,
879+
ISD::SPLAT_VECTOR, ISD::LRINT, ISD::LLRINT},
880+
VT, Expand);
881881

882-
// Constrained floating-point operations default to expand.
882+
// Constrained floating-point operations default to expand.
883883
#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
884884
setOperationAction(ISD::STRICT_##DAGN, VT, Expand);
885885
#include "llvm/IR/ConstrainedOps.def"

llvm/lib/IR/Verifier.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5669,10 +5669,28 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
56695669
}
56705670
break;
56715671
}
5672-
case Intrinsic::lround:
5673-
case Intrinsic::llround:
56745672
case Intrinsic::lrint:
56755673
case Intrinsic::llrint: {
5674+
Type *ValTy = Call.getArgOperand(0)->getType();
5675+
Type *ResultTy = Call.getType();
5676+
Check(
5677+
ValTy->isFPOrFPVectorTy() && ResultTy->isIntOrIntVectorTy(),
5678+
"llvm.lrint, llvm.llrint: argument must be floating-point or vector "
5679+
"of floating-points, and result must be integer or vector of integers",
5680+
&Call);
5681+
Check(ValTy->isVectorTy() == ResultTy->isVectorTy(),
5682+
"llvm.lrint, llvm.llrint: argument and result disagree on vector use",
5683+
&Call);
5684+
if (ValTy->isVectorTy()) {
5685+
Check(cast<VectorType>(ValTy)->getElementCount() ==
5686+
cast<VectorType>(ResultTy)->getElementCount(),
5687+
"llvm.lrint, llvm.llrint: argument must be same length as result",
5688+
&Call);
5689+
}
5690+
break;
5691+
}
5692+
case Intrinsic::lround:
5693+
case Intrinsic::llround: {
56765694
Type *ValTy = Call.getArgOperand(0)->getType();
56775695
Type *ResultTy = Call.getType();
56785696
Check(!ValTy->isVectorTy() && !ResultTy->isVectorTy(),

0 commit comments

Comments
 (0)