Skip to content

Commit

Permalink
[Local] Simplify the alignment limits in getOrEnforceKnownAlignment. …
Browse files Browse the repository at this point in the history
…NFCI

We previously clamped the trailing zero count to 31 bits. And
then clamped the final alignment to MaximumAlignment which is
1 << 29.

This patch simplifies this to just clamp the trailing zero to
29 using MaxAlignmentExponent.

I was looking into changing this function to use Align/MaybeAlign
and noticed this.

Differential Revision: https://reviews.llvm.org/D78418
  • Loading branch information
topperc committed Apr 18, 2020
1 parent aad3d57 commit e00cfe2
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions llvm/lib/Transforms/Utils/Local.cpp
Expand Up @@ -1215,13 +1215,11 @@ unsigned llvm::getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,

// Avoid trouble with ridiculously large TrailZ values, such as
// those computed from a null pointer.
TrailZ = std::min(TrailZ, unsigned(sizeof(unsigned) * CHAR_BIT - 1));
// LLVM doesn't support alignments larger than (1 << MaxAlignmentExponent).
TrailZ = std::min(TrailZ, Value::MaxAlignmentExponent);

unsigned Align = 1u << std::min(Known.getBitWidth() - 1, TrailZ);

// LLVM doesn't support alignments larger than this currently.
Align = std::min(Align, +Value::MaximumAlignment);

if (PrefAlign > Align)
Align = enforceKnownAlignment(V, Align, PrefAlign, DL);

Expand Down

0 comments on commit e00cfe2

Please sign in to comment.