Skip to content

Commit 8ee7ef6

Browse files
authored
[GlobalISel] Use LocationSize in GISelAddressing. NFC (#83885)
This is similar to #83017 but for the areas in GlobalISel's LoadStoreOpt, and should help simplify #70452 a little. It will likely change a little again once the sizes can be scalable.
1 parent 1c6e09c commit 8ee7ef6

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ bool GISelAddressing::aliasIsKnownForLoadStore(const MachineInstr &MI1,
117117
if (!BasePtr0.BaseReg.isValid() || !BasePtr1.BaseReg.isValid())
118118
return false;
119119

120-
int64_t Size1 = LdSt1->getMemSize();
121-
int64_t Size2 = LdSt2->getMemSize();
120+
LocationSize Size1 = LdSt1->getMemSize() != MemoryLocation::UnknownSize
121+
? LdSt1->getMemSize()
122+
: LocationSize::beforeOrAfterPointer();
123+
LocationSize Size2 = LdSt2->getMemSize() != MemoryLocation::UnknownSize
124+
? LdSt2->getMemSize()
125+
: LocationSize::beforeOrAfterPointer();
122126

123127
int64_t PtrDiff;
124128
if (BasePtr0.BaseReg == BasePtr1.BaseReg) {
@@ -128,20 +132,18 @@ bool GISelAddressing::aliasIsKnownForLoadStore(const MachineInstr &MI1,
128132
// vector objects on the stack.
129133
// BasePtr1 is PtrDiff away from BasePtr0. They alias if none of the
130134
// following situations arise:
131-
if (PtrDiff >= 0 &&
132-
Size1 != static_cast<int64_t>(MemoryLocation::UnknownSize)) {
135+
if (PtrDiff >= 0 && Size1.hasValue()) {
133136
// [----BasePtr0----]
134137
// [---BasePtr1--]
135138
// ========PtrDiff========>
136-
IsAlias = !(Size1 <= PtrDiff);
139+
IsAlias = !((int64_t)Size1.getValue() <= PtrDiff);
137140
return true;
138141
}
139-
if (PtrDiff < 0 &&
140-
Size2 != static_cast<int64_t>(MemoryLocation::UnknownSize)) {
142+
if (PtrDiff < 0 && Size2.hasValue()) {
141143
// [----BasePtr0----]
142144
// [---BasePtr1--]
143145
// =====(-PtrDiff)====>
144-
IsAlias = !((PtrDiff + Size2) <= 0);
146+
IsAlias = !((PtrDiff + (int64_t)Size2.getValue()) <= 0);
145147
return true;
146148
}
147149
return false;
@@ -196,7 +198,7 @@ bool GISelAddressing::instMayAlias(const MachineInstr &MI,
196198
bool IsAtomic;
197199
Register BasePtr;
198200
int64_t Offset;
199-
uint64_t NumBytes;
201+
LocationSize NumBytes;
200202
MachineMemOperand *MMO;
201203
};
202204

@@ -212,16 +214,22 @@ bool GISelAddressing::instMayAlias(const MachineInstr &MI,
212214
Offset = 0;
213215
}
214216

215-
uint64_t Size = MemoryLocation::getSizeOrUnknown(
216-
LS->getMMO().getMemoryType().getSizeInBytes());
217-
return {LS->isVolatile(), LS->isAtomic(), BaseReg,
218-
Offset /*base offset*/, Size, &LS->getMMO()};
217+
TypeSize Size = LS->getMMO().getMemoryType().getSizeInBytes();
218+
return {LS->isVolatile(),
219+
LS->isAtomic(),
220+
BaseReg,
221+
Offset /*base offset*/,
222+
Size.isScalable() ? LocationSize::beforeOrAfterPointer()
223+
: LocationSize::precise(Size),
224+
&LS->getMMO()};
219225
}
220226
// FIXME: support recognizing lifetime instructions.
221227
// Default.
222228
return {false /*isvolatile*/,
223-
/*isAtomic*/ false, Register(),
224-
(int64_t)0 /*offset*/, 0 /*size*/,
229+
/*isAtomic*/ false,
230+
Register(),
231+
(int64_t)0 /*offset*/,
232+
LocationSize::beforeOrAfterPointer() /*size*/,
225233
(MachineMemOperand *)nullptr};
226234
};
227235
MemUseCharacteristics MUC0 = getCharacteristics(&MI),
@@ -262,15 +270,14 @@ bool GISelAddressing::instMayAlias(const MachineInstr &MI,
262270
// FIXME: port the alignment based alias analysis from SDAG's isAlias().
263271
int64_t SrcValOffset0 = MUC0.MMO->getOffset();
264272
int64_t SrcValOffset1 = MUC1.MMO->getOffset();
265-
uint64_t Size0 = MUC0.NumBytes;
266-
uint64_t Size1 = MUC1.NumBytes;
267-
if (AA && MUC0.MMO->getValue() && MUC1.MMO->getValue() &&
268-
Size0 != MemoryLocation::UnknownSize &&
269-
Size1 != MemoryLocation::UnknownSize) {
273+
LocationSize Size0 = MUC0.NumBytes;
274+
LocationSize Size1 = MUC1.NumBytes;
275+
if (AA && MUC0.MMO->getValue() && MUC1.MMO->getValue() && Size0.hasValue() &&
276+
Size1.hasValue()) {
270277
// Use alias analysis information.
271278
int64_t MinOffset = std::min(SrcValOffset0, SrcValOffset1);
272-
int64_t Overlap0 = Size0 + SrcValOffset0 - MinOffset;
273-
int64_t Overlap1 = Size1 + SrcValOffset1 - MinOffset;
279+
int64_t Overlap0 = Size0.getValue() + SrcValOffset0 - MinOffset;
280+
int64_t Overlap1 = Size1.getValue() + SrcValOffset1 - MinOffset;
274281
if (AA->isNoAlias(MemoryLocation(MUC0.MMO->getValue(), Overlap0,
275282
MUC0.MMO->getAAInfo()),
276283
MemoryLocation(MUC1.MMO->getValue(), Overlap1,

0 commit comments

Comments
 (0)