Skip to content

Reland [llvm-ml] Fix RIP-relative addressing for ptr operands #108061

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

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

nga888
Copy link
Collaborator

@nga888 nga888 commented Sep 10, 2024

Relands #107618 with fix for assertion triggered by OpenMP runtime MASM assembly source.

@llvmbot
Copy link
Member

llvmbot commented Sep 10, 2024

@llvm/pr-subscribers-backend-x86

Author: Andrew Ng (nga888)

Changes

Relands #107618 with fix for assertion triggered by OpenMP runtime MASM assembly source.


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

2 Files Affected:

  • (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+2-1)
  • (modified) llvm/test/tools/llvm-ml/rip_relative_addressing.asm (+11-1)
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 03f49306c2b7b5..6b4e47a49eb17b 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -2707,7 +2707,8 @@ bool X86AsmParser::parseIntelOperand(OperandVector &Operands, StringRef Name) {
   bool MaybeDirectBranchDest = true;
 
   if (Parser.isParsingMasm()) {
-    if (is64BitMode() && SM.getElementSize() > 0) {
+    if (is64BitMode() &&
+        ((PtrInOperand && !IndexReg) || 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..c005b9721c07e0 100644
--- a/llvm/test/tools/llvm-ml/rip_relative_addressing.asm
+++ b/llvm/test/tools/llvm-ml/rip_relative_addressing.asm
@@ -53,4 +53,14 @@ 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]
+
+t10:
+mov ebx, dword ptr [4*eax]
+; CHECK: mov ebx, dword ptr [4*eax]
+
+END

Copy link
Contributor

@ericastor ericastor left a comment

Choose a reason for hiding this comment

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

Seems sensible to me - but @mstorsjo should probably check that this works on the OpenMP build too. (I'm less experienced with that.)

@mstorsjo
Copy link
Member

Seems sensible to me - but @mstorsjo should probably check that this works on the OpenMP build too. (I'm less experienced with that.)

I've verified that the OpenMP object files assemble into bitexact the same thing as before, after this patch, and no asserts are triggered now.

Copy link
Member

@mstorsjo mstorsjo 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!

Relands llvm#107618 with fix for assertion triggered by OpenMP runtime MASM
assembly source.
@nga888 nga888 force-pushed the fix-llvm-ml-rip-relative-addressing branch from 33438a2 to 240beb9 Compare September 13, 2024 11:18
@nga888 nga888 merged commit 7574e1d into llvm:main Sep 13, 2024
5 of 6 checks passed
@nga888 nga888 deleted the fix-llvm-ml-rip-relative-addressing branch September 13, 2024 11:19
@mstorsjo mstorsjo added this to the LLVM 19.X Release milestone Sep 18, 2024
@mstorsjo
Copy link
Member

/cherry-pick 7574e1d

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 18, 2024
…08061)

Relands llvm#107618 with fix for assertion triggered by OpenMP runtime MASM
assembly source.

(cherry picked from commit 7574e1d)
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

/pull-request #109091

tru pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 24, 2024
…08061)

Relands llvm#107618 with fix for assertion triggered by OpenMP runtime MASM
assembly source.

(cherry picked from commit 7574e1d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

4 participants