[PATCH] D98759: [AssumeBundles] offset should be added to correctly calculate align

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 16 22:04:39 PDT 2021


aqjune created this revision.
aqjune added reviewers: jdoerfert, Tyker.
Herald added subscribers: javed.absar, hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is a patch to fix the bug in alignment calculation (see https://reviews.llvm.org/D90529#2619492).

Consider this code:

  call void @llvm.assume(i1 true) ["align"(i32* %a, i32 32, i32 28)]
  %arrayidx = getelementptr inbounds i32, i32* %a, i64 -1
  ; aligment of %arrayidx?

The llvm.assume guarantees that `%a - 28` is 32-bytes aligned, meaning that `%a` is 32k + 28 for some k.
Therefore `a - 4` cannot be 32-bytes aligned but the existing code was calculating the pointer as 32-bytes aligned.

The reason why this happened is as follows.
`DiffSCEV` stores `%arrayidx - %a` which is -4.
`OffSCEV` stores the offset value of “align”, which is 28.
`DiffSCEV` + `OffSCEV` = 24 should be used for the alignment of `a - 4`, but `DiffSCEV` - `OffSCEV` = 32 was being used instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98759

Files:
  llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
  llvm/test/Transforms/AlignmentFromAssumptions/simple.ll
  llvm/test/Transforms/AlignmentFromAssumptions/simple32.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98759.331160.patch
Type: text/x-patch
Size: 4409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210317/6579e00d/attachment.bin>


More information about the llvm-commits mailing list