Skip to content

Commit 21a295a

Browse files
committed
Merge branch 'main' into ACCtdAppertainment
2 parents 5c42a53 + f2ecd86 commit 21a295a

File tree

24 files changed

+448
-102
lines changed

24 files changed

+448
-102
lines changed

llvm/include/llvm/Analysis/MemoryLocation.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ class LocationSize {
8080

8181
uint64_t Value;
8282

83-
// Hack to support implicit construction. This should disappear when the
84-
// public LocationSize ctor goes away.
85-
enum DirectConstruction { Direct };
86-
87-
constexpr LocationSize(uint64_t Raw, DirectConstruction) : Value(Raw) {}
83+
constexpr LocationSize(uint64_t Raw) : Value(Raw) {}
8884
constexpr LocationSize(uint64_t Raw, bool Scalable)
8985
: Value(Raw > MaxValue ? AfterPointer
9086
: Raw | (Scalable ? ScalableBit : uint64_t(0))) {}
@@ -96,14 +92,6 @@ class LocationSize {
9692
static_assert(~(MaxValue & ScalableBit), "Max value don't have bit 62 set");
9793

9894
public:
99-
// FIXME: Migrate all users to construct via either `precise` or `upperBound`,
100-
// to make it more obvious at the callsite the kind of size that they're
101-
// providing.
102-
//
103-
// Since the overwhelming majority of users of this provide precise values,
104-
// this assumes the provided value is precise.
105-
constexpr LocationSize(uint64_t Raw)
106-
: Value(Raw > MaxValue ? AfterPointer : Raw) {}
10795
// Create non-scalable LocationSize
10896
static LocationSize precise(uint64_t Value) {
10997
return LocationSize(Value, false /*Scalable*/);
@@ -118,7 +106,7 @@ class LocationSize {
118106
return precise(0);
119107
if (LLVM_UNLIKELY(Value > MaxValue))
120108
return afterPointer();
121-
return LocationSize(Value | ImpreciseBit, Direct);
109+
return LocationSize(Value | ImpreciseBit);
122110
}
123111
static LocationSize upperBound(TypeSize Value) {
124112
if (Value.isScalable())
@@ -129,21 +117,21 @@ class LocationSize {
129117
/// Any location after the base pointer (but still within the underlying
130118
/// object).
131119
constexpr static LocationSize afterPointer() {
132-
return LocationSize(AfterPointer, Direct);
120+
return LocationSize(AfterPointer);
133121
}
134122

135123
/// Any location before or after the base pointer (but still within the
136124
/// underlying object).
137125
constexpr static LocationSize beforeOrAfterPointer() {
138-
return LocationSize(BeforeOrAfterPointer, Direct);
126+
return LocationSize(BeforeOrAfterPointer);
139127
}
140128

141129
// Sentinel values, generally used for maps.
142130
constexpr static LocationSize mapTombstone() {
143-
return LocationSize(MapTombstone, Direct);
131+
return LocationSize(MapTombstone);
144132
}
145133
constexpr static LocationSize mapEmpty() {
146-
return LocationSize(MapEmpty, Direct);
134+
return LocationSize(MapEmpty);
147135
}
148136

149137
// Returns a LocationSize that can correctly represent either `*this` or
@@ -189,14 +177,16 @@ class LocationSize {
189177
bool operator==(const LocationSize &Other) const {
190178
return Value == Other.Value;
191179
}
192-
193180
bool operator==(const TypeSize &Other) const {
194-
return hasValue() && getValue() == Other;
181+
return (*this == LocationSize::precise(Other));
182+
}
183+
bool operator==(uint64_t Other) const {
184+
return (*this == LocationSize::precise(Other));
195185
}
196186

197187
bool operator!=(const LocationSize &Other) const { return !(*this == Other); }
198-
199188
bool operator!=(const TypeSize &Other) const { return !(*this == Other); }
189+
bool operator!=(uint64_t Other) const { return !(*this == Other); }
200190

201191
// Ordering operators are not provided, since it's unclear if there's only one
202192
// reasonable way to compare:
@@ -301,6 +291,12 @@ class MemoryLocation {
301291
explicit MemoryLocation(const Value *Ptr, LocationSize Size,
302292
const AAMDNodes &AATags = AAMDNodes())
303293
: Ptr(Ptr), Size(Size), AATags(AATags) {}
294+
explicit MemoryLocation(const Value *Ptr, TypeSize Size,
295+
const AAMDNodes &AATags = AAMDNodes())
296+
: Ptr(Ptr), Size(LocationSize::precise(Size)), AATags(AATags) {}
297+
explicit MemoryLocation(const Value *Ptr, uint64_t Size,
298+
const AAMDNodes &AATags = AAMDNodes())
299+
: Ptr(Ptr), Size(LocationSize::precise(Size)), AATags(AATags) {}
304300

305301
MemoryLocation getWithNewPtr(const Value *NewPtr) const {
306302
MemoryLocation Copy(*this);
@@ -313,6 +309,12 @@ class MemoryLocation {
313309
Copy.Size = NewSize;
314310
return Copy;
315311
}
312+
MemoryLocation getWithNewSize(uint64_t NewSize) const {
313+
return getWithNewSize(LocationSize::precise(NewSize));
314+
}
315+
MemoryLocation getWithNewSize(TypeSize NewSize) const {
316+
return getWithNewSize(LocationSize::precise(NewSize));
317+
}
316318

317319
MemoryLocation getWithoutAATags() const {
318320
MemoryLocation Copy(*this);

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,16 @@ class LLVM_ABI MachineFunction {
10721072
const MDNode *Ranges = nullptr, SyncScope::ID SSID = SyncScope::System,
10731073
AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
10741074
AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic);
1075+
MachineMemOperand *getMachineMemOperand(
1076+
MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, uint64_t Size,
1077+
Align BaseAlignment, const AAMDNodes &AAInfo = AAMDNodes(),
1078+
const MDNode *Ranges = nullptr, SyncScope::ID SSID = SyncScope::System,
1079+
AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
1080+
AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic) {
1081+
return getMachineMemOperand(PtrInfo, F, LocationSize::precise(Size),
1082+
BaseAlignment, AAInfo, Ranges, SSID, Ordering,
1083+
FailureOrdering);
1084+
}
10751085
MachineMemOperand *getMachineMemOperand(
10761086
MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, TypeSize Size,
10771087
Align BaseAlignment, const AAMDNodes &AAInfo = AAMDNodes(),
@@ -1098,6 +1108,10 @@ class LLVM_ABI MachineFunction {
10981108
? LLT::scalable_vector(1, 8 * Size.getValue().getKnownMinValue())
10991109
: LLT::scalar(8 * Size.getValue().getKnownMinValue()));
11001110
}
1111+
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
1112+
int64_t Offset, uint64_t Size) {
1113+
return getMachineMemOperand(MMO, Offset, LocationSize::precise(Size));
1114+
}
11011115
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
11021116
int64_t Offset, TypeSize Size) {
11031117
return getMachineMemOperand(MMO, Offset, LocationSize::precise(Size));
@@ -1113,6 +1127,11 @@ class LLVM_ABI MachineFunction {
11131127
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
11141128
const MachinePointerInfo &PtrInfo,
11151129
LLT Ty);
1130+
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
1131+
const MachinePointerInfo &PtrInfo,
1132+
uint64_t Size) {
1133+
return getMachineMemOperand(MMO, PtrInfo, LocationSize::precise(Size));
1134+
}
11161135
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
11171136
const MachinePointerInfo &PtrInfo,
11181137
TypeSize Size) {

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,15 +1345,17 @@ class SelectionDAG {
13451345
EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment,
13461346
MachineMemOperand::Flags Flags = MachineMemOperand::MOLoad |
13471347
MachineMemOperand::MOStore,
1348-
LocationSize Size = 0, const AAMDNodes &AAInfo = AAMDNodes());
1348+
LocationSize Size = LocationSize::precise(0),
1349+
const AAMDNodes &AAInfo = AAMDNodes());
13491350

13501351
inline SDValue getMemIntrinsicNode(
13511352
unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef<SDValue> Ops,
13521353
EVT MemVT, MachinePointerInfo PtrInfo,
13531354
MaybeAlign Alignment = std::nullopt,
13541355
MachineMemOperand::Flags Flags = MachineMemOperand::MOLoad |
13551356
MachineMemOperand::MOStore,
1356-
LocationSize Size = 0, const AAMDNodes &AAInfo = AAMDNodes()) {
1357+
LocationSize Size = LocationSize::precise(0),
1358+
const AAMDNodes &AAInfo = AAMDNodes()) {
13571359
// Ensure that codegen never sees alignment 0
13581360
return getMemIntrinsicNode(Opcode, dl, VTList, Ops, MemVT, PtrInfo,
13591361
Alignment.value_or(getEVTAlign(MemVT)), Flags,

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,6 +3804,63 @@ static bool isNonEqualPointersWithRecursiveGEP(const Value *A, const Value *B,
38043804
(StartOffset.sle(OffsetB) && StepOffset.isNegative()));
38053805
}
38063806

3807+
static bool isKnownNonEqualFromContext(const Value *V1, const Value *V2,
3808+
unsigned Depth, const SimplifyQuery &Q) {
3809+
if (!Q.CxtI)
3810+
return false;
3811+
3812+
// Try to infer NonEqual based on information from dominating conditions.
3813+
if (Q.DC && Q.DT) {
3814+
auto IsKnownNonEqualFromDominatingCondition = [&](const Value *V) {
3815+
for (BranchInst *BI : Q.DC->conditionsFor(V)) {
3816+
Value *Cond = BI->getCondition();
3817+
BasicBlockEdge Edge0(BI->getParent(), BI->getSuccessor(0));
3818+
if (Q.DT->dominates(Edge0, Q.CxtI->getParent()) &&
3819+
isImpliedCondition(Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL,
3820+
/*LHSIsTrue=*/true, Depth)
3821+
.value_or(false))
3822+
return true;
3823+
3824+
BasicBlockEdge Edge1(BI->getParent(), BI->getSuccessor(1));
3825+
if (Q.DT->dominates(Edge1, Q.CxtI->getParent()) &&
3826+
isImpliedCondition(Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL,
3827+
/*LHSIsTrue=*/false, Depth)
3828+
.value_or(false))
3829+
return true;
3830+
}
3831+
3832+
return false;
3833+
};
3834+
3835+
if (IsKnownNonEqualFromDominatingCondition(V1) ||
3836+
IsKnownNonEqualFromDominatingCondition(V2))
3837+
return true;
3838+
}
3839+
3840+
if (!Q.AC)
3841+
return false;
3842+
3843+
// Try to infer NonEqual based on information from assumptions.
3844+
for (auto &AssumeVH : Q.AC->assumptionsFor(V1)) {
3845+
if (!AssumeVH)
3846+
continue;
3847+
CallInst *I = cast<CallInst>(AssumeVH);
3848+
3849+
assert(I->getFunction() == Q.CxtI->getFunction() &&
3850+
"Got assumption for the wrong function!");
3851+
assert(I->getIntrinsicID() == Intrinsic::assume &&
3852+
"must be an assume intrinsic");
3853+
3854+
if (isImpliedCondition(I->getArgOperand(0), ICmpInst::ICMP_NE, V1, V2, Q.DL,
3855+
/*LHSIsTrue=*/true, Depth)
3856+
.value_or(false) &&
3857+
isValidAssumeForContext(I, Q.CxtI, Q.DT))
3858+
return true;
3859+
}
3860+
3861+
return false;
3862+
}
3863+
38073864
/// Return true if it is known that V1 != V2.
38083865
static bool isKnownNonEqual(const Value *V1, const Value *V2,
38093866
const APInt &DemandedElts, unsigned Depth,
@@ -3875,49 +3932,8 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
38753932
match(V2, m_PtrToIntSameSize(Q.DL, m_Value(B))))
38763933
return isKnownNonEqual(A, B, DemandedElts, Depth + 1, Q);
38773934

3878-
if (!Q.CxtI)
3879-
return false;
3880-
3881-
// Try to infer NonEqual based on information from dominating conditions.
3882-
if (Q.DC && Q.DT) {
3883-
for (BranchInst *BI : Q.DC->conditionsFor(V1)) {
3884-
Value *Cond = BI->getCondition();
3885-
BasicBlockEdge Edge0(BI->getParent(), BI->getSuccessor(0));
3886-
if (Q.DT->dominates(Edge0, Q.CxtI->getParent()) &&
3887-
isImpliedCondition(Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL,
3888-
/*LHSIsTrue=*/true, Depth)
3889-
.value_or(false))
3890-
return true;
3891-
3892-
BasicBlockEdge Edge1(BI->getParent(), BI->getSuccessor(1));
3893-
if (Q.DT->dominates(Edge1, Q.CxtI->getParent()) &&
3894-
isImpliedCondition(Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL,
3895-
/*LHSIsTrue=*/false, Depth)
3896-
.value_or(false))
3897-
return true;
3898-
}
3899-
}
3900-
3901-
if (!Q.AC)
3902-
return false;
3903-
3904-
// Try to infer NonEqual based on information from assumptions.
3905-
for (auto &AssumeVH : Q.AC->assumptionsFor(V1)) {
3906-
if (!AssumeVH)
3907-
continue;
3908-
CallInst *I = cast<CallInst>(AssumeVH);
3909-
3910-
assert(I->getFunction() == Q.CxtI->getFunction() &&
3911-
"Got assumption for the wrong function!");
3912-
assert(I->getIntrinsicID() == Intrinsic::assume &&
3913-
"must be an assume intrinsic");
3914-
3915-
if (isImpliedCondition(I->getArgOperand(0), ICmpInst::ICMP_NE, V1, V2, Q.DL,
3916-
/*LHSIsTrue=*/true, Depth)
3917-
.value_or(false) &&
3918-
isValidAssumeForContext(I, Q.CxtI, Q.DT))
3919-
return true;
3920-
}
3935+
if (isKnownNonEqualFromContext(V1, V2, Depth, Q))
3936+
return true;
39213937

39223938
return false;
39233939
}
@@ -10348,7 +10364,8 @@ void llvm::findValuesAffectedByCondition(
1034810364
bool HasRHSC = match(B, m_ConstantInt());
1034910365
if (ICmpInst::isEquality(Pred)) {
1035010366
AddAffected(A);
10351-
AddAffected(B);
10367+
if (IsAssume)
10368+
AddAffected(B);
1035210369
if (HasRHSC) {
1035310370
Value *Y;
1035410371
// (X & C) or (X | C).

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ void BaseMemOpClusterMutation::collectMemOpRecords(
21062106
SmallVector<const MachineOperand *, 4> BaseOps;
21072107
int64_t Offset;
21082108
bool OffsetIsScalable;
2109-
LocationSize Width = 0;
2109+
LocationSize Width = LocationSize::precise(0);
21102110
if (TII->getMemOperandsWithOffsetWidth(MI, BaseOps, Offset,
21112111
OffsetIsScalable, Width, TRI)) {
21122112
if (!Width.hasValue())

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5298,9 +5298,9 @@ void SelectionDAGBuilder::visitTargetIntrinsic(const CallInst &I,
52985298
MPI = MachinePointerInfo(Info.ptrVal, Info.offset);
52995299
else if (Info.fallbackAddressSpace)
53005300
MPI = MachinePointerInfo(*Info.fallbackAddressSpace);
5301-
Result = DAG.getMemIntrinsicNode(Info.opc, getCurSDLoc(), VTs, Ops,
5302-
Info.memVT, MPI, Info.align, Info.flags,
5303-
Info.size, I.getAAMetadata());
5301+
Result = DAG.getMemIntrinsicNode(
5302+
Info.opc, getCurSDLoc(), VTs, Ops, Info.memVT, MPI, Info.align,
5303+
Info.flags, LocationSize::precise(Info.size), I.getAAMetadata());
53045304
} else if (!HasChain) {
53055305
Result = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, getCurSDLoc(), VTs, Ops);
53065306
} else if (!I.getType()->isVoidTy()) {

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ bool TargetInstrInfo::getMemOperandWithOffset(
17161716
const MachineInstr &MI, const MachineOperand *&BaseOp, int64_t &Offset,
17171717
bool &OffsetIsScalable, const TargetRegisterInfo *TRI) const {
17181718
SmallVector<const MachineOperand *, 4> BaseOps;
1719-
LocationSize Width = 0;
1719+
LocationSize Width = LocationSize::precise(0);
17201720
if (!getMemOperandsWithOffsetWidth(MI, BaseOps, Offset, OffsetIsScalable,
17211721
Width, TRI) ||
17221722
BaseOps.size() != 1)

llvm/lib/Target/AMDGPU/SIInsertHardClauses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class SIInsertHardClauses {
199199

200200
int64_t Dummy1;
201201
bool Dummy2;
202-
LocationSize Dummy3 = 0;
202+
LocationSize Dummy3 = LocationSize::precise(0);
203203
SmallVector<const MachineOperand *, 4> BaseOps;
204204
if (Type <= LAST_REAL_HARDCLAUSE_TYPE) {
205205
if (!SII->getMemOperandsWithOffsetWidth(MI, BaseOps, Dummy1, Dummy2,

0 commit comments

Comments
 (0)