[llvm] [IRBuilder] Limit created masked load/store alignment to valid 32bit values (PR #73647)

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 28 08:12:00 PST 2023


================
@@ -584,7 +584,8 @@ CallInst *IRBuilderBase::CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment,
   if (!PassThru)
     PassThru = PoisonValue::get(Ty);
   Type *OverloadedTypes[] = { Ty, PtrTy };
-  Value *Ops[] = {Ptr, getInt32(Alignment.value()), Mask, PassThru};
+  unsigned Align32 = std::min<uint64_t>(Alignment.value(), 0x80000000ULL);
----------------
gchatelet wrote:

Oh, my bad, you're absolutely right that should be 
```
const Align LimitedAlign = std::min(Alignment, Align(1<<31));
```

Now I've looked around and found
https://github.com/llvm/llvm-project/blob/7f3ee3ca1d09daf0f7d350ed9d62796640a59bf4/llvm/include/llvm/IR/Value.h#L799-L804

which is already some kind of global alignment limitation.

I'm not sure about the implications but would that make sense to lower `MaxAlignmentExponent` to `31` and use this instead?
```
const Align LimitedAlign = std::min(Alignment, Align(Value::MaximumAlignment));
```

In that case, I'd rather have a static function in `Value` to limit alignments.

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


More information about the llvm-commits mailing list