[llvm] Add Addend Checks for MOVT and MOVW instructions. (PR #111970)
David Spickett via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 11 02:43:21 PDT 2024
================
@@ -446,6 +447,16 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
const MCSubtargetInfo* STI) const {
unsigned Kind = Fixup.getKind();
+ // For MOVW/MOVT Instructions, the Fixup Value needs to be 16 bit aligned.
+ // If this is not the case, we should reject compilation.
+ if((Kind == ARM::fixup_arm_movw_lo16 || Kind == ARM::fixup_arm_movt_hi16 ||
+ Kind == ARM::fixup_t2_movw_lo16 || Kind == ARM::fixup_t2_movt_hi16) &&
+ (!(minIntN(16) <= static_cast<int64_t>(Value) &&
+ static_cast<int64_t>(Value) <= maxIntN(16)))) {
----------------
DavidSpickett wrote:
This condition could do with re-ordering. Put the fixup value first each time and remove the need for `!`. This if is "if something produce an error", so write it in terms of when you will error not when you won't.
```
&& (static_cast<int64_t>(Value) < minIntN(16) || static_cast<int64_t>(Value) > maxIntN(16))
```
https://github.com/llvm/llvm-project/pull/111970
More information about the llvm-commits
mailing list