This is an archive of the discontinued LLVM Phabricator instance.

[AssumeBundles] offset should be added to correctly calculate align
ClosedPublic

Authored by aqjune on Mar 16 2021, 10:04 PM.

Details

Summary

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 a - 4's offset from 32k, but DiffSCEV - OffSCEV = 32 was being used instead.

Diff Detail

Event Timeline

aqjune created this revision.Mar 16 2021, 10:04 PM
aqjune requested review of this revision.Mar 16 2021, 10:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2021, 10:04 PM
aqjune edited the summary of this revision. (Show Details)Mar 16 2021, 11:56 PM
Tyker accepted this revision.Apr 1 2021, 9:37 AM

LGTM

This revision is now accepted and ready to land.Apr 1 2021, 9:37 AM