diff options
author | Arthur Eubanks <aeubanks@google.com> | 2021-09-24 15:54:17 -0700 |
---|---|---|
committer | Arthur Eubanks <aeubanks@google.com> | 2021-10-06 11:03:51 -0700 |
commit | 8d64314ffea55f2ad94c1b489586daa8ce30f451 (patch) | |
tree | ab949f45a1698f6f509596d8e1d2550eed92ed56 /llvm/lib/CodeGen/SafeStack.cpp | |
parent | 05de0ab431ec70abdd035eb80244f8788a115259 (diff) | |
download | llvm-8d64314ffea55f2ad94c1b489586daa8ce30f451.zip llvm-8d64314ffea55f2ad94c1b489586daa8ce30f451.tar.gz llvm-8d64314ffea55f2ad94c1b489586daa8ce30f451.tar.bz2 |
Reland [IR] Increase max alignment to 4GB
Currently the max alignment representable is 1GB, see D108661.
Setting the align of an object to 4GB is desirable in some cases to make sure the lower 32 bits are clear which can be used for some optimizations, e.g. https://crbug.com/1016945.
This uses an extra bit in instructions that carry an alignment. We can store 15 bits of "free" information, and with this change some instructions (e.g. AtomicCmpXchgInst) use 14 bits.
We can increase the max alignment representable above 4GB (up to 2^62) since we're only using 33 of the 64 values, but I've just limited it to 4GB for now.
The one place we have to update the bitcode format is for the alloca instruction. It stores its alignment into 5 bits of a 32 bit bitfield. I've added another field which is 8 bits and should be future proof for a while. For backward compatibility, we check if the old field has a value and use that, otherwise use the new field.
Updating clang's max allowed alignment will come in a future patch.
Reviewed By: hans
Differential Revision: https://reviews.llvm.org/D110451
Diffstat (limited to 'llvm/lib/CodeGen/SafeStack.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SafeStack.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp index 94add92..e1d11c3 100644 --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -147,7 +147,7 @@ class SafeStack { /// /// 16 seems like a reasonable upper bound on the alignment of objects that we /// might expect to appear on the stack on most common targets. - enum { StackAlignment = 16 }; + static constexpr uint64_t StackAlignment = 16; /// Return the value of the stack canary. Value *getStackGuard(IRBuilder<> &IRB, Function &F); @@ -544,8 +544,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack( Size = 1; // Don't create zero-sized stack objects. // Ensure the object is properly aligned. - unsigned Align = - std::max((unsigned)DL.getPrefTypeAlignment(Ty), AI->getAlignment()); + uint64_t Align = std::max(DL.getPrefTypeAlignment(Ty), AI->getAlignment()); SSL.addObject(AI, Size, Align, ClColoring ? SSC.getLiveRange(AI) : NoColoringRange); @@ -676,9 +675,9 @@ void SafeStack::moveDynamicAllocasToUnsafeStack( SP = IRB.CreateSub(SP, Size); // Align the SP value to satisfy the AllocaInst, type and stack alignments. - unsigned Align = std::max( - std::max((unsigned)DL.getPrefTypeAlignment(Ty), AI->getAlignment()), - (unsigned)StackAlignment); + uint64_t Align = + std::max(std::max(DL.getPrefTypeAlignment(Ty), AI->getAlignment()), + StackAlignment); assert(isPowerOf2_32(Align)); Value *NewTop = IRB.CreateIntToPtr( |