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

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 04:18:56 PDT 2024


https://github.com/nga888 updated https://github.com/llvm/llvm-project/pull/108061

>From 240beb9bd6b8cd5b0e4f0962388f5c7d4aede77a Mon Sep 17 00:00:00 2001
From: Andrew Ng <andrew.ng at sony.com>
Date: Tue, 10 Sep 2024 17:19:18 +0100
Subject: [PATCH] Reland [llvm-ml] Fix RIP-relative addressing for ptr operands

Relands #107618 with fix for assertion triggered by OpenMP runtime MASM
assembly source.
---
 llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp      |  3 ++-
 llvm/test/tools/llvm-ml/rip_relative_addressing.asm | 12 +++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

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



More information about the llvm-commits mailing list