Skip to content

Commit ee489ee

Browse files
committed
Allow loads and stores with align >= the size of the data.
Currently we only allow through loads and stores where the alignment of the operation is equal the natural alignment of the type of the data being loaded/stored. However, we can also allow through cases where the alignment of the operation is *greater* than the natural alignment of the data being loaded/stored. In such a case a read/write from memory could never straddle the alignment boundary. The LLVM lang ref says: > An alignment value higher than the size of the loaded type implies > memory up to the alignment value bytes can be safely loaded without > trapping in the default address space
1 parent 90737ba commit ee489ee

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,14 +718,17 @@ class YkIRWriter {
718718
// operation into multiple loads (in order to avoid a memory access
719719
// straddling an alignment boundary on a CPU that disallows such things).
720720
//
721-
// For now we are going to reject any load that has an alignment value not
722-
// the same as the natural alignment of the type of the data being loaded.
721+
// For now we let through only loads with an alignment greater-than or
722+
// equal-to the size of the type of the data being loaded. Such cases are
723+
// trivially safe, since the codegen will never have to face an unaligned
724+
// load for these.
725+
//
723726
// Eventually we will have to encode the alignment of the load into our IR
724727
// and have the trace code generator split up the loads where necessary.
725728
// The same will have to be done for store instructions.
726729
if (I->isVolatile() || (I->getOrdering() != AtomicOrdering::NotAtomic) ||
727730
(I->getPointerAddressSpace() != 0) ||
728-
(I->getAlign() != DL.getPrefTypeAlign(I->getType()))) {
731+
(I->getAlign() < DL.getTypeSizeInBits(I->getType()) / 8)) {
729732
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
730733
return;
731734
}
@@ -753,8 +756,8 @@ class YkIRWriter {
753756
// accesses.
754757
if (I->isVolatile() || (I->getOrdering() != AtomicOrdering::NotAtomic) ||
755758
(I->getPointerAddressSpace() != 0) ||
756-
(I->getAlign() !=
757-
DL.getPrefTypeAlign(I->getValueOperand()->getType()))) {
759+
(I->getAlign() <
760+
DL.getTypeSizeInBits(I->getValueOperand()->getType()) / 8)) {
758761
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
759762
return;
760763
}

0 commit comments

Comments
 (0)