[llvm] [llvm] Optimize misaligned accesses with early profitable splitting (PR #145168)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 22 13:00:16 PDT 2025


nikic wrote:

> > If you don't have an appropriately aligned base your current approach will also not help, right? Do you maybe have an example of the situation you're concerned about?
> 
> ```
> %p, align 2
> %gep = %p + %i * 4 + 1  ; align 1
> %gep2 = %gep + 2
> store %v, %gep2, align 1
> ```

Okay, I see what you mean. I don't think you should worry about cases like this. We are moving towards breaking down geps like that, which will avoid situations where a constant offset is part of larger gep.

> > And the offset stored in MPI is allowed to be negative.
> 
> Yes, MPI offset is int64_t, but the following code uses it as uint64_t. I am not sure if it can get the correct value when the offset is negative:
> 
> ```
> inline Align commonAlignment(Align A, uint64_t Offset) {
>   return Align(MinAlign(A.value(), Offset));
> }
> 
> /// getAlign - Return the minimum known alignment in bytes of the
> /// actual memory reference.
> Align MachineMemOperand::getAlign() const {
>   return commonAlignment(getBaseAlign(), getOffset());
> }
> ```

I believe this logic is also correct for signed offset cast to unsigned.



https://github.com/llvm/llvm-project/pull/145168


More information about the llvm-commits mailing list