Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AArch64] Fix a presumed typo in isFPImmLegal limit. NFC #106716

Merged
merged 2 commits into from
Aug 30, 2024

Conversation

citymarina
Copy link
Contributor

The worst possible case for a double literal goes like:

  mov ...
  movk ..., lsl #16
  movk ..., lsl #32
  movk ..., lsl #48
  fmov ...

The limit of 5 in the code gives the impression that Insn includes all instructions including the fmov, but that's not true. It only counts the integer moves. This led me astray on some other work in this area.

The worst possible case for a double literal goes like:

```
  mov ...
  movk ..., lsl llvm#16
  movk ..., lsl llvm#32
  movk ..., lsl llvm#48
  fmov ...
```

The limit of 5 in the code gives the impression that  `Insn` includes
all instructions including the `fmov`, but that's not true. It only
counts the integer moves. This led me astray on some other work in
this area.
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 30, 2024

@llvm/pr-subscribers-backend-aarch64

Author: Marina Taylor (citymarina)

Changes

The worst possible case for a double literal goes like:

  mov ...
  movk ..., lsl #<!-- -->16
  movk ..., lsl #<!-- -->32
  movk ..., lsl #<!-- -->48
  fmov ...

The limit of 5 in the code gives the impression that Insn includes all instructions including the fmov, but that's not true. It only counts the integer moves. This led me astray on some other work in this area.


Full diff: https://github.com/llvm/llvm-project/pull/106716.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+2-1)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 02390e0a85c0a5..98f6f30112a8c7 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -11463,7 +11463,8 @@ bool AArch64TargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
     // movw+movk is fused). So we limit up to 2 instrdduction at most.
     SmallVector<AArch64_IMM::ImmInsnModel, 4> Insn;
     AArch64_IMM::expandMOVImm(ImmInt.getZExtValue(), VT.getSizeInBits(), Insn);
-    unsigned Limit = (OptForSize ? 1 : (Subtarget->hasFuseLiterals() ? 5 : 2));
+    assert(Insn.size() <= 4);
+    unsigned Limit = (OptForSize ? 1 : (Subtarget->hasFuseLiterals() ? 4 : 2));
     IsLegal = Insn.size() <= Limit;
   }
 

Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@@ -11463,7 +11463,9 @@ bool AArch64TargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
// movw+movk is fused). So we limit up to 2 instrdduction at most.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind changing instrdduction to instructions whilst you are here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - you remove it in a follow up. Don't worry about it here then.

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@fhahn fhahn merged commit d0d0e12 into llvm:main Aug 30, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants