-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[llvm-ml] Fix RIP-relative addressing for ptr operands #107618
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
[llvm-ml] Fix RIP-relative addressing for ptr operands #107618
Conversation
@llvm/pr-subscribers-backend-x86 Author: Andrew Ng (nga888) ChangesFixes #54773 Full diff: https://github.com/llvm/llvm-project/pull/107618.diff 2 Files Affected:
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 03f49306c2b7b5..e88dc9cfbf4877 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -2707,7 +2707,7 @@ bool X86AsmParser::parseIntelOperand(OperandVector &Operands, StringRef Name) {
bool MaybeDirectBranchDest = true;
if (Parser.isParsingMasm()) {
- if (is64BitMode() && SM.getElementSize() > 0) {
+ if (is64BitMode() && (PtrInOperand || SM.getElementSize() > 0)) {
DefaultBaseReg = X86::RIP;
}
if (IsUnconditionalBranch) {
diff --git a/llvm/test/tools/llvm-ml/rip_relative_addressing.asm b/llvm/test/tools/llvm-ml/rip_relative_addressing.asm
index d237e84435b7d6..cdd984ee6a8522 100644
--- a/llvm/test/tools/llvm-ml/rip_relative_addressing.asm
+++ b/llvm/test/tools/llvm-ml/rip_relative_addressing.asm
@@ -53,4 +53,10 @@ mov eax, [t8]
; CHECK-LABEL: t8:
; CHECK: mov eax, dword ptr [t8]
-END
\ No newline at end of file
+t9:
+mov eax, dword ptr [bar]
+; CHECK-LABEL: t9:
+; CHECK-32: mov eax, dword ptr [bar]
+; CHECK-64: mov eax, dword ptr [rip + bar]
+
+END
|
4aa238e
to
52ea8e7
Compare
Thanks for working on this! Unfortunately, I'm not quite familiar enough with x86 assembly to comment reasonably on this... Hopefully someone else can ack it. |
Have we confirmed that this fully fixes #54773 ? I'm prepared to approve this if so - it seems to match ml64's behavior - but I don't want us closing the other bug if this doesn't fix it! |
I have checked that using It was my own experiment of trying to replace MS |
Fantastic! LGTM. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/5376 Here is the relevant piece of the build log for the reference
|
I think it'd be great to have this fix widely deployed in 19.x as well, so we probably should file a backport request. But as it isn't entirely critical, and the bar for including things in 19.1.0 now is pretty high, we probably should file a backport request only after 19.1.0 is cut (early next week). |
…)" This reverts commit 7543d09. This change caused failed asserts when building the openmp assembly sources, reproducible with: $ llvm-ml -m64 -D_M_AMD64 -c -Fo out.obj openmp/runtime/src/z_Windows_NT-586_asm.asm llvm-ml: ../lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp:624: void {anonymous}::X86MCCodeEmitter::emitMemModRMByte(const llvm::MCInst&, unsigned int, unsigned int, uint64_t, {anonymous}::PrefixKind, uint64_t, llvm::SmallVectorImpl<char>&, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&, bool) const: Assertion `IndexReg.getReg() == 0 && !ForceSIB && "Invalid rip-relative address"' failed. The assert can also be triggered with one lone instruction: lea rdx, QWORD PTR [rax*8+16]
Unfortunately, I had to revert this, as this triggered failed asserts when building the openmp runtime assembly sources. See 1581183 for details on how to build that, and for the single instruction that triggers the assert ( |
Relands llvm#107618 with fix for assertion triggered by OpenMP runtime MASM assembly source.
Relands llvm#107618 with fix for assertion triggered by OpenMP runtime MASM assembly source.
Relands #107618 with fix for assertion triggered by OpenMP runtime MASM assembly source.
…08061) Relands llvm#107618 with fix for assertion triggered by OpenMP runtime MASM assembly source. (cherry picked from commit 7574e1d)
…08061) Relands llvm#107618 with fix for assertion triggered by OpenMP runtime MASM assembly source. (cherry picked from commit 7574e1d)
Fixes #54773