Skip to content

Commit 188582b

Browse files
committed
[RISCV] Considering existing offset in the alignment when folding ADDIs into load/store.
getPointerAlignment and ConstantPoolSDNode::getAlign only consider the alignment of the object. If we already have a non-zero offset into the offset that may have reduced the alignment. Since the base pointer will become an LUI with the old offset, we need to be sure the new offset fits in the alignment of the address that will be used to create the LUI immediate. I'm not sure it is possible to have a non-zero offset in the GlobalAddressSDNode or ConstantPoolSDNode at this point today so this may only be a theoretical bug. Differential Revision: https://reviews.llvm.org/D129006
1 parent c998273 commit 188582b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,8 @@ bool RISCVDAGToDAGISel::doPeepholeLoadStoreADDI(SDNode *N) {
22692269
// to provide a margin of safety before off1 can overflow the 12 bits.
22702270
// Check if off2 falls within that margin; if so off1+off2 can't overflow.
22712271
const DataLayout &DL = CurDAG->getDataLayout();
2272-
Align Alignment = GA->getGlobal()->getPointerAlignment(DL);
2272+
Align Alignment = commonAlignment(GA->getGlobal()->getPointerAlignment(DL),
2273+
GA->getOffset());
22732274
if (Offset2 != 0 && Alignment <= Offset2)
22742275
return false;
22752276
int64_t Offset1 = GA->getOffset();
@@ -2279,7 +2280,7 @@ bool RISCVDAGToDAGISel::doPeepholeLoadStoreADDI(SDNode *N) {
22792280
CombinedOffset, GA->getTargetFlags());
22802281
} else if (auto *CP = dyn_cast<ConstantPoolSDNode>(ImmOperand)) {
22812282
// Ditto.
2282-
Align Alignment = CP->getAlign();
2283+
Align Alignment = commonAlignment(CP->getAlign(), CP->getOffset());
22832284
if (Offset2 != 0 && Alignment <= Offset2)
22842285
return false;
22852286
int64_t Offset1 = CP->getOffset();

0 commit comments

Comments
 (0)